Monorepo for Tangled tangled.org
4

Configure Feed

Select the types of activity you want to include in your feed.

1package repoverify 2 3import "testing" 4 5func TestNewRepoDid_RejectsInvalid(t *testing.T) { 6 if _, err := NewRepoDid(""); err == nil { 7 t.Error("NewRepoDid(\"\") err = nil, want error") 8 } 9} 10 11func TestNewRepoDid_AcceptsValid(t *testing.T) { 12 raw := "did:plc:abc123abc123abc123abc123" 13 got, err := NewRepoDid(raw) 14 if err != nil { 15 t.Fatalf("NewRepoDid(%q): %v", raw, err) 16 } 17 if got.String() != raw { 18 t.Errorf("got %q, want %q", got, raw) 19 } 20} 21 22func TestParseKnotEndpoint_RejectsHttpInProd(t *testing.T) { 23 if _, err := ParseKnotEndpoint("http://knot.example", false); err == nil { 24 t.Error("http:// knot URL accepted in prod") 25 } 26} 27 28func TestParseKnotEndpoint_AllowsHttpInDev(t *testing.T) { 29 u, err := ParseKnotEndpoint("http://knot.example", true) 30 if err != nil { 31 t.Fatalf("dev mode should allow http: %v", err) 32 } 33 if u.Host != "knot.example" { 34 t.Errorf("Host = %q, want knot.example", u.Host) 35 } 36} 37 38func TestParseKnotEndpoint_RejectsUnsupportedScheme(t *testing.T) { 39 if _, err := ParseKnotEndpoint("ftp://knot.example", true); err == nil { 40 t.Error("ParseKnotEndpoint accepted ftp:// in dev") 41 } 42 if _, err := ParseKnotEndpoint("ftp://knot.example", false); err == nil { 43 t.Error("ParseKnotEndpoint accepted ftp:// in prod") 44 } 45} 46 47func TestParseKnotEndpoint_RejectsEmptyOrHostless(t *testing.T) { 48 cases := []string{"", "https://", "not a url at all"} 49 for _, raw := range cases { 50 t.Run(raw, func(t *testing.T) { 51 if _, err := ParseKnotEndpoint(raw, false); err == nil { 52 t.Errorf("ParseKnotEndpoint(%q) accepted bogus URL", raw) 53 } 54 }) 55 } 56} 57 58func TestParseKnotEndpoint_HostPreservesPort(t *testing.T) { 59 u, err := ParseKnotEndpoint("http://localhost:3000", true) 60 if err != nil { 61 t.Fatalf("ParseKnotEndpoint: %v", err) 62 } 63 if u.Host != "localhost:3000" { 64 t.Errorf("Host = %q, want localhost:3000", u.Host) 65 } 66}