From 00ed214513c2f8071712f5853d73ebe07d79c4bf Mon Sep 17 00:00:00 2001 From: Tine Date: Tue, 6 Feb 2024 23:42:14 +0100 Subject: [PATCH] test: simplify request body --- cmd/server_test.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cmd/server_test.go b/cmd/server_test.go index a24e004..b0c83f0 100644 --- a/cmd/server_test.go +++ b/cmd/server_test.go @@ -59,6 +59,12 @@ func setup(t *testing.T) (func(), *openapi.Server) { }, server } +func toJson(t *testing.T, request interface{ MarshalJSON() ([]byte, error) }) *bytes.Buffer { + json, err := request.MarshalJSON() + assert.Nil(t, err) + return bytes.NewBuffer(json) +} + func TestHealth(t *testing.T) { teardown, srv := setup(t) defer teardown() @@ -78,11 +84,8 @@ func TestCreatingGroup(t *testing.T) { teardown, srv := setup(t) defer teardown() - groupUpdate := openapi.GroupUpdate{Name: "test"} - json, err := groupUpdate.MarshalJSON() - assert.Nil(t, err) - - req, err := http.NewRequest("POST", "/groups", bytes.NewBuffer(json)) + // TODO: Maybe we can create a "newRequest" method to wrap this 6 lines? + req, err := http.NewRequest("POST", "/groups", toJson(t, &openapi.GroupUpdate{Name: "test"})) assert.Nil(t, err) req.Header.Add("Content-Type", "application/json")