MCPcopy
hub / github.com/labstack/echo / TestValueBinder_String

Function TestValueBinder_String

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

Source from the content-addressed store, hash-verified

416}
417
418func TestValueBinder_String(t *testing.T) {
419 var testCases = []struct {
420 name string
421 whenURL string
422 expectValue string
423 expectError string
424 givenBindErrors []error
425 givenFailFast bool
426 whenMust bool
427 }{
428 {
429 name: "ok, binds value",
430 whenURL: "/search?param=en&param=de",
431 expectValue: "en",
432 },
433 {
434 name: "ok, params values empty, value is not changed",
435 whenURL: "/search?nr=en",
436 expectValue: "default",
437 },
438 {
439 name: "nok, previous errors fail fast without binding value",
440 givenFailFast: true,
441 whenURL: "/search?nr=en&id=1&id=100",
442 expectValue: "default",
443 expectError: "previous error",
444 },
445 {
446 name: "ok (must), binds value",
447 whenMust: true,
448 whenURL: "/search?param=en&param=de",
449 expectValue: "en",
450 },
451 {
452 name: "ok (must), params values empty, returns error, value is not changed",
453 whenMust: true,
454 whenURL: "/search?nr=en",
455 expectValue: "default",
456 expectError: "code=400, message=required field value is empty, field=param",
457 },
458 {
459 name: "nok (must), previous errors fail fast without binding value",
460 givenFailFast: true,
461 whenMust: true,
462 whenURL: "/search?nr=en&id=1&id=100",
463 expectValue: "default",
464 expectError: "previous error",
465 },
466 }
467
468 for _, tc := range testCases {
469 t.Run(tc.name, func(t *testing.T) {
470 c := createTestContext(tc.whenURL, nil, nil)
471 b := QueryParamsBinder(c).FailFast(tc.givenFailFast)
472 if tc.givenFailFast {
473 b.errors = []error{errors.New("previous error")}
474 }
475

Callers

nothing calls this directly

Calls 6

createTestContextFunction · 0.85
QueryParamsBinderFunction · 0.85
FailFastMethod · 0.80
BindErrorMethod · 0.80
MustStringMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…