TestRunGHFunctions tests that RunGH and RunGHCombined delegate correctly to their context variants.
(t *testing.T)
| 343 | |
| 344 | // TestRunGHFunctions tests that RunGH and RunGHCombined delegate correctly to their context variants. |
| 345 | func TestRunGHFunctions(t *testing.T) { |
| 346 | // Save original environment |
| 347 | originalGHToken := os.Getenv("GH_TOKEN") |
| 348 | originalGitHubToken := os.Getenv("GITHUB_TOKEN") |
| 349 | defer func() { |
| 350 | os.Setenv("GH_TOKEN", originalGHToken) |
| 351 | os.Setenv("GITHUB_TOKEN", originalGitHubToken) |
| 352 | }() |
| 353 | |
| 354 | // Set up test environment with no tokens to keep behavior deterministic for unit tests. |
| 355 | os.Unsetenv("GH_TOKEN") |
| 356 | os.Unsetenv("GITHUB_TOKEN") |
| 357 | |
| 358 | t.Run("RunGH matches RunGHContext", func(t *testing.T) { |
| 359 | gotOut, gotErr := RunGH("Test spinner...", "auth", "status") |
| 360 | wantOut, wantErr := RunGHContext(context.Background(), "Test spinner...", "auth", "status") |
| 361 | |
| 362 | assert.Equal(t, wantOut, gotOut, "RunGH should return the same output as RunGHContext") |
| 363 | if wantErr == nil { |
| 364 | assert.NoError(t, gotErr, "RunGH should match RunGHContext error behavior") |
| 365 | } else { |
| 366 | require.Error(t, gotErr, "RunGH should match RunGHContext error behavior") |
| 367 | assert.Equal(t, wantErr.Error(), gotErr.Error(), "RunGH should return the same error text as RunGHContext") |
| 368 | } |
| 369 | }) |
| 370 | |
| 371 | t.Run("RunGHCombined matches RunGHCombinedContext", func(t *testing.T) { |
| 372 | gotOut, gotErr := RunGHCombined("Test spinner...", "auth", "status") |
| 373 | wantOut, wantErr := RunGHCombinedContext(context.Background(), "Test spinner...", "auth", "status") |
| 374 | |
| 375 | assert.Equal(t, wantOut, gotOut, "RunGHCombined should return the same output as RunGHCombinedContext") |
| 376 | if wantErr == nil { |
| 377 | assert.NoError(t, gotErr, "RunGHCombined should match RunGHCombinedContext error behavior") |
| 378 | } else { |
| 379 | require.Error(t, gotErr, "RunGHCombined should match RunGHCombinedContext error behavior") |
| 380 | assert.Equal(t, wantErr.Error(), gotErr.Error(), "RunGHCombined should return the same error text as RunGHCombinedContext") |
| 381 | } |
| 382 | }) |
| 383 | } |
| 384 | |
| 385 | // TestEnrichGHError tests that enrichGHError appends stderr from *exec.ExitError |
| 386 | func TestEnrichGHError(t *testing.T) { |
nothing calls this directly
no test coverage detected