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