(t *testing.T)
| 142 | } |
| 143 | |
| 144 | func TestRedirectWWWRedirect(t *testing.T) { |
| 145 | var testCases = []struct { |
| 146 | whenHost string |
| 147 | whenHeader http.Header |
| 148 | expectLocation string |
| 149 | expectStatusCode int |
| 150 | }{ |
| 151 | { |
| 152 | whenHost: "labstack.com", |
| 153 | expectLocation: "http://www.labstack.com/", |
| 154 | expectStatusCode: http.StatusMovedPermanently, |
| 155 | }, |
| 156 | { |
| 157 | whenHost: "a.com", |
| 158 | expectLocation: "http://www.a.com/", |
| 159 | expectStatusCode: http.StatusMovedPermanently, |
| 160 | }, |
| 161 | { |
| 162 | whenHost: "ip", |
| 163 | expectLocation: "http://www.ip/", |
| 164 | expectStatusCode: http.StatusMovedPermanently, |
| 165 | }, |
| 166 | { |
| 167 | whenHost: "a.com", |
| 168 | whenHeader: map[string][]string{echo.HeaderXForwardedProto: {"https"}}, |
| 169 | expectLocation: "https://www.a.com/", |
| 170 | expectStatusCode: http.StatusMovedPermanently, |
| 171 | }, |
| 172 | { |
| 173 | whenHost: "www.ip", |
| 174 | expectLocation: "", |
| 175 | expectStatusCode: http.StatusOK, |
| 176 | }, |
| 177 | } |
| 178 | |
| 179 | for _, tc := range testCases { |
| 180 | t.Run(tc.whenHost, func(t *testing.T) { |
| 181 | res := redirectTest(WWWRedirect, tc.whenHost, tc.whenHeader) |
| 182 | |
| 183 | assert.Equal(t, tc.expectStatusCode, res.Code) |
| 184 | assert.Equal(t, tc.expectLocation, res.Header().Get(echo.HeaderLocation)) |
| 185 | }) |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | func TestRedirectNonWWWRedirect(t *testing.T) { |
| 190 | var testCases = []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…