Skip to content

Commit

Permalink
Test CanHaveBody, AllowsBody and IsSafe
Browse files Browse the repository at this point in the history
Signed-off-by: Kazuyoshi Kato <[email protected]>
  • Loading branch information
kzys committed Oct 25, 2021
1 parent 5156d21 commit 7729882
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"bytes"
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
"testing"
Expand Down Expand Up @@ -152,17 +153,34 @@ func TestJSONRequest(t *testing.T) {
assert.Nil(t, req)
}

//func TestCanHaveBody(t *testing.T) {
//assert.True(t, CanHaveBody("put"))
//assert.True(t, CanHaveBody("post"))
//assert.True(t, CanHaveBody("patch"))
//assert.True(t, CanHaveBody("delete"))
//assert.False(t, CanHaveBody(""))
//assert.False(t, CanHaveBody("get"))
//assert.False(t, CanHaveBody("options"))
//assert.False(t, CanHaveBody("head"))
//assert.False(t, CanHaveBody("invalid"))
//}
func TestMethod(t *testing.T) {
testcase := []struct {
method string
canHaveBody bool
allowsBody bool
isSafe bool
}{
{"put", true, true, false},
{"post", true, true, false},
{"patch", true, true, false},
{"delete", true, true, false},
{"get", false, true, true},
{"options", false, true, false},
{"head", false, false, true},
{"invalid", false, true, false},
{"", false, true, false},
}

for _, tc := range testcase {
t.Run(tc.method, func(t *testing.T) {
assert.Equal(t, tc.canHaveBody, CanHaveBody(tc.method), "CanHaveBody")

req := http.Request{Method: tc.method}
assert.Equal(t, tc.allowsBody, AllowsBody(&req), "AllowsBody")
assert.Equal(t, tc.isSafe, IsSafe(&req), "IsSafe")
})
}
}

func TestReadSingle(t *testing.T) {
values := url.Values(make(map[string][]string))
Expand Down

0 comments on commit 7729882

Please sign in to comment.