(t *testing.T)
| 1050 | } |
| 1051 | |
| 1052 | func TestContainsNotContainsFailMessage(t *testing.T) { |
| 1053 | mockT := new(mockTestingT) |
| 1054 | |
| 1055 | type nonContainer struct { |
| 1056 | Value string |
| 1057 | } |
| 1058 | |
| 1059 | cases := []struct { |
| 1060 | assertion func(t TestingT, s, contains interface{}, msgAndArgs ...interface{}) bool |
| 1061 | container interface{} |
| 1062 | instance interface{} |
| 1063 | expected string |
| 1064 | }{ |
| 1065 | { |
| 1066 | assertion: Contains, |
| 1067 | container: "Hello World", |
| 1068 | instance: errors.New("Hello"), |
| 1069 | expected: "\"Hello World\" does not contain &errors.errorString{s:\"Hello\"}", |
| 1070 | }, |
| 1071 | { |
| 1072 | assertion: Contains, |
| 1073 | container: map[string]int{"one": 1}, |
| 1074 | instance: "two", |
| 1075 | expected: "map[string]int{\"one\":1} does not contain \"two\"\n", |
| 1076 | }, |
| 1077 | { |
| 1078 | assertion: NotContains, |
| 1079 | container: map[string]int{"one": 1}, |
| 1080 | instance: "one", |
| 1081 | expected: "map[string]int{\"one\":1} should not contain \"one\"", |
| 1082 | }, |
| 1083 | { |
| 1084 | assertion: Contains, |
| 1085 | container: nonContainer{Value: "Hello"}, |
| 1086 | instance: "Hello", |
| 1087 | expected: "assert.nonContainer{Value:\"Hello\"} could not be applied builtin len()\n", |
| 1088 | }, |
| 1089 | { |
| 1090 | assertion: NotContains, |
| 1091 | container: nonContainer{Value: "Hello"}, |
| 1092 | instance: "Hello", |
| 1093 | expected: "assert.nonContainer{Value:\"Hello\"} could not be applied builtin len()\n", |
| 1094 | }, |
| 1095 | } |
| 1096 | for _, c := range cases { |
| 1097 | name := filepath.Base(runtime.FuncForPC(reflect.ValueOf(c.assertion).Pointer()).Name()) |
| 1098 | t.Run(fmt.Sprintf("%v(%T, %T)", name, c.container, c.instance), func(t *testing.T) { |
| 1099 | c.assertion(mockT, c.container, c.instance) |
| 1100 | actualFail := mockT.errorString() |
| 1101 | if !strings.Contains(actualFail, c.expected) { |
| 1102 | t.Errorf("Contains failure should include %q but was %q", c.expected, actualFail) |
| 1103 | } |
| 1104 | }) |
| 1105 | } |
| 1106 | } |
| 1107 | |
| 1108 | func TestContainsNotContainsOnNilValue(t *testing.T) { |
| 1109 | mockT := new(mockTestingT) |
nothing calls this directly
no test coverage detected