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

Function TestRedirectHTTPSWWWRedirect

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

Source from the content-addressed store, hash-verified

45}
46
47func TestRedirectHTTPSWWWRedirect(t *testing.T) {
48 var testCases = []struct {
49 whenHost string
50 whenHeader http.Header
51 expectLocation string
52 expectStatusCode int
53 }{
54 {
55 whenHost: "labstack.com",
56 expectLocation: "https://www.labstack.com/",
57 expectStatusCode: http.StatusMovedPermanently,
58 },
59 {
60 whenHost: "www.labstack.com",
61 expectLocation: "https://www.labstack.com/",
62 expectStatusCode: http.StatusMovedPermanently,
63 },
64 {
65 whenHost: "a.com",
66 expectLocation: "https://www.a.com/",
67 expectStatusCode: http.StatusMovedPermanently,
68 },
69 {
70 whenHost: "ip",
71 expectLocation: "https://www.ip/",
72 expectStatusCode: http.StatusMovedPermanently,
73 },
74 {
75 whenHost: "labstack.com",
76 whenHeader: map[string][]string{echo.HeaderXForwardedProto: {"https"}},
77 expectLocation: "https://www.labstack.com/",
78 expectStatusCode: http.StatusMovedPermanently,
79 },
80 {
81 whenHost: "www.labstack.com",
82 whenHeader: map[string][]string{echo.HeaderXForwardedProto: {"https"}},
83 expectLocation: "",
84 expectStatusCode: http.StatusOK,
85 },
86 }
87
88 for _, tc := range testCases {
89 t.Run(tc.whenHost, func(t *testing.T) {
90 res := redirectTest(HTTPSWWWRedirect, tc.whenHost, tc.whenHeader)
91
92 assert.Equal(t, tc.expectStatusCode, res.Code)
93 assert.Equal(t, tc.expectLocation, res.Header().Get(echo.HeaderLocation))
94 })
95 }
96}
97
98func TestRedirectHTTPSNonWWWRedirect(t *testing.T) {
99 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…