HTTP response validator for ISUCON benchmarker with Functional Option Pattern
An executable example is in example/main.go.
- Status Code
err := isugata.Validate(res,
isugata.WithStatusCode(http.StatusOK),
)
- Content Type
err := isugata.Validate(res,
isugata.WithContentType("application/json"),
)
- JSON Body Validation
type user struct {
ID int `json:"id"`
Name string `json:"name"`
}
err := isugata.Validate(res,
isugata.WithJSONValidation[user](
isugata.JSONEquals[user](
user{
ID: 1,
Name: "test",
},
),
),
)
- JSON Array Body Validation
type user struct {
ID int `json:"id"`
Name string `json:"name"`
}
err := isugata.Validate(res,
isugata.WithJSONArrayValidation[user](
isugata.JSONArrayLengthEquals[user](2),
isugata.JSONArrayValidateOrder[user, int](
func(u user) int { return u.ID },
isugata.Asc,
),
isugata.JSONArrayValidateEach[user](
func(body user) error {
if body.Name != fmt.Sprintf("test%d", body.ID) {
return fmt.Errorf("expected: test%d, actual: %s", body.ID, body.Name)
}
return nil
},
),
),
)