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

Function TestValueBinder_Strings

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

Source from the content-addressed store, hash-verified

492}
493
494func TestValueBinder_Strings(t *testing.T) {
495 var testCases = []struct {
496 name string
497 whenURL string
498 expectError string
499 givenBindErrors []error
500 expectValue []string
501 givenFailFast bool
502 whenMust bool
503 }{
504 {
505 name: "ok, binds value",
506 whenURL: "/search?param=en&param=de",
507 expectValue: []string{"en", "de"},
508 },
509 {
510 name: "ok, params values empty, value is not changed",
511 whenURL: "/search?nr=en",
512 expectValue: []string{"default"},
513 },
514 {
515 name: "nok, previous errors fail fast without binding value",
516 givenFailFast: true,
517 whenURL: "/search?nr=en&id=1&id=100",
518 expectValue: []string{"default"},
519 expectError: "previous error",
520 },
521 {
522 name: "ok (must), binds value",
523 whenMust: true,
524 whenURL: "/search?param=en&param=de",
525 expectValue: []string{"en", "de"},
526 },
527 {
528 name: "ok (must), params values empty, returns error, value is not changed",
529 whenMust: true,
530 whenURL: "/search?nr=en",
531 expectValue: []string{"default"},
532 expectError: "code=400, message=required field value is empty, field=param",
533 },
534 {
535 name: "nok (must), previous errors fail fast without binding value",
536 givenFailFast: true,
537 whenMust: true,
538 whenURL: "/search?nr=en&id=1&id=100",
539 expectValue: []string{"default"},
540 expectError: "previous error",
541 },
542 }
543
544 for _, tc := range testCases {
545 t.Run(tc.name, func(t *testing.T) {
546 c := createTestContext(tc.whenURL, nil, nil)
547 b := QueryParamsBinder(c).FailFast(tc.givenFailFast)
548 if tc.givenFailFast {
549 b.errors = []error{errors.New("previous error")}
550 }
551

Callers

nothing calls this directly

Calls 6

createTestContextFunction · 0.85
QueryParamsBinderFunction · 0.85
FailFastMethod · 0.80
BindErrorMethod · 0.80
MustStringsMethod · 0.80
StringsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…