mirror of
https://github.com/willnorris/imageproxy.git
synced 2024-12-16 21:56:43 -05:00
e1558d5626
it's a little bit rough, but seems to work pretty well. Ref #145
34 lines
915 B
Go
34 lines
915 B
Go
package main
|
|
|
|
import (
|
|
"net/url"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseURL(t *testing.T) {
|
|
tests := []struct {
|
|
input, output string
|
|
}{
|
|
{"/", "/#0x0"},
|
|
|
|
// imageproxy URLs
|
|
{"http://localhost:8080//http://example.com/", "http://example.com/#0x0"},
|
|
{"http://localhost:8080/10,r90,jpeg/http://example.com/", "http://example.com/#10x10,jpeg,r90"},
|
|
|
|
// remote URLs, with and without options
|
|
{"http://example.com/", "http://example.com/#0x0"},
|
|
{"http://example.com/#r90,jpeg", "http://example.com/#0x0,jpeg,r90"},
|
|
|
|
// ensure signature values are stripped
|
|
{"http://localhost:8080/sc0ffee/http://example.com/", "http://example.com/#0x0"},
|
|
{"http://example.com/#sc0ffee", "http://example.com/#0x0"},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
want, _ := url.Parse(tt.output)
|
|
got := parseURL(tt.input)
|
|
if got.String() != want.String() {
|
|
t.Errorf("parseURL(%q) returned %q, want %q", tt.input, got, want)
|
|
}
|
|
}
|
|
}
|