SourceURL() previously hardcoded https:// regardless of the AllowHTTP config setting. This made testing with HTTP-only test servers impossible. Add AllowHTTP field to ImageRequest and use it to determine the URL scheme. The Service propagates the config setting to each request. Fixes #1
45 lines
985 B
Go
45 lines
985 B
Go
package imgcache
|
|
|
|
import "testing"
|
|
|
|
func TestImageRequest_SourceURL_DefaultHTTPS(t *testing.T) {
|
|
req := &ImageRequest{
|
|
SourceHost: "cdn.example.com",
|
|
SourcePath: "/photos/cat.jpg",
|
|
SourceQuery: "v=2",
|
|
}
|
|
|
|
got := req.SourceURL()
|
|
want := "https://cdn.example.com/photos/cat.jpg?v=2"
|
|
if got != want {
|
|
t.Errorf("SourceURL() = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestImageRequest_SourceURL_AllowHTTP(t *testing.T) {
|
|
req := &ImageRequest{
|
|
SourceHost: "localhost:8080",
|
|
SourcePath: "/photos/cat.jpg",
|
|
AllowHTTP: true,
|
|
}
|
|
|
|
got := req.SourceURL()
|
|
want := "http://localhost:8080/photos/cat.jpg"
|
|
if got != want {
|
|
t.Errorf("SourceURL() = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestImageRequest_SourceURL_AllowHTTPFalse(t *testing.T) {
|
|
req := &ImageRequest{
|
|
SourceHost: "cdn.example.com",
|
|
SourcePath: "/img.jpg",
|
|
AllowHTTP: false,
|
|
}
|
|
|
|
got := req.SourceURL()
|
|
if got != "https://cdn.example.com/img.jpg" {
|
|
t.Errorf("SourceURL() = %q, want https scheme", got)
|
|
}
|
|
}
|