Skip to content

Commit 03c04c6

Browse files
committed
fix(webhook): Fix response content type
1 parent 280cbeb commit 03c04c6

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

internal/httputil/response.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ func NoContent(w http.ResponseWriter) error {
4242
}
4343

4444
func JSON(w http.ResponseWriter, status int, data interface{}) error {
45-
w.WriteHeader(status)
4645
w.Header().Set("Content-Type", "application/json")
46+
w.WriteHeader(status)
4747

4848
if err := json.NewEncoder(w).Encode(data); err != nil {
4949
return fmt.Errorf("failed to write json to http response: %w", err)

test/e2e/github_webhook_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
. "github.com/onsi/ginkgo"
1313
. "github.com/onsi/gomega"
1414
"github.com/tommy351/pullup/internal/fakegithub"
15+
"github.com/tommy351/pullup/internal/testutil"
1516
"k8s.io/apimachinery/pkg/runtime"
1617
)
1718

@@ -28,7 +29,10 @@ func sendGitHubRequest(event string, data interface{}) {
2829
req.Header.Set("X-GitHub-Event", event)
2930

3031
return http.DefaultClient.Do(req)
31-
}).Should(HaveHTTPStatus(http.StatusOK))
32+
}).Should(And(
33+
HaveHTTPStatus(http.StatusOK),
34+
testutil.HaveHTTPHeader("Content-Type", "application/json"),
35+
))
3236
}
3337

3438
var _ = Describe("GitHubWebhook", func() {

test/e2e/http_webhook_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
. "github.com/onsi/ginkgo"
1111
. "github.com/onsi/gomega"
12+
"github.com/tommy351/pullup/internal/testutil"
1213
"k8s.io/apimachinery/pkg/runtime"
1314
"k8s.io/apimachinery/pkg/util/rand"
1415
)
@@ -40,8 +41,8 @@ var _ = Describe("HTTPWebhook", func() {
4041

4142
return http.DefaultClient.Do(req)
4243
}).Should(And(
43-
Not(BeNil()),
4444
HaveHTTPStatus(http.StatusOK),
45+
testutil.HaveHTTPHeader("Content-Type", "application/json"),
4546
))
4647
}
4748

0 commit comments

Comments
 (0)