diff options
| author | xengineering <me@xengineering.eu> | 2026-06-21 14:36:47 +0200 |
|---|---|---|
| committer | xengineering <me@xengineering.eu> | 2026-06-21 14:36:47 +0200 |
| commit | 2009b9726e2aac595a186063deb729df0d7cd850 (patch) | |
| tree | 8d418c7c4438ab07ed0eef7832c7fcf1eaad2201 /handlers_test.go | |
| parent | 20f56806b405f3d33f3db2f419e02a3361d99296 (diff) | |
| download | finserv-2009b9726e2aac595a186063deb729df0d7cd850.tar finserv-2009b9726e2aac595a186063deb729df0d7cd850.tar.zst finserv-2009b9726e2aac595a186063deb729df0d7cd850.zip | |
Use only string-based input output for HTTP tests
The API should only communicate via UTF-8 encoded text. Requiring by
default makes test case notation easier and improves scalability.
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 { |
