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

Function TestContext_QueryParam

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

Source from the content-addressed store, hash-verified

856}
857
858func TestContext_QueryParam(t *testing.T) {
859 var testCases = []struct {
860 name string
861 givenURL string
862 whenParamName string
863 expect string
864 }{
865 {
866 name: "value exists in url",
867 givenURL: "/?test=1",
868 whenParamName: "test",
869 expect: "1",
870 },
871 {
872 name: "multiple values exists in url",
873 givenURL: "/?test=9&test=8",
874 whenParamName: "test",
875 expect: "9", // <-- first value in returned
876 },
877 {
878 name: "value does not exists in url",
879 givenURL: "/?nope=1",
880 whenParamName: "test",
881 expect: "",
882 },
883 {
884 name: "value is empty in url",
885 givenURL: "/?test=",
886 whenParamName: "test",
887 expect: "",
888 },
889 }
890
891 for _, tc := range testCases {
892 t.Run(tc.name, func(t *testing.T) {
893 req := httptest.NewRequest(http.MethodGet, tc.givenURL, nil)
894 e := New()
895 c := e.NewContext(req, nil)
896
897 assert.Equal(t, tc.expect, c.QueryParam(tc.whenParamName))
898 })
899 }
900}
901
902func TestContext_QueryParamDefault(t *testing.T) {
903 var testCases = []struct {

Callers

nothing calls this directly

Calls 3

QueryParamMethod · 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…