Skip to content

Commit

Permalink
fix(webhook): Fix response content type
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy351 committed Dec 16, 2020
1 parent 280cbeb commit 03c04c6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/httputil/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion test/e2e/github_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/http_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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"),
))
}

Expand Down

0 comments on commit 03c04c6

Please sign in to comment.