示例#1
0
func TestJSON(t *testing.T) {
	reader := getJSONResponse()

	err := schema.MatchJSON(
		schema.Map{
			"id":       schema.IsInteger,
			"name":     "Max Mustermann",
			"age":      42,
			"height":   schema.IsFloat,
			"footsize": schema.IsPresent,
			"address": schema.Map{
				"street": schema.IsString,
				"zip":    schema.IsString,
			},
			"tags": schema.ArrayIncluding("red"),
		},
		reader,
	)

	if err != nil {
		t.Fatal(err)
	}
}
示例#2
0
func AssertJSONSchema(t *testing.T, matcher schema.Matcher, r io.Reader) {
	err := schema.MatchJSON(matcher, r)
	if err != nil {
		th.Error(t, 1, err.Error())
	}
}