Skip to content

Commit a31e86d

Browse files
committed
added status code asserter
1 parent 09ed10b commit a31e86d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pkg/goponent/assert_http.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,20 @@ func (h HttpResponseAsserter) Assert(t *testing.T, context *Context, stepContext
3030
AssertEqual(t, h.ExpectedStatusCode, res.StatusCode)
3131
return nil
3232
}
33+
34+
var _ Asserter = HttpResponseStatusCodeAsserter{}
35+
36+
type HttpResponseStatusCodeAsserter struct {
37+
ExpectedStatusCode int
38+
}
39+
40+
func (h HttpResponseStatusCodeAsserter) Assert(t *testing.T, context *Context, stepContext *Context) error {
41+
res, ok := ContextGet[*http.Response](stepContext, "response")
42+
if !ok {
43+
t.Error("no response in context")
44+
return errors.New("no response in context")
45+
}
46+
47+
AssertEqual(t, h.ExpectedStatusCode, res.StatusCode)
48+
return nil
49+
}

0 commit comments

Comments
 (0)