package nixcache
import (
"net/url"
"testing"
)
func TestReadURL(t *testing.T) {
got, err := ReadURL("https://attic.example/base/", "plc-abc", "pull.jwt")
if err != nil {
t.Fatal(err)
}
u, err := url.Parse(got)
if err != nil {
t.Fatal(err)
}
password, _ := u.User.Password()
if u.Host != "attic.example" || u.Path != "/base/plc-abc" || u.User.Username() != "x" || password != "pull.jwt" {
t.Fatalf("ReadURL = %q", got)
}
for name, args := range map[string][3]string{
"cache name": {"http://attic", "../other", "tok"},
"no token": {"http://attic", "plc-abc", ""},
"unix scheme": {"unix:///run/attic", "plc-abc", "tok"},
} {
if got, err := ReadURL(args[0], args[1], args[2]); err == nil {
t.Errorf("%s: ReadURL = %q, want an error", name, got)
}
}
}