TestEnrichGHError tests that enrichGHError appends stderr from *exec.ExitError
(t *testing.T)
| 384 | |
| 385 | // TestEnrichGHError tests that enrichGHError appends stderr from *exec.ExitError |
| 386 | func TestEnrichGHError(t *testing.T) { |
| 387 | t.Run("nil error unchanged", func(t *testing.T) { |
| 388 | assert.NoError(t, enrichGHError(nil), "nil error should remain nil") |
| 389 | }) |
| 390 | |
| 391 | t.Run("non-ExitError unchanged", func(t *testing.T) { |
| 392 | err := errors.New("plain error") |
| 393 | assert.Equal(t, err, enrichGHError(err), "non-ExitError should be returned unchanged") |
| 394 | }) |
| 395 | |
| 396 | t.Run("ExitError with no stderr unchanged", func(t *testing.T) { |
| 397 | // Run a command that exits non-zero without producing stderr |
| 398 | cmd := exec.Command("sh", "-c", "exit 1") |
| 399 | _, cmdErr := cmd.Output() |
| 400 | require.Error(t, cmdErr, "command should fail") |
| 401 | enriched := enrichGHError(cmdErr) |
| 402 | // With no stderr, the error should be equivalent to the original |
| 403 | assert.Equal(t, cmdErr.Error(), enriched.Error(), "ExitError with empty stderr should match original error message") |
| 404 | }) |
| 405 | |
| 406 | t.Run("ExitError with stderr gets stderr appended", func(t *testing.T) { |
| 407 | // Run a command that exits non-zero and writes to stderr |
| 408 | cmd := exec.Command("sh", "-c", "echo 'not found' >&2; exit 1") |
| 409 | _, cmdErr := cmd.Output() |
| 410 | require.Error(t, cmdErr, "command should fail") |
| 411 | enriched := enrichGHError(cmdErr) |
| 412 | assert.Contains(t, enriched.Error(), "not found", "enriched error should contain stderr output") |
| 413 | assert.Contains(t, enriched.Error(), "exit status 1", "enriched error should still contain original error") |
| 414 | }) |
| 415 | } |
| 416 | |
| 417 | func TestSetGHHostEnv(t *testing.T) { |
| 418 | tests := []struct { |
nothing calls this directly
no test coverage detected