(t *testing.T)
| 174 | } |
| 175 | |
| 176 | func 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 | |
| 206 | func TestReferrerMatches(t *testing.T) { |
| 207 | hosts := []string{"a.test"} |
nothing calls this directly
no test coverage detected