(t *testing.T)
| 1313 | } |
| 1314 | |
| 1315 | func TestValueBinder_Bools(t *testing.T) { |
| 1316 | var testCases = []struct { |
| 1317 | name string |
| 1318 | whenURL string |
| 1319 | expectError string |
| 1320 | givenBindErrors []error |
| 1321 | expectValue []bool |
| 1322 | givenFailFast bool |
| 1323 | whenMust bool |
| 1324 | }{ |
| 1325 | { |
| 1326 | name: "ok, binds value", |
| 1327 | whenURL: "/search?param=true¶m=false¶m=1¶m=0", |
| 1328 | expectValue: []bool{true, false, true, false}, |
| 1329 | }, |
| 1330 | { |
| 1331 | name: "ok, params values empty, value is not changed", |
| 1332 | whenURL: "/search?nope=1", |
| 1333 | expectValue: []bool(nil), |
| 1334 | }, |
| 1335 | { |
| 1336 | name: "nok, previous errors fail fast without binding value", |
| 1337 | givenFailFast: true, |
| 1338 | givenBindErrors: []error{errors.New("previous error")}, |
| 1339 | whenURL: "/search?param=1¶m=100", |
| 1340 | expectValue: []bool(nil), |
| 1341 | expectError: "previous error", |
| 1342 | }, |
| 1343 | { |
| 1344 | name: "nok, conversion fails, value is not changed", |
| 1345 | whenURL: "/search?param=true¶m=nope¶m=100", |
| 1346 | expectValue: []bool(nil), |
| 1347 | expectError: "code=400, message=failed to bind field value to bool, err=strconv.ParseBool: parsing \"nope\": invalid syntax, field=param", |
| 1348 | }, |
| 1349 | { |
| 1350 | name: "nok, conversion fails fast, value is not changed", |
| 1351 | givenFailFast: true, |
| 1352 | whenURL: "/search?param=true¶m=nope¶m=100", |
| 1353 | expectValue: []bool(nil), |
| 1354 | expectError: "code=400, message=failed to bind field value to bool, err=strconv.ParseBool: parsing \"nope\": invalid syntax, field=param", |
| 1355 | }, |
| 1356 | { |
| 1357 | name: "ok (must), binds value", |
| 1358 | whenMust: true, |
| 1359 | whenURL: "/search?param=true¶m=false¶m=1¶m=0", |
| 1360 | expectValue: []bool{true, false, true, false}, |
| 1361 | }, |
| 1362 | { |
| 1363 | name: "ok (must), params values empty, returns error, value is not changed", |
| 1364 | whenMust: true, |
| 1365 | whenURL: "/search?nope=1", |
| 1366 | expectValue: []bool(nil), |
| 1367 | expectError: "code=400, message=required field value is empty, field=param", |
| 1368 | }, |
| 1369 | { |
| 1370 | name: "nok (must), previous errors fail fast without binding value", |
| 1371 | givenFailFast: true, |
| 1372 | givenBindErrors: []error{errors.New("previous error")}, |
nothing calls this directly
no test coverage detected
searching dependent graphs…