diff --git a/internal/httputil/response.go b/internal/httputil/response.go index d87161b..1fa275e 100644 --- a/internal/httputil/response.go +++ b/internal/httputil/response.go @@ -42,8 +42,8 @@ func NoContent(w http.ResponseWriter) error { } func JSON(w http.ResponseWriter, status int, data interface{}) error { - w.WriteHeader(status) w.Header().Set("Content-Type", "application/json") + w.WriteHeader(status) if err := json.NewEncoder(w).Encode(data); err != nil { return fmt.Errorf("failed to write json to http response: %w", err) diff --git a/test/e2e/github_webhook_test.go b/test/e2e/github_webhook_test.go index f800f14..91a20a7 100644 --- a/test/e2e/github_webhook_test.go +++ b/test/e2e/github_webhook_test.go @@ -12,6 +12,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/tommy351/pullup/internal/fakegithub" + "github.com/tommy351/pullup/internal/testutil" "k8s.io/apimachinery/pkg/runtime" ) @@ -28,7 +29,10 @@ func sendGitHubRequest(event string, data interface{}) { req.Header.Set("X-GitHub-Event", event) return http.DefaultClient.Do(req) - }).Should(HaveHTTPStatus(http.StatusOK)) + }).Should(And( + HaveHTTPStatus(http.StatusOK), + testutil.HaveHTTPHeader("Content-Type", "application/json"), + )) } var _ = Describe("GitHubWebhook", func() { diff --git a/test/e2e/http_webhook_test.go b/test/e2e/http_webhook_test.go index 9349371..fe6ca09 100644 --- a/test/e2e/http_webhook_test.go +++ b/test/e2e/http_webhook_test.go @@ -9,6 +9,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "github.com/tommy351/pullup/internal/testutil" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/rand" ) @@ -40,8 +41,8 @@ var _ = Describe("HTTPWebhook", func() { return http.DefaultClient.Do(req) }).Should(And( - Not(BeNil()), HaveHTTPStatus(http.StatusOK), + testutil.HaveHTTPHeader("Content-Type", "application/json"), )) }