diff --git a/main_test.go b/main_test.go index 3786a2f2..28cfaa57 100644 --- a/main_test.go +++ b/main_test.go @@ -98,8 +98,11 @@ func newMockApmServer(t *testing.T, l *zap.SugaredLogger) (*MockServerInternals, apmServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { decompressedBytes, err := e2eTesting.GetDecompressedBytesFromRequest(r) if err != nil { + l.Debugf("failed to read decompressedBytes: %v", err) w.WriteHeader(http.StatusInternalServerError) + return } + l.Debugf("Event type received by mock APM server : %s", string(decompressedBytes)) switch APMServerBehavior(decompressedBytes) { case TimelyResponse: @@ -119,12 +122,12 @@ func newMockApmServer(t *testing.T, l *zap.SugaredLogger) (*MockServerInternals, panic("Server crashed") default: } + if r.RequestURI == "/intake/v2/events" { - w.WriteHeader(http.StatusAccepted) apmServerInternals.Data += string(decompressedBytes) l.Debug("APM Payload processed") + w.WriteHeader(http.StatusAccepted) } else if r.RequestURI == "/" { - w.WriteHeader(http.StatusOK) infoPayload, err := json.Marshal(ApmInfo{ BuildDate: time.Now(), BuildSHA: "7814d524d3602e70b703539c57568cba6964fc20", @@ -132,11 +135,14 @@ func newMockApmServer(t *testing.T, l *zap.SugaredLogger) (*MockServerInternals, Version: "8.1.2", }) if err != nil { + l.Debugf("failed to marshal payload: %v", err) w.WriteHeader(http.StatusInternalServerError) + return } - _, err = w.Write(infoPayload) - if err != nil { - w.WriteHeader(http.StatusInternalServerError) + + if _, err = w.Write(infoPayload); err != nil { + l.Debugf("failed to write payload: %v", err) + return } } }))