diff --git a/pkg/handlers/launch.go b/pkg/handlers/launch.go index 347bf17..8f86ecc 100644 --- a/pkg/handlers/launch.go +++ b/pkg/handlers/launch.go @@ -30,6 +30,7 @@ type launchPayload struct { WaitForResults bool SlackChannelsString string `json:"slack_channels"` SlackChannels []string + NotificationContext string `json:"notification_context"` } `json:"metadata"` } @@ -103,11 +104,12 @@ func (h *launchHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) { return } + slackContext := payload.Metadata.NotificationContext // Find the Cloud URL from the k6 output if waitErr := h.waitForOutputPath(&buf); waitErr != nil { logError(req, resp, fmt.Sprintf("error while waiting for test to start: %v", waitErr), 400) text := fmt.Sprintf(":red_circle: Load testing of `%s` in namespace `%s` didn't start successfully", payload.Name, payload.Namespace) - slackMessages, err := h.slackClient.SendMessages(payload.Metadata.SlackChannels, text, "") + slackMessages, err := h.slackClient.SendMessages(payload.Metadata.SlackChannels, text, slackContext) if err != nil { log.Error(err) } @@ -117,10 +119,10 @@ func (h *launchHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) { return } - url, slackContext := "", "" + url := "" if payload.Metadata.UploadToCloud { url = outputRegex.FindStringSubmatch(buf.String())[1] - slackContext = fmt.Sprintf("Cloud URL: <%s>", url) + slackContext += fmt.Sprintf("\nCloud URL: <%s>", url) log.Infof("cloud run URL: %s", url) } diff --git a/pkg/handlers/launch_test.go b/pkg/handlers/launch_test.go index 0786f93..47dcab2 100644 --- a/pkg/handlers/launch_test.go +++ b/pkg/handlers/launch_test.go @@ -138,7 +138,7 @@ func TestLaunchAndWaitCloud(t *testing.T) { slackClient.EXPECT().SendMessages( []string{"test", "test2"}, ":warning: Load testing of `test-name` in namespace `test-space` has started", - "Cloud URL: ", + "extra context\nCloud URL: ", ).Return(channelMap, nil) // * Wait for the command to finish @@ -156,12 +156,12 @@ func TestLaunchAndWaitCloud(t *testing.T) { slackClient.EXPECT().UpdateMessages( channelMap, ":large_green_circle: Load testing of `test-name` in namespace `test-space` has succeeded", - "Cloud URL: ", + "extra context\nCloud URL: ", ).Return(nil) // Make request request := &http.Request{ - Body: ioutil.NopCloser(strings.NewReader(`{"name": "test-name", "namespace": "test-space", "phase": "pre-rollout", "metadata": {"script": "my-script", "upload_to_cloud": "true", "slack_channels": "test,test2"}}`)), + Body: ioutil.NopCloser(strings.NewReader(`{"name": "test-name", "namespace": "test-space", "phase": "pre-rollout", "metadata": {"script": "my-script", "upload_to_cloud": "true", "slack_channels": "test,test2", "notification_context": "extra context"}}`)), } rr := httptest.NewRecorder() handler.ServeHTTP(rr, request)