Documentation
¶
Overview ¶
Package openapitest provides utilities for validating HTTP requests and responses against an OpenAPI spec in tests.
Typical usage with a package-level validator initialized in TestMain:
var v *openapitest.Validator
func TestMain(m *testing.M) {
var err error
v, err = openapitest.NewValidator("testdata/openapi.yaml")
if err != nil {
log.Fatal(err)
}
os.Exit(m.Run())
}
func TestSomething(t *testing.T) {
// ... make request ...
v.AssertResponse(t, req, resp)
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator validates HTTP responses against an OpenAPI spec.
func NewValidator ¶
NewValidator reads the OpenAPI spec at path and returns a Validator.
func NewValidatorFromSpec ¶
NewValidatorFromSpec parses spec bytes and returns a Validator.
func (*Validator) AssertResponse ¶
AssertResponse validates resp against the OpenAPI spec for req. It calls t.Error for every validation failure, allowing the test to continue. The response body is restored after reading so callers can still decode it.
Click to show internal directories.
Click to hide internal directories.