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

Function TestRedirectWWWRedirect

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

Source from the content-addressed store, hash-verified

142}
143
144func 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
189func TestRedirectNonWWWRedirect(t *testing.T) {
190 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…