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

Function TestRedirectHTTPSRedirect

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

Source from the content-addressed store, hash-verified

15type middlewareGenerator func() echo.MiddlewareFunc
16
17func TestRedirectHTTPSRedirect(t *testing.T) {
18 var testCases = []struct {
19 whenHost string
20 whenHeader http.Header
21 expectLocation string
22 expectStatusCode int
23 }{
24 {
25 whenHost: "labstack.com",
26 expectLocation: "https://labstack.com/",
27 expectStatusCode: http.StatusMovedPermanently,
28 },
29 {
30 whenHost: "labstack.com",
31 whenHeader: map[string][]string{echo.HeaderXForwardedProto: {"https"}},
32 expectLocation: "",
33 expectStatusCode: http.StatusOK,
34 },
35 }
36
37 for _, tc := range testCases {
38 t.Run(tc.whenHost, func(t *testing.T) {
39 res := redirectTest(HTTPSRedirect, tc.whenHost, tc.whenHeader)
40
41 assert.Equal(t, tc.expectStatusCode, res.Code)
42 assert.Equal(t, tc.expectLocation, res.Header().Get(echo.HeaderLocation))
43 })
44 }
45}
46
47func TestRedirectHTTPSWWWRedirect(t *testing.T) {
48 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…