Пример #1
0
// ShouldResemble receives exactly two parameters and does a deep equal check (see reflect.DeepEqual)
func ShouldResemble(actual interface{}, expected ...interface{}) string {
	if message := need(1, expected); message != success {
		return message
	}

	if matchError := oglematchers.DeepEquals(expected[0]).Matches(actual); matchError != nil {
		return serializer.serialize(expected[0], actual, fmt.Sprintf(shouldHaveResembled, expected[0], actual))
	}

	return success
}
Пример #2
0
func shouldSlicesResemble(actual interface{}, expected ...interface{}) string {
	expectedSlice, ok := takeSliceArg(expected[0])
	if !ok {
		return "Cannot cast expected slice to []T"
	}
	actualSlice, ok := takeSliceArg(actual)
	if !ok {
		return "Cannot cast actual slice to []T"
	}

	if len(expectedSlice) != len(actualSlice) {
		return fmt.Sprintf("Expected: '%v'\nActual:   '%v'\n(Should resemble: slices have different lengths.)", expectedSlice, actualSlice)
	}
	for i := 0; i < len(expectedSlice); i++ {
		if matchError := oglematchers.DeepEquals(expectedSlice[i]).Matches(actualSlice[i]); matchError != nil {
			return fmt.Sprintf("Expected: '%v'\nActual:   '%v'\n(Element[%v] Should be equal: %v)", expectedSlice, actualSlice, i, matchError)
		}
	}
	return ""
}