(t *testing.T)
| 198 | } |
| 199 | |
| 200 | func TestValueBinder_GetValues(t *testing.T) { |
| 201 | var testCases = []struct { |
| 202 | whenValuesFunc func(sourceParam string) []string |
| 203 | name string |
| 204 | expectError string |
| 205 | expect []int64 |
| 206 | }{ |
| 207 | { |
| 208 | name: "ok, default implementation", |
| 209 | expect: []int64{1, 101}, |
| 210 | }, |
| 211 | { |
| 212 | name: "ok, values returns nil", |
| 213 | whenValuesFunc: func(sourceParam string) []string { |
| 214 | return nil |
| 215 | }, |
| 216 | expect: []int64(nil), |
| 217 | }, |
| 218 | { |
| 219 | name: "ok, values returns empty slice", |
| 220 | whenValuesFunc: func(sourceParam string) []string { |
| 221 | return []string{} |
| 222 | }, |
| 223 | expect: []int64(nil), |
| 224 | }, |
| 225 | } |
| 226 | |
| 227 | for _, tc := range testCases { |
| 228 | t.Run(tc.name, func(t *testing.T) { |
| 229 | c := createTestContext("/search?nr=en&id=1&id=101", nil, nil) |
| 230 | b := QueryParamsBinder(c) |
| 231 | if tc.whenValuesFunc != nil { |
| 232 | b.ValuesFunc = tc.whenValuesFunc |
| 233 | } |
| 234 | |
| 235 | var IDs []int64 |
| 236 | err := b.Int64s("id", &IDs).BindError() |
| 237 | |
| 238 | assert.Equal(t, tc.expect, IDs) |
| 239 | if tc.expectError != "" { |
| 240 | assert.EqualError(t, err, tc.expectError) |
| 241 | } else { |
| 242 | assert.NoError(t, err) |
| 243 | } |
| 244 | }) |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | func TestValueBinder_CustomFuncWithError(t *testing.T) { |
| 249 | c := createTestContext("/search?nr=en&id=1&id=101", nil, nil) |
nothing calls this directly
no test coverage detected
searching dependent graphs…