(t *testing.T)
| 187 | } |
| 188 | |
| 189 | func TestRedirectNonWWWRedirect(t *testing.T) { |
| 190 | var testCases = []struct { |
| 191 | whenHost string |
| 192 | whenHeader http.Header |
| 193 | expectLocation string |
| 194 | expectStatusCode int |
| 195 | }{ |
| 196 | { |
| 197 | whenHost: "www.labstack.com", |
| 198 | expectLocation: "http://labstack.com/", |
| 199 | expectStatusCode: http.StatusMovedPermanently, |
| 200 | }, |
| 201 | { |
| 202 | whenHost: "www.a.com", |
| 203 | expectLocation: "http://a.com/", |
| 204 | expectStatusCode: http.StatusMovedPermanently, |
| 205 | }, |
| 206 | { |
| 207 | whenHost: "www.a.com", |
| 208 | whenHeader: map[string][]string{echo.HeaderXForwardedProto: {"https"}}, |
| 209 | expectLocation: "https://a.com/", |
| 210 | expectStatusCode: http.StatusMovedPermanently, |
| 211 | }, |
| 212 | { |
| 213 | whenHost: "ip", |
| 214 | expectLocation: "", |
| 215 | expectStatusCode: http.StatusOK, |
| 216 | }, |
| 217 | } |
| 218 | |
| 219 | for _, tc := range testCases { |
| 220 | t.Run(tc.whenHost, func(t *testing.T) { |
| 221 | res := redirectTest(NonWWWRedirect, tc.whenHost, tc.whenHeader) |
| 222 | |
| 223 | assert.Equal(t, tc.expectStatusCode, res.Code) |
| 224 | assert.Equal(t, tc.expectLocation, res.Header().Get(echo.HeaderLocation)) |
| 225 | }) |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | func TestNonWWWRedirectWithConfig(t *testing.T) { |
| 230 | var testCases = []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…