func compare()

in report/diff_message.go [60:131]


func compare(got interface{}, expect interface{}, path string) []string {
	if expect == nil && got == nil {
		return []string{}
	}
	if expect == nil {
		return []string{fmt.Sprintf("%s: expect null, but got %v", path, got)}
	}
	if got == nil {
		return []string{fmt.Sprintf("%s = %v: not returned from response", path, expect)}
	}
	switch expectValue := expect.(type) {
	case map[string]interface{}:
		if gotMap, ok := got.(map[string]interface{}); ok {
			res := make([]string, 0)
			for key, value := range expectValue {
				res = append(res, compare(gotMap[key], value, fmt.Sprintf("%s.%s", path, key))...)
			}
			return res
		} else {
			return []string{fmt.Sprintf("%s: expect %v which is a map, but got %v", path, expect, got)}
		}
	case []interface{}:
		if gotArr, ok := got.([]interface{}); ok {
			if len(gotArr) != len(expectValue) {
				return []string{fmt.Sprintf("%s: expect %d in length, but got %d", path, len(expectValue), len(gotArr))}
			}
			res := make([]string, 0)
			for index := range expectValue {
				res = append(res, compare(gotArr[index], expectValue[index], fmt.Sprintf("%s.%d", path, index))...)
			}
			return res
		} else {
			return []string{fmt.Sprintf("%s: expect %v which is an array, but got %v", path, expect, got)}
		}
	case bool:
		if gotBool, ok := got.(bool); ok {
			if gotBool != expectValue {
				return []string{fmt.Sprintf("%s: expect %v, but got %v", path, expect, got)}
			}
		} else {
			return []string{fmt.Sprintf("%s: expect %v which is a bool, but got %v", path, expect, got)}
		}
	case string:
		if gotString, ok := got.(string); ok {
			if gotString != expectValue {
				if strings.EqualFold(gotString, expectValue) {
					return []string{fmt.Sprintf("%s: the values are not equal case-sensitively, expect %v, but got %v", path, expect, got)}
				}
				return []string{fmt.Sprintf("%s: expect %v, but got %v", path, expect, got)}
			}
		} else {
			return []string{fmt.Sprintf("%s: expect %v which is a string, but got %v", path, expect, got)}
		}
	case float64:
		if gotFloat, ok := got.(float64); ok {
			if gotFloat != expectValue {
				return []string{fmt.Sprintf("%s: expect %v, but got %v", path, expect, got)}
			}
		} else {
			return []string{fmt.Sprintf("%s: expect %v which is a number, but got %v", path, expect, got)}
		}
	case int64:
		if gotInt, ok := got.(int64); ok {
			if gotInt != expectValue {
				return []string{fmt.Sprintf("%s: expect %v, but got %v", path, expect, got)}
			}
		} else {
			return []string{fmt.Sprintf("%s: expect %v which is a number, but got %v", path, expect, got)}
		}
	}
	return nil
}