Documentation ¶
Overview ¶
schema provides a testing utility for testing API types against a predefined JSON schema.
The core philosophy for this package is as follows: when a new API is accepted, JSON Schema files should be added to document the types that are exchanged over this new API. Those files are placed in the `/api/schema` directory, and are used by the schema.Validate function to test that particular instances of these types as represented in Go match the predefined schema that was proposed as a part of the API.
For ease of use, this file defines several constants, one for each schema file's name, to easily pass around during tests.
As briefly described above, to validate that a Go type matches the schema for a particular API call, one should use the schema.Validate() function.
Index ¶
Constants ¶
const ( LockListSchema = "lock_list_schema.json" LockRequestSchema = "lock_request_schema.json" LockResponseSchema = "lock_response_schema.json" UnlockRequestSchema = "unlock_request_schema.json" UnlockResponseSchema = "unlock_response_schema.json" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type SchemaValidator ¶
type SchemaValidator struct {
// Schema is the JSON schema to validate against.
//
// Subject is the instance of Go type that will be validated.
Schema, Subject gojsonschema.JSONLoader
}
SchemaValidator uses the gojsonschema library to validate the JSON encoding of Go objects against a pre-defined JSON schema.
func NewSchemaValidator ¶
func NewSchemaValidator(t *testing.T, schemaName string, got interface{}) *SchemaValidator
func (*SchemaValidator) Assert ¶
func (v *SchemaValidator) Assert(t *testing.T)
Assert preforms the validation assertion against the given *testing.T.
func (*SchemaValidator) Refute ¶
func (v *SchemaValidator) Refute(t *testing.T)
Refute refutes that the given subject will validate against a particular schema.