diff options
Diffstat (limited to 'handlers_test.go')
| -rw-r--r-- | handlers_test.go | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/handlers_test.go b/handlers_test.go index db97502..f24bde4 100644 --- a/handlers_test.go +++ b/handlers_test.go @@ -13,8 +13,8 @@ type Handler func(db *sql.DB) http.Handler type httpCase struct { name string method string - input []byte - output []byte + input string + output string status int } @@ -28,7 +28,7 @@ func testHandler( t.Run(c.name, func(t *testing.T) { db := setup(t) - in := bytes.NewReader(c.input) + in := bytes.NewReader([]byte(c.input)) rr := httptest.NewRecorder() @@ -54,7 +54,7 @@ func testHandler( func TestHTTPVersion(t *testing.T) { cases := []httpCase{ - {"basic", "GET", []byte(``), []byte(versionTxt), http.StatusOK}, + {"basic", "GET", ``, versionTxt, http.StatusOK}, } setup := func(t *testing.T) *sql.DB { @@ -66,11 +66,11 @@ func TestHTTPVersion(t *testing.T) { func TestHTTPRegister(t *testing.T) { cases := []httpCase{ - {"basic", "POST", []byte(`{"username":"testuser","password":"mypass"}`), []byte(""), http.StatusOK}, - {"missing-password", "POST", []byte(`{"username":"testuser"}`), []byte(""), http.StatusBadRequest}, - {"missing-username", "POST", []byte(`{"password":"mypass"}`), []byte(""), http.StatusBadRequest}, - {"unknown-field", "POST", []byte(`{"username":"testuser","password":"mypass","foo":"bar"}`), []byte(""), http.StatusBadRequest}, - {"invalid-json", "POST", []byte(`{username":"testuser","password":"mypass"}`), []byte(""), http.StatusBadRequest}, + {"basic", "POST", `{"username":"testuser","password":"mypass"}`, "", http.StatusOK}, + {"missing-password", "POST", `{"username":"testuser"}`, "", http.StatusBadRequest}, + {"missing-username", "POST", `{"password":"mypass"}`, "", http.StatusBadRequest}, + {"unknown-field", "POST", `{"username":"testuser","password":"mypass","foo":"bar"}`, "", http.StatusBadRequest}, + {"invalid-json", "POST", `{username":"testuser","password":"mypass"}`, "", http.StatusBadRequest}, } setup := func(t *testing.T) *sql.DB { @@ -87,13 +87,13 @@ func TestHTTPRegister(t *testing.T) { func TestHTTPAuthenticate(t *testing.T) { cases := []httpCase{ - {"basic", "POST", []byte(`{"username":"testuser","password":"mypass"}`), []byte(""), http.StatusOK}, - {"missing-password", "POST", []byte(`{"username":"testuser"}`), []byte(""), http.StatusBadRequest}, - {"missing-username", "POST", []byte(`{"password":"mypass"}`), []byte(""), http.StatusBadRequest}, - {"unknown-field", "POST", []byte(`{"username":"testuser","password":"mypass","foo":"bar"}`), []byte(""), http.StatusBadRequest}, - {"invalid-json", "POST", []byte(`{username":"testuser","password":"mypass"}`), []byte(""), http.StatusBadRequest}, - {"wrong-username", "POST", []byte(`{"username":"wronguser","password":"mypass"}`), []byte(""), http.StatusUnauthorized}, - {"wrong-password", "POST", []byte(`{"username":"testuser","password":"wrongpass"}`), []byte(""), http.StatusUnauthorized}, + {"basic", "POST", `{"username":"testuser","password":"mypass"}`, "", http.StatusOK}, + {"missing-password", "POST", `{"username":"testuser"}`, "", http.StatusBadRequest}, + {"missing-username", "POST", `{"password":"mypass"}`, "", http.StatusBadRequest}, + {"unknown-field", "POST", `{"username":"testuser","password":"mypass","foo":"bar"}`, "", http.StatusBadRequest}, + {"invalid-json", "POST", `{username":"testuser","password":"mypass"}`, "", http.StatusBadRequest}, + {"wrong-username", "POST", `{"username":"wronguser","password":"mypass"}`, "", http.StatusUnauthorized}, + {"wrong-password", "POST", `{"username":"testuser","password":"wrongpass"}`, "", http.StatusUnauthorized}, } setup := func(t *testing.T) *sql.DB { |
