Esempio n. 1
0
func VerifyRoundTrip(t *testing.T, value interface{}) interface{} {

	var newValue interface{}

	for _, verbose := range []bool{true, false} {
		json, err := EncodeToString(value, verbose)

		if err != nil {
			t.Errorf("Error encoding to Transit %v: %v", value, err)
		}

		newValue, err = DecodeFromString(json)

		if err != nil {
			t.Errorf("Error decoding %v: %v.\nJson:\n%v", value, err, json)
		}

		if !same.IsSame(value, newValue) {
			t.Errorf("Round trip values do not match.\nValue:[%v]\n%v\nNew value:[%v]\n %v\nJson:\n%v",
				value, reflect.TypeOf(value), newValue, reflect.TypeOf(newValue), json)
		}
	}

	return newValue
}
Esempio n. 2
0
func VerifyJson(t *testing.T, transit string, path string) error {
	var actual interface{}
	var err error

	if err = json.Unmarshal([]byte(transit), &actual); err != nil {
		t.Errorf("Error reading generated transit %v: %v", transit, err)
		return err
	}

	expectedJson, err := ioutil.ReadFile(path)
	if err != nil {
		t.Errorf("Error reading exemplare [%v]: %v", path, err)
		return err
	}

	var expected interface{}
	if err = json.Unmarshal([]byte(expectedJson), &expected); err != nil {
		t.Errorf("Error decoding expected [%v]: %v", path, err)
		return err
	}

	if !same.IsSame(actual, expected) {
		t.Errorf("Actual does not match exemplar.\nExpected: %v\nActual: %v", expected, actual)
		return NewTransitError("No match", actual)
	}
	return nil
}