MCPcopy
hub / github.com/cli/cli / TestRequireNoAmbiguityBaseRepoFunc

Function TestRequireNoAmbiguityBaseRepoFunc

pkg/cmd/secret/shared/base_repo_test.go:17–87  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestRequireNoAmbiguityBaseRepoFunc(t *testing.T) {
18 t.Parallel()
19
20 t.Run("succeeds when there is only one remote", func(t *testing.T) {
21 t.Parallel()
22
23 // Given there is only one remote
24 baseRepoFn := shared.RequireNoAmbiguityBaseRepoFunc(baseRepoStubFn, oneRemoteStubFn)
25
26 // When fetching the base repo
27 baseRepo, err := baseRepoFn()
28
29 // It succeeds and returns the inner base repo
30 require.NoError(t, err)
31 require.True(t, ghrepo.IsSame(ghrepo.New("owner", "repo"), baseRepo))
32 })
33
34 t.Run("returns specific error when there are multiple remotes", func(t *testing.T) {
35 t.Parallel()
36
37 // Given there are multiple remotes
38 baseRepoFn := shared.RequireNoAmbiguityBaseRepoFunc(baseRepoStubFn, twoRemotesStubFn)
39
40 // When fetching the base repo
41 _, err := baseRepoFn()
42
43 // It succeeds and returns the inner base repo
44 var multipleRemotesError shared.AmbiguousBaseRepoError
45 require.ErrorAs(t, err, &multipleRemotesError)
46 require.Equal(t, ghContext.Remotes{
47 {
48 Remote: &git.Remote{
49 Name: "origin",
50 },
51 Repo: ghrepo.New("owner", "fork"),
52 },
53 {
54 Remote: &git.Remote{
55 Name: "upstream",
56 },
57 Repo: ghrepo.New("owner", "repo"),
58 },
59 }, multipleRemotesError.Remotes)
60 })
61
62 t.Run("when the remote fetching function fails, it returns the error", func(t *testing.T) {
63 t.Parallel()
64
65 // Given the remote fetching function fails
66 baseRepoFn := shared.RequireNoAmbiguityBaseRepoFunc(baseRepoStubFn, errRemoteStubFn)
67
68 // When fetching the base repo
69 _, err := baseRepoFn()
70
71 // It returns the error
72 require.Equal(t, errors.New("test remote error"), err)
73 })
74

Callers

nothing calls this directly

Calls 6

IsSameFunction · 0.92
NewFunction · 0.92
baseRepoFnFuncType · 0.85
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected