MCPcopy
hub / github.com/labstack/echo / TestRedirectNonWWWRedirect

Function TestRedirectNonWWWRedirect

middleware/redirect_test.go:189–227  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

187}
188
189func 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
229func TestNonWWWRedirectWithConfig(t *testing.T) {
230 var testCases = []struct {

Callers

nothing calls this directly

Calls 3

redirectTestFunction · 0.85
GetMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…