(t *testing.T)
| 415 | } |
| 416 | |
| 417 | func TestSetGHHostEnv(t *testing.T) { |
| 418 | tests := []struct { |
| 419 | name string |
| 420 | host string |
| 421 | expectSet bool |
| 422 | initialEnv []string |
| 423 | }{ |
| 424 | { |
| 425 | name: "github.com is a no-op", |
| 426 | host: "github.com", |
| 427 | expectSet: false, |
| 428 | }, |
| 429 | { |
| 430 | name: "empty host is a no-op", |
| 431 | host: "", |
| 432 | expectSet: false, |
| 433 | }, |
| 434 | { |
| 435 | name: "GHES host sets GH_HOST", |
| 436 | host: "myorg.ghe.com", |
| 437 | expectSet: true, |
| 438 | }, |
| 439 | { |
| 440 | name: "Proxima host sets GH_HOST", |
| 441 | host: "verizon.ghe.com", |
| 442 | expectSet: true, |
| 443 | }, |
| 444 | { |
| 445 | name: "appends to existing env", |
| 446 | host: "myorg.ghe.com", |
| 447 | expectSet: true, |
| 448 | initialEnv: []string{"FOO=bar"}, |
| 449 | }, |
| 450 | } |
| 451 | |
| 452 | for _, tt := range tests { |
| 453 | t.Run(tt.name, func(t *testing.T) { |
| 454 | cmd := exec.Command("echo", "test") |
| 455 | if tt.initialEnv != nil { |
| 456 | cmd.Env = tt.initialEnv |
| 457 | } |
| 458 | |
| 459 | SetGHHostEnv(cmd, tt.host) |
| 460 | |
| 461 | if !tt.expectSet { |
| 462 | if tt.initialEnv == nil { |
| 463 | assert.Nil(t, cmd.Env, "Env should remain nil for %s", tt.host) |
| 464 | } |
| 465 | return |
| 466 | } |
| 467 | |
| 468 | require.NotNil(t, cmd.Env, "Env should be set for host %s", tt.host) |
| 469 | found := slices.ContainsFunc(cmd.Env, func(e string) bool { |
| 470 | return e == "GH_HOST="+tt.host |
| 471 | }) |
| 472 | assert.True(t, found, "GH_HOST=%s should be in cmd.Env", tt.host) |
| 473 | }) |
| 474 | } |
nothing calls this directly
no test coverage detected