(t *testing.T)
| 15 | type middlewareGenerator func() echo.MiddlewareFunc |
| 16 | |
| 17 | func TestRedirectHTTPSRedirect(t *testing.T) { |
| 18 | var testCases = []struct { |
| 19 | whenHost string |
| 20 | whenHeader http.Header |
| 21 | expectLocation string |
| 22 | expectStatusCode int |
| 23 | }{ |
| 24 | { |
| 25 | whenHost: "labstack.com", |
| 26 | expectLocation: "https://labstack.com/", |
| 27 | expectStatusCode: http.StatusMovedPermanently, |
| 28 | }, |
| 29 | { |
| 30 | whenHost: "labstack.com", |
| 31 | whenHeader: map[string][]string{echo.HeaderXForwardedProto: {"https"}}, |
| 32 | expectLocation: "", |
| 33 | expectStatusCode: http.StatusOK, |
| 34 | }, |
| 35 | } |
| 36 | |
| 37 | for _, tc := range testCases { |
| 38 | t.Run(tc.whenHost, func(t *testing.T) { |
| 39 | res := redirectTest(HTTPSRedirect, tc.whenHost, tc.whenHeader) |
| 40 | |
| 41 | assert.Equal(t, tc.expectStatusCode, res.Code) |
| 42 | assert.Equal(t, tc.expectLocation, res.Header().Get(echo.HeaderLocation)) |
| 43 | }) |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | func TestRedirectHTTPSWWWRedirect(t *testing.T) { |
| 48 | var testCases = []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…