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

Function TestRedirectHTTPSNonWWWRedirect

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

Source from the content-addressed store, hash-verified

96}
97
98func TestRedirectHTTPSNonWWWRedirect(t *testing.T) {
99 var testCases = []struct {
100 whenHost string
101 whenHeader http.Header
102 expectLocation string
103 expectStatusCode int
104 }{
105 {
106 whenHost: "www.labstack.com",
107 expectLocation: "https://labstack.com/",
108 expectStatusCode: http.StatusMovedPermanently,
109 },
110 {
111 whenHost: "a.com",
112 expectLocation: "https://a.com/",
113 expectStatusCode: http.StatusMovedPermanently,
114 },
115 {
116 whenHost: "ip",
117 expectLocation: "https://ip/",
118 expectStatusCode: http.StatusMovedPermanently,
119 },
120 {
121 whenHost: "www.labstack.com",
122 whenHeader: map[string][]string{echo.HeaderXForwardedProto: {"https"}},
123 expectLocation: "https://labstack.com/",
124 expectStatusCode: http.StatusMovedPermanently,
125 },
126 {
127 whenHost: "labstack.com",
128 whenHeader: map[string][]string{echo.HeaderXForwardedProto: {"https"}},
129 expectLocation: "",
130 expectStatusCode: http.StatusOK,
131 },
132 }
133
134 for _, tc := range testCases {
135 t.Run(tc.whenHost, func(t *testing.T) {
136 res := redirectTest(HTTPSNonWWWRedirect, tc.whenHost, tc.whenHeader)
137
138 assert.Equal(t, tc.expectStatusCode, res.Code)
139 assert.Equal(t, tc.expectLocation, res.Header().Get(echo.HeaderLocation))
140 })
141 }
142}
143
144func TestRedirectWWWRedirect(t *testing.T) {
145 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…