~james/core

core/spindle/nixcache/upstream_test.go -rw-r--r-- 787 bytes
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 16 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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)
		}
	}
}