Defined in pkg/cmdutil/repo_override.go but test it along with other BaseRepo functions
(t *testing.T)
| 257 | |
| 258 | // Defined in pkg/cmdutil/repo_override.go but test it along with other BaseRepo functions |
| 259 | func Test_OverrideBaseRepo(t *testing.T) { |
| 260 | tests := []struct { |
| 261 | name string |
| 262 | remotes git.RemoteSet |
| 263 | config gh.Config |
| 264 | envOverride string |
| 265 | argOverride string |
| 266 | wantsErr bool |
| 267 | wantsName string |
| 268 | wantsOwner string |
| 269 | wantsHost string |
| 270 | }{ |
| 271 | { |
| 272 | name: "override from argument", |
| 273 | argOverride: "override/test", |
| 274 | wantsHost: "github.com", |
| 275 | wantsOwner: "override", |
| 276 | wantsName: "test", |
| 277 | }, |
| 278 | { |
| 279 | name: "override from environment", |
| 280 | envOverride: "somehost.com/override/test", |
| 281 | wantsHost: "somehost.com", |
| 282 | wantsOwner: "override", |
| 283 | wantsName: "test", |
| 284 | }, |
| 285 | { |
| 286 | name: "no override", |
| 287 | remotes: git.RemoteSet{ |
| 288 | git.NewRemote("origin", "https://nonsense.com/owner/repo.git"), |
| 289 | }, |
| 290 | config: defaultConfig(), |
| 291 | wantsHost: "nonsense.com", |
| 292 | wantsOwner: "owner", |
| 293 | wantsName: "repo", |
| 294 | }, |
| 295 | } |
| 296 | |
| 297 | for _, tt := range tests { |
| 298 | t.Run(tt.name, func(t *testing.T) { |
| 299 | if tt.envOverride != "" { |
| 300 | t.Setenv("GH_REPO", tt.envOverride) |
| 301 | } |
| 302 | rr := &remoteResolver{ |
| 303 | readRemotes: func() (git.RemoteSet, error) { |
| 304 | return tt.remotes, nil |
| 305 | }, |
| 306 | getConfig: func() (gh.Config, error) { |
| 307 | return tt.config, nil |
| 308 | }, |
| 309 | } |
| 310 | remotes := rr.Resolver() |
| 311 | f := &cmdutil.Factory{ |
| 312 | BaseRepo: cmdutil.OverrideBaseRepoFunc(BaseRepoFunc(remotes), tt.argOverride), |
| 313 | } |
| 314 | repo, err := f.BaseRepo() |
| 315 | if tt.wantsErr { |
| 316 | assert.Error(t, err) |
nothing calls this directly
no test coverage detected