Skip to content

Commit

Permalink
add server-side test
Browse files Browse the repository at this point in the history
  • Loading branch information
jhump committed Nov 30, 2023
1 parent d3e1470 commit 72f3ee2
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions handler_ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,35 @@ func TestHandler_ServeHTTP(t *testing.T) {
assert.Equal(t, resp.StatusCode, http.StatusUnsupportedMediaType)
})

t.Run("get_method_body_not_allowed", func(t *testing.T) {
t.Parallel()
request, err := http.NewRequestWithContext(
context.Background(),
http.MethodGet,
server.URL()+pingProcedure+`?encoding=json&message={}`,

Check failure on line 88 in handler_ext_test.go

View workflow job for this annotation

GitHub Actions / ci (1.21.x)

string `?encoding=json&message={}` has 4 occurrences, make it a constant (goconst)
strings.NewReader("!"), //non-empty body

Check failure on line 89 in handler_ext_test.go

View workflow job for this annotation

GitHub Actions / ci (1.21.x)

commentFormatting: put a space between `//` and comment text (gocritic)
)
assert.Nil(t, err)
resp, err := client.Do(request)
assert.Nil(t, err)
defer resp.Body.Close()
assert.Equal(t, resp.StatusCode, http.StatusUnsupportedMediaType)

// Same thing, but this time w/ a content-length header
request, err = http.NewRequestWithContext(
context.Background(),
http.MethodGet,
server.URL()+pingProcedure+`?encoding=json&message={}`,
strings.NewReader("!"), //non-empty body

Check failure on line 102 in handler_ext_test.go

View workflow job for this annotation

GitHub Actions / ci (1.21.x)

commentFormatting: put a space between `//` and comment text (gocritic)
)
assert.Nil(t, err)
request.Header.Set("content-length", "1")
resp, err = client.Do(request)
assert.Nil(t, err)
defer resp.Body.Close()
assert.Equal(t, resp.StatusCode, http.StatusUnsupportedMediaType)
})

t.Run("idempotent_get_method", func(t *testing.T) {
t.Parallel()
request, err := http.NewRequestWithContext(
Expand Down

0 comments on commit 72f3ee2

Please sign in to comment.