(t *testing.T)
| 45 | } |
| 46 | |
| 47 | func TestRedirectHTTPSWWWRedirect(t *testing.T) { |
| 48 | var testCases = []struct { |
| 49 | whenHost string |
| 50 | whenHeader http.Header |
| 51 | expectLocation string |
| 52 | expectStatusCode int |
| 53 | }{ |
| 54 | { |
| 55 | whenHost: "labstack.com", |
| 56 | expectLocation: "https://www.labstack.com/", |
| 57 | expectStatusCode: http.StatusMovedPermanently, |
| 58 | }, |
| 59 | { |
| 60 | whenHost: "www.labstack.com", |
| 61 | expectLocation: "https://www.labstack.com/", |
| 62 | expectStatusCode: http.StatusMovedPermanently, |
| 63 | }, |
| 64 | { |
| 65 | whenHost: "a.com", |
| 66 | expectLocation: "https://www.a.com/", |
| 67 | expectStatusCode: http.StatusMovedPermanently, |
| 68 | }, |
| 69 | { |
| 70 | whenHost: "ip", |
| 71 | expectLocation: "https://www.ip/", |
| 72 | expectStatusCode: http.StatusMovedPermanently, |
| 73 | }, |
| 74 | { |
| 75 | whenHost: "labstack.com", |
| 76 | whenHeader: map[string][]string{echo.HeaderXForwardedProto: {"https"}}, |
| 77 | expectLocation: "https://www.labstack.com/", |
| 78 | expectStatusCode: http.StatusMovedPermanently, |
| 79 | }, |
| 80 | { |
| 81 | whenHost: "www.labstack.com", |
| 82 | whenHeader: map[string][]string{echo.HeaderXForwardedProto: {"https"}}, |
| 83 | expectLocation: "", |
| 84 | expectStatusCode: http.StatusOK, |
| 85 | }, |
| 86 | } |
| 87 | |
| 88 | for _, tc := range testCases { |
| 89 | t.Run(tc.whenHost, func(t *testing.T) { |
| 90 | res := redirectTest(HTTPSWWWRedirect, tc.whenHost, tc.whenHeader) |
| 91 | |
| 92 | assert.Equal(t, tc.expectStatusCode, res.Code) |
| 93 | assert.Equal(t, tc.expectLocation, res.Header().Get(echo.HeaderLocation)) |
| 94 | }) |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | func TestRedirectHTTPSNonWWWRedirect(t *testing.T) { |
| 99 | var testCases = []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…