(t *testing.T)
| 122 | } |
| 123 | |
| 124 | func TestNewCmdListBaseRepoFuncs(t *testing.T) { |
| 125 | multipleRemotes := ghContext.Remotes{ |
| 126 | &ghContext.Remote{ |
| 127 | Remote: &git.Remote{ |
| 128 | Name: "origin", |
| 129 | }, |
| 130 | Repo: ghrepo.New("owner", "fork"), |
| 131 | }, |
| 132 | &ghContext.Remote{ |
| 133 | Remote: &git.Remote{ |
| 134 | Name: "upstream", |
| 135 | }, |
| 136 | Repo: ghrepo.New("owner", "repo"), |
| 137 | }, |
| 138 | } |
| 139 | |
| 140 | singleRemote := ghContext.Remotes{ |
| 141 | &ghContext.Remote{ |
| 142 | Remote: &git.Remote{ |
| 143 | Name: "origin", |
| 144 | }, |
| 145 | Repo: ghrepo.New("owner", "repo"), |
| 146 | }, |
| 147 | } |
| 148 | |
| 149 | tests := []struct { |
| 150 | name string |
| 151 | args string |
| 152 | env map[string]string |
| 153 | remotes ghContext.Remotes |
| 154 | prompterStubs func(*prompter.MockPrompter) |
| 155 | wantRepo ghrepo.Interface |
| 156 | wantErr error |
| 157 | }{ |
| 158 | { |
| 159 | name: "when there is a repo flag provided, the factory base repo func is used", |
| 160 | args: "--repo owner/repo", |
| 161 | remotes: multipleRemotes, |
| 162 | wantRepo: ghrepo.New("owner", "repo"), |
| 163 | }, |
| 164 | { |
| 165 | name: "when GH_REPO env var is provided, the factory base repo func is used", |
| 166 | env: map[string]string{ |
| 167 | "GH_REPO": "owner/repo", |
| 168 | }, |
| 169 | remotes: multipleRemotes, |
| 170 | wantRepo: ghrepo.New("owner", "repo"), |
| 171 | }, |
| 172 | { |
| 173 | name: "when there is no repo flag or GH_REPO env var provided, and no prompting, the base func requiring no ambiguity is used", |
| 174 | args: "", |
| 175 | remotes: multipleRemotes, |
| 176 | wantErr: shared.AmbiguousBaseRepoError{ |
| 177 | Remotes: multipleRemotes, |
| 178 | }, |
| 179 | }, |
| 180 | { |
| 181 | name: "when there is no repo flag or GH_REPO env provided, and there is a single remote, the factory base repo func is used", |
nothing calls this directly
no test coverage detected