Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -119,24 +122,27 @@ 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",
PublishReady: true,
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
}
}
}))
Expand Down