Monorepo for Tangled
tangled.org
1package repoinfo
2
3import "testing"
4
5func TestSlug(t *testing.T) {
6 cases := []struct {
7 name string
8 info RepoInfo
9 want string
10 }{
11 {"name preferred over rkey", RepoInfo{Name: "barnacle", Rkey: "3kabc"}, "barnacle"},
12 {"name equals rkey", RepoInfo{Name: "clam", Rkey: "clam"}, "clam"},
13 {"name empty falls to rkey", RepoInfo{Rkey: "limpet"}, "limpet"},
14 }
15 for _, c := range cases {
16 t.Run(c.name, func(t *testing.T) {
17 if got := c.info.Slug(); got != c.want {
18 t.Errorf("Slug() = %q, want %q", got, c.want)
19 }
20 })
21 }
22}
23
24func TestFullName_PrefersNameOverRkey(t *testing.T) {
25 info := RepoInfo{OwnerHandle: "boltless.dev", Name: "uni", Rkey: "3kabcxyz"}
26 if got, want := info.FullName(), "boltless.dev/uni"; got != want {
27 t.Errorf("FullName() = %q, want %q", got, want)
28 }
29 if got, want := info.FullNameWithoutAt(), "boltless.dev/uni"; got != want {
30 t.Errorf("FullNameWithoutAt() = %q, want %q", got, want)
31 }
32}
33
34func TestFullName_FallsBackToRkey(t *testing.T) {
35 info := RepoInfo{OwnerHandle: "akshay.dev", Rkey: "3kabcxyz"}
36 if got, want := info.FullName(), "akshay.dev/3kabcxyz"; got != want {
37 t.Errorf("FullName() = %q, want %q", got, want)
38 }
39}
40
41func TestFullNameWithoutAt_FlattensDid(t *testing.T) {
42 info := RepoInfo{OwnerDid: "did:plc:boltless", Name: "nautilus", Rkey: "nautilus"}
43 if got, want := info.FullNameWithoutAt(), "did-plc-boltless/nautilus"; got != want {
44 t.Errorf("FullNameWithoutAt() = %q, want %q", got, want)
45 }
46}