An unofficial terminal client for Tangled, optimized for humans and agents. tgcli.wisp.place
cli atproto go tangled
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081package app
import ( "testing")
func TestParseTarget(t *testing.T) { tests := []struct { name string arg string wantHandle string wantRepo string wantErr bool }{ {name: "handle and repo", arg: "aly.codes/tg", wantHandle: "aly.codes", wantRepo: "tg"}, {name: "did handle", arg: "did:plc:abc123/tg", wantHandle: "did:plc:abc123", wantRepo: "tg"}, // Repo names become atproto record keys, which cannot contain "/". {name: "repo containing slash", arg: "aly.codes/a/b", wantErr: true}, {name: "no slash", arg: "tg", wantErr: true}, {name: "empty handle", arg: "/tg", wantErr: true}, {name: "empty repo", arg: "aly.codes/", wantErr: true}, {name: "empty", arg: "", wantErr: true}, }
for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { target, err := ParseTarget(tt.arg) if (err != nil) != tt.wantErr { t.Fatalf("error = %v, wantErr %v", err, tt.wantErr) } if target.Handle != tt.wantHandle || target.Repo != tt.wantRepo { t.Fatalf("got (%q, %q), want (%q, %q)", target.Handle, target.Repo, tt.wantHandle, tt.wantRepo) } }) }}
func TestParseKnotServiceEndpoint(t *testing.T) { tests := []struct { raw string wantAuthority string wantHostname string }{ {raw: "https://KNOT.EXAMPLE", wantAuthority: "knot.example", wantHostname: "knot.example"}, {raw: "https://KNOT.EXAMPLE/", wantAuthority: "knot.example", wantHostname: "knot.example"}, {raw: "https://KNOT.EXAMPLE:443/", wantAuthority: "knot.example", wantHostname: "knot.example"}, {raw: "https://KNOT.EXAMPLE:00443/", wantAuthority: "knot.example", wantHostname: "knot.example"}, {raw: "https://knot.example:8443/", wantAuthority: "knot.example:8443", wantHostname: "knot.example"}, {raw: "https://knot.example/xrpc"}, {raw: "http://knot.example"}, {raw: "https://user@knot.example"}, {raw: "https://knot.example?query=yes"}, {raw: "https://knot.example/#fragment"}, {raw: "https://knot.example:0/"}, {raw: "https://knot.example:65536/"}, {raw: "https://knot.example:not-a-port/"}, } for _, tt := range tests { t.Run(tt.raw, func(t *testing.T) { got, err := parseKnotServiceEndpoint(tt.raw) if tt.wantAuthority == "" { if err == nil { t.Fatalf("parseKnotServiceEndpoint() = %+v, want error", got) } return } want := knotServiceEndpoint{Authority: tt.wantAuthority, Hostname: tt.wantHostname} if err != nil || got != want { t.Fatalf("parseKnotServiceEndpoint() = %+v, %v, want %+v", got, err, want) } }) }}
func TestTargetString(t *testing.T) { target := Target{Handle: "aly.codes", Repo: "tg"} if got := target.String(); got != "aly.codes/tg" { t.Fatalf("String() = %q, want %q", got, "aly.codes/tg") }}