test: simplify request body
This commit is contained in:
parent
93650d7d5a
commit
00ed214513
1 changed files with 8 additions and 5 deletions
|
@ -59,6 +59,12 @@ func setup(t *testing.T) (func(), *openapi.Server) {
|
||||||
}, 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) {
|
func TestHealth(t *testing.T) {
|
||||||
teardown, srv := setup(t)
|
teardown, srv := setup(t)
|
||||||
defer teardown()
|
defer teardown()
|
||||||
|
@ -78,11 +84,8 @@ func TestCreatingGroup(t *testing.T) {
|
||||||
teardown, srv := setup(t)
|
teardown, srv := setup(t)
|
||||||
defer teardown()
|
defer teardown()
|
||||||
|
|
||||||
groupUpdate := openapi.GroupUpdate{Name: "test"}
|
// TODO: Maybe we can create a "newRequest" method to wrap this 6 lines?
|
||||||
json, err := groupUpdate.MarshalJSON()
|
req, err := http.NewRequest("POST", "/groups", toJson(t, &openapi.GroupUpdate{Name: "test"}))
|
||||||
assert.Nil(t, err)
|
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "/groups", bytes.NewBuffer(json))
|
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
req.Header.Add("Content-Type", "application/json")
|
req.Header.Add("Content-Type", "application/json")
|
||||||
|
|
||||||
|
|
Reference in a new issue