Beispiel #1
0
func TestVerifyModelAgainstFileShouldAccountForUntaggedFields(t *testing.T) {
	trec := openrtbtest.NewTestingRecorder()

	// When verifying model against a type with some of the fields untagged.
	openrtbtest.VerifyModelAgainstFile(
		trec,
		"untagged.json",
		reflect.TypeOf(struct {
			P1 int    `json:"p1"`
			P2 string `json:"p2"`
			P3 float64
		}{}))

	// Expect the verification too pass.
	if len(trec.Replays()) > 0 {
		t.Fatal("Verification should not have any errors.", trec.Replays())
	}

	trec = openrtbtest.NewTestingRecorder()

	// When verifying model against a type with some of the fields untagged.
	openrtbtest.VerifyModelAgainstFile(
		trec,
		"untagged.json",
		reflect.TypeOf(struct {
			P1 int     `json:"p1"`
			P2 string  `json:"p2"`
			P3 float64 `json:"p3"`
		}{}))

	// Expect there are some errors.
	replays := trec.Replays()
	if len(replays) == 0 {
		t.Fatal("Verification should produced some errors.")
	}

	if replays[0].Format != "JSON contains %d properties but the model %v declared %d." {
		t.Fatal("The first error should check the number of fields match.")
	}
}
Beispiel #2
0
func TestVerifyModelAgainstFileStructWithNoJsonTagsShouldOnlyMatchEmptyJSON(t *testing.T) {
	trec := openrtbtest.NewTestingRecorder()

	// When verifying model against a non-empty type but with no JSON fields.
	openrtbtest.VerifyModelAgainstFile(
		trec,
		"empty.json",
		reflect.TypeOf(struct {
			P1 int    `xml:"p1"`
			P2 string `xml:"p2"`
			P3 float64
		}{}))

	// Expect the verification too pass.
	if len(trec.Replays()) > 0 {
		t.Fatal("Verification should not have any errors.", trec.Replays())
	}
}
Beispiel #3
0
func TestGeoMarshalUnmarshal(t *testing.T) {
	openrtbtest.VerifyModelAgainstFile(t, "geo.json", GeoModelType)
}
Beispiel #4
0
func TestDeviceMarshalUnmarshal(t *testing.T) {
	openrtbtest.VerifyModelAgainstFile(t, "device.json", DeviceModelType)
}
Beispiel #5
0
func TestPublisherMarshalUnmarshal(t *testing.T) {
	openrtbtest.VerifyModelAgainstFile(t, "publisher.json", PublisherModelType)
}