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

Function TestContext_QueryParamDefault

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

Source from the content-addressed store, hash-verified

900}
901
902func TestContext_QueryParamDefault(t *testing.T) {
903 var testCases = []struct {
904 name string
905 givenURL string
906 whenParamName string
907 whenDefaultValue string
908 expect string
909 }{
910 {
911 name: "value exists in url",
912 givenURL: "/?test=1",
913 whenParamName: "test",
914 whenDefaultValue: "999",
915 expect: "1",
916 },
917 {
918 name: "value does not exists in url",
919 givenURL: "/?nope=1",
920 whenParamName: "test",
921 whenDefaultValue: "999",
922 expect: "999",
923 },
924 {
925 name: "value is empty in url",
926 givenURL: "/?test=",
927 whenParamName: "test",
928 whenDefaultValue: "999",
929 expect: "999",
930 },
931 }
932
933 for _, tc := range testCases {
934 t.Run(tc.name, func(t *testing.T) {
935 req := httptest.NewRequest(http.MethodGet, tc.givenURL, nil)
936 e := New()
937 c := e.NewContext(req, nil)
938
939 assert.Equal(t, tc.expect, c.QueryParamOr(tc.whenParamName, tc.whenDefaultValue))
940 })
941 }
942}
943
944func TestContextFormFile(t *testing.T) {
945 e := New()

Callers

nothing calls this directly

Calls 3

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