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

Function TestContext_PathParamDefault

context_test.go:636–686  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

634}
635
636func TestContext_PathParamDefault(t *testing.T) {
637 var testCases = []struct {
638 name string
639 given PathValues
640 whenParamName string
641 whenDefaultValue string
642 expect string
643 }{
644 {
645 name: "param exists",
646 given: PathValues{
647 {Name: "uid", Value: "101"},
648 {Name: "fid", Value: "501"},
649 },
650 whenParamName: "uid",
651 whenDefaultValue: "999",
652 expect: "101",
653 },
654 {
655 name: "param exists and is empty",
656 given: PathValues{
657 {Name: "uid", Value: ""},
658 {Name: "fid", Value: "501"},
659 },
660 whenParamName: "uid",
661 whenDefaultValue: "999",
662 expect: "", // <-- this is different from QueryParamOr behaviour
663 },
664 {
665 name: "param does not exists",
666 given: PathValues{
667 {Name: "uid", Value: "101"},
668 },
669 whenParamName: "nope",
670 whenDefaultValue: "999",
671 expect: "999",
672 },
673 }
674
675 for _, tc := range testCases {
676 t.Run(tc.name, func(t *testing.T) {
677 e := New()
678 req := httptest.NewRequest(http.MethodGet, "/", nil)
679 c := e.NewContext(req, nil)
680
681 c.SetPathValues(tc.given)
682
683 assert.EqualValues(t, tc.expect, c.ParamOr(tc.whenParamName, tc.whenDefaultValue))
684 })
685 }
686}
687
688func TestContextGetAndSetPathValuesMutability(t *testing.T) {
689 t.Run("c.PathValues() does not return copy and modifying raw slice mutates value in context", func(t *testing.T) {

Callers

nothing calls this directly

Calls 4

SetPathValuesMethod · 0.95
ParamOrMethod · 0.95
NewFunction · 0.85
NewContextMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…