github.com/qri-io/qri@v0.10.1-0.20220104210721-c771715036cb/dsref/ref_test.go (about) 1 package dsref 2 3 import ( 4 "testing" 5 ) 6 7 func TestRefAlias(t *testing.T) { 8 cases := []struct { 9 in Ref 10 expect string 11 }{ 12 {Ref{}, ""}, 13 {Ref{Username: "a", Name: "b"}, "a/b"}, 14 {Ref{Username: "a", Name: "b", Path: "foo"}, "a/b"}, 15 } 16 17 for _, c := range cases { 18 got := c.in.Alias() 19 if c.expect != got { 20 t.Errorf("result mismatch. input:%#v \nwant: %q\ngot: %q", c.in, c.expect, got) 21 } 22 } 23 } 24 25 func TestRefHuman(t *testing.T) { 26 cases := []struct { 27 in Ref 28 expect string 29 }{ 30 {Ref{}, ""}, 31 {Ref{Username: "a", Name: "b"}, "a/b"}, 32 {Ref{Username: "a", Name: "b", Path: "foo"}, "a/b"}, 33 } 34 35 for _, c := range cases { 36 got := c.in.Human() 37 if c.expect != got { 38 t.Errorf("result mismatch. input:%#v \nwant: %q\ngot: %q", c.in, c.expect, got) 39 } 40 } 41 } 42 43 func TestRefString(t *testing.T) { 44 cases := []struct { 45 in Ref 46 expect string 47 }{ 48 {Ref{}, ""}, 49 {Ref{Username: "a", Name: "b"}, "a/b"}, 50 {Ref{Username: "a", Name: "b"}, "a/b"}, 51 {Ref{Username: "a", Name: "b", Path: "/foo"}, "a/b@/foo"}, 52 {Ref{Username: "a", Name: "b", InitID: "initid", Path: "/foo"}, "a/b@initid/foo"}, 53 } 54 55 for _, c := range cases { 56 got := c.in.String() 57 if c.expect != got { 58 t.Errorf("result mismatch. input:%#v \nwant: %q\ngot: %q", c.in, c.expect, got) 59 } 60 } 61 } 62 63 func TestRefLegacyProfileIDString(t *testing.T) { 64 cases := []struct { 65 in Ref 66 expect string 67 }{ 68 {Ref{}, ""}, 69 {Ref{Username: "a", Name: "b"}, "a/b"}, 70 {Ref{Username: "a", Name: "b"}, "a/b"}, 71 {Ref{Username: "a", Name: "b", Path: "/foo"}, "a/b@/foo"}, 72 {Ref{Username: "a", Name: "b", ProfileID: "ProfileID", Path: "/foo"}, "a/b@ProfileID/foo"}, 73 } 74 75 for _, c := range cases { 76 got := c.in.LegacyProfileIDString() 77 if c.expect != got { 78 t.Errorf("result mismatch. input:%#v \nwant: %q\ngot: %q", c.in, c.expect, got) 79 } 80 } 81 } 82 83 func TestRefComplete(t *testing.T) { 84 compl := Ref{ 85 InitID: "an init id", 86 Username: "some username", 87 ProfileID: "hey look a profile ID", 88 Name: "a username. who knows if this is valid", 89 Path: "a path", 90 } 91 if !compl.Complete() { 92 t.Errorf("expected isComplete to return true when all fields are populated") 93 } 94 95 bad := []Ref{ 96 { 97 InitID: "an init id", 98 }, 99 { 100 InitID: "an init id", 101 Username: "some username", 102 }, 103 { 104 InitID: "an init id", 105 Username: "some username", 106 ProfileID: "hey look a profile ID", 107 }, 108 { 109 InitID: "an init id", 110 Username: "some username", 111 ProfileID: "hey look a profile ID", 112 Name: "a username. who knows if this is valid", 113 }, 114 } 115 for _, ref := range bad { 116 if ref.Complete() { 117 t.Errorf("expected %s to return false for complete", ref) 118 } 119 } 120 }