(t *testing.T)
| 900 | } |
| 901 | |
| 902 | func 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 | |
| 944 | func TestContextFormFile(t *testing.T) { |
| 945 | e := New() |
nothing calls this directly
no test coverage detected
searching dependent graphs…