forked from
tangled.org/core
Monorepo for Tangled
1.4 kB
49 lines
1package repoverify
2
3import "testing"
4
5func TestParseKnotEndpoint_RejectsHttpInProd(t *testing.T) {
6 if _, err := ParseKnotEndpoint("http://knot.example", false); err == nil {
7 t.Error("http:// knot URL accepted in prod")
8 }
9}
10
11func TestParseKnotEndpoint_AllowsHttpInDev(t *testing.T) {
12 u, err := ParseKnotEndpoint("http://knot.example", true)
13 if err != nil {
14 t.Fatalf("dev mode should allow http: %v", err)
15 }
16 if u.Host != "knot.example" {
17 t.Errorf("Host = %q, want knot.example", u.Host)
18 }
19}
20
21func TestParseKnotEndpoint_RejectsUnsupportedScheme(t *testing.T) {
22 if _, err := ParseKnotEndpoint("ftp://knot.example", true); err == nil {
23 t.Error("ParseKnotEndpoint accepted ftp:// in dev")
24 }
25 if _, err := ParseKnotEndpoint("ftp://knot.example", false); err == nil {
26 t.Error("ParseKnotEndpoint accepted ftp:// in prod")
27 }
28}
29
30func TestParseKnotEndpoint_RejectsEmptyOrHostless(t *testing.T) {
31 cases := []string{"", "https://", "not a url at all"}
32 for _, raw := range cases {
33 t.Run(raw, func(t *testing.T) {
34 if _, err := ParseKnotEndpoint(raw, false); err == nil {
35 t.Errorf("ParseKnotEndpoint(%q) accepted bogus URL", raw)
36 }
37 })
38 }
39}
40
41func TestParseKnotEndpoint_HostPreservesPort(t *testing.T) {
42 u, err := ParseKnotEndpoint("http://localhost:3000", true)
43 if err != nil {
44 t.Fatalf("ParseKnotEndpoint: %v", err)
45 }
46 if u.Host != "localhost:3000" {
47 t.Errorf("Host = %q, want localhost:3000", u.Host)
48 }
49}