(t *testing.T)
| 856 | } |
| 857 | |
| 858 | func 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 | |
| 902 | func TestContext_QueryParamDefault(t *testing.T) { |
| 903 | var testCases = []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…