MCPcopy Index your code
hub / github.com/labstack/echo / TestValueBinder_Bools

Function TestValueBinder_Bools

binder_test.go:1315–1409  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1313}
1314
1315func 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&param=false&param=1&param=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&param=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&param=nope&param=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&param=nope&param=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&param=false&param=1&param=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")},

Callers

nothing calls this directly

Calls 6

createTestContextFunction · 0.85
QueryParamsBinderFunction · 0.85
FailFastMethod · 0.80
BindErrorMethod · 0.80
MustBoolsMethod · 0.80
BoolsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…