MCPcopy Index your code
hub / github.com/willnorris/imageproxy / TestHostMatches

Function TestHostMatches

imageproxy_test.go:176–204  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

174}
175
176func TestHostMatches(t *testing.T) {
177 hosts := []string{"a.test", "*.b.test", "*c.test"}
178
179 tests := []struct {
180 url string
181 valid bool
182 }{
183 {"http://a.test/image", true},
184 {"http://x.a.test/image", false},
185
186 {"http://b.test/image", true},
187 {"http://x.b.test/image", true},
188 {"http://x.y.b.test/image", true},
189
190 {"http://c.test/image", false},
191 {"http://xc.test/image", false},
192 {"/image", false},
193 }
194
195 for _, tt := range tests {
196 u, err := url.Parse(tt.url)
197 if err != nil {
198 t.Errorf("error parsing url %q: %v", tt.url, err)
199 }
200 if got, want := hostMatches(hosts, u), tt.valid; got != want {
201 t.Errorf("hostMatches(%v, %q) returned %v, want %v", hosts, u, got, want)
202 }
203 }
204}
205
206func TestReferrerMatches(t *testing.T) {
207 hosts := []string{"a.test"}

Callers

nothing calls this directly

Calls 1

hostMatchesFunction · 0.85

Tested by

no test coverage detected