(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestRunPreservesGitErrorDiagnostics(t *testing.T) { |
| 13 | // Given a command that writes output before failing with a diagnostic on stderr |
| 14 | const stdout = "partial output\n" |
| 15 | const stderr = "fatal: test transport failed\n" |
| 16 | execCmd := createCommand(t, 128, stdout, stderr) |
| 17 | stdoutBuffer := &bytes.Buffer{} |
| 18 | execCmd.Stdout = stdoutBuffer |
| 19 | cmd := Command{execCmd} |
| 20 | |
| 21 | // When the command is run |
| 22 | err := cmd.Run() |
| 23 | |
| 24 | // Then stdout is written and the Git error preserves the diagnostic and exit code |
| 25 | require.Error(t, err) |
| 26 | var gitErr *GitError |
| 27 | require.ErrorAs(t, err, &gitErr) |
| 28 | assert.Equal(t, stdout, stdoutBuffer.String()) |
| 29 | assert.Equal(t, 128, gitErr.ExitCode) |
| 30 | assert.Equal(t, stderr, gitErr.Stderr) |
| 31 | require.EqualError(t, err, "failed to run git: fatal: test transport failed\n") |
| 32 | } |
| 33 | |
| 34 | func TestOutputReturnsCommandOutput(t *testing.T) { |
| 35 | // Given a command that writes to standard output |
nothing calls this directly
no test coverage detected