(t *testing.T)
| 96 | } |
| 97 | |
| 98 | func TestRedirectHTTPSNonWWWRedirect(t *testing.T) { |
| 99 | var testCases = []struct { |
| 100 | whenHost string |
| 101 | whenHeader http.Header |
| 102 | expectLocation string |
| 103 | expectStatusCode int |
| 104 | }{ |
| 105 | { |
| 106 | whenHost: "www.labstack.com", |
| 107 | expectLocation: "https://labstack.com/", |
| 108 | expectStatusCode: http.StatusMovedPermanently, |
| 109 | }, |
| 110 | { |
| 111 | whenHost: "a.com", |
| 112 | expectLocation: "https://a.com/", |
| 113 | expectStatusCode: http.StatusMovedPermanently, |
| 114 | }, |
| 115 | { |
| 116 | whenHost: "ip", |
| 117 | expectLocation: "https://ip/", |
| 118 | expectStatusCode: http.StatusMovedPermanently, |
| 119 | }, |
| 120 | { |
| 121 | whenHost: "www.labstack.com", |
| 122 | whenHeader: map[string][]string{echo.HeaderXForwardedProto: {"https"}}, |
| 123 | expectLocation: "https://labstack.com/", |
| 124 | expectStatusCode: http.StatusMovedPermanently, |
| 125 | }, |
| 126 | { |
| 127 | whenHost: "labstack.com", |
| 128 | whenHeader: map[string][]string{echo.HeaderXForwardedProto: {"https"}}, |
| 129 | expectLocation: "", |
| 130 | expectStatusCode: http.StatusOK, |
| 131 | }, |
| 132 | } |
| 133 | |
| 134 | for _, tc := range testCases { |
| 135 | t.Run(tc.whenHost, func(t *testing.T) { |
| 136 | res := redirectTest(HTTPSNonWWWRedirect, tc.whenHost, tc.whenHeader) |
| 137 | |
| 138 | assert.Equal(t, tc.expectStatusCode, res.Code) |
| 139 | assert.Equal(t, tc.expectLocation, res.Header().Get(echo.HeaderLocation)) |
| 140 | }) |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | func TestRedirectWWWRedirect(t *testing.T) { |
| 145 | var testCases = []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…