MCPcopy
hub / github.com/cli/cli / Test_Remotes_FindByRepo

Function Test_Remotes_FindByRepo

context/remote_test.go:31–94  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

29}
30
31func Test_Remotes_FindByRepo(t *testing.T) {
32 list := Remotes{
33 &Remote{Remote: &git.Remote{Name: "remote-0"}, Repo: ghrepo.New("owner", "repo")},
34 &Remote{Remote: &git.Remote{Name: "remote-1"}, Repo: ghrepo.New("another-owner", "another-repo")},
35 }
36
37 tests := []struct {
38 name string
39 owner string
40 repo string
41 wantsRemote *Remote
42 wantsError string
43 }{
44 {
45 name: "exact match (owner/repo)",
46 owner: "owner",
47 repo: "repo",
48 wantsRemote: list[0],
49 },
50 {
51 name: "exact match (another-owner/another-repo)",
52 owner: "another-owner",
53 repo: "another-repo",
54 wantsRemote: list[1],
55 },
56 {
57 name: "case-insensitive match",
58 owner: "OWNER",
59 repo: "REPO",
60 wantsRemote: list[0],
61 },
62 {
63 name: "non-match (owner)",
64 owner: "unknown-owner",
65 repo: "repo",
66 wantsError: "no matching remote found; looking for unknown-owner/repo",
67 },
68 {
69 name: "non-match (repo)",
70 owner: "owner",
71 repo: "unknown-repo",
72 wantsError: "no matching remote found; looking for owner/unknown-repo",
73 },
74 {
75 name: "non-match (owner, repo)",
76 owner: "unknown-owner",
77 repo: "unknown-repo",
78 wantsError: "no matching remote found; looking for unknown-owner/unknown-repo",
79 },
80 }
81
82 for _, tt := range tests {
83 t.Run(tt.name, func(t *testing.T) {
84 r, err := list.FindByRepo(tt.owner, tt.repo)
85 if tt.wantsError != "" {
86 assert.Error(t, err, tt.wantsError)
87 assert.Nil(t, r)
88 } else {

Callers

nothing calls this directly

Calls 5

FindByRepoMethod · 0.95
NewFunction · 0.92
EqualMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected