(t *testing.T)
| 1100 | } |
| 1101 | |
| 1102 | func TestContainsNotContainsFailMessage(t *testing.T) { |
| 1103 | t.Parallel() |
| 1104 | |
| 1105 | mockT := new(mockTestingT) |
| 1106 | |
| 1107 | type nonContainer struct { |
| 1108 | Value string |
| 1109 | } |
| 1110 | |
| 1111 | cases := []struct { |
| 1112 | assertion func(t TestingT, s, contains interface{}, msgAndArgs ...interface{}) bool |
| 1113 | container interface{} |
| 1114 | instance interface{} |
| 1115 | expected string |
| 1116 | }{ |
| 1117 | { |
| 1118 | assertion: Contains, |
| 1119 | container: "Hello World", |
| 1120 | instance: errors.New("Hello"), |
| 1121 | expected: "\"Hello World\" does not contain &errors.errorString{s:\"Hello\"}", |
| 1122 | }, |
| 1123 | { |
| 1124 | assertion: Contains, |
| 1125 | container: map[string]int{"one": 1}, |
| 1126 | instance: "two", |
| 1127 | expected: "map[string]int{\"one\":1} does not contain \"two\"\n", |
| 1128 | }, |
| 1129 | { |
| 1130 | assertion: NotContains, |
| 1131 | container: map[string]int{"one": 1}, |
| 1132 | instance: "one", |
| 1133 | expected: "map[string]int{\"one\":1} should not contain \"one\"", |
| 1134 | }, |
| 1135 | { |
| 1136 | assertion: Contains, |
| 1137 | container: nonContainer{Value: "Hello"}, |
| 1138 | instance: "Hello", |
| 1139 | expected: "assert.nonContainer{Value:\"Hello\"} could not be applied builtin len()\n", |
| 1140 | }, |
| 1141 | { |
| 1142 | assertion: NotContains, |
| 1143 | container: nonContainer{Value: "Hello"}, |
| 1144 | instance: "Hello", |
| 1145 | expected: "assert.nonContainer{Value:\"Hello\"} could not be applied builtin len()\n", |
| 1146 | }, |
| 1147 | } |
| 1148 | for _, c := range cases { |
| 1149 | name := filepath.Base(runtime.FuncForPC(reflect.ValueOf(c.assertion).Pointer()).Name()) |
| 1150 | t.Run(fmt.Sprintf("%v(%T, %T)", name, c.container, c.instance), func(t *testing.T) { |
| 1151 | c.assertion(mockT, c.container, c.instance) |
| 1152 | actualFail := mockT.errorString() |
| 1153 | if !strings.Contains(actualFail, c.expected) { |
| 1154 | t.Errorf("Contains failure should include %q but was %q", c.expected, actualFail) |
| 1155 | } |
| 1156 | }) |
| 1157 | } |
| 1158 | } |
| 1159 |
nothing calls this directly
no test coverage detected