MCPcopy Create free account
hub / github.com/cli/cli / TestRunPreservesGitErrorDiagnostics

Function TestRunPreservesGitErrorDiagnostics

git/command_test.go:12–32  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func 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
34func TestOutputReturnsCommandOutput(t *testing.T) {
35 // Given a command that writes to standard output

Callers

nothing calls this directly

Calls 5

RunMethod · 0.95
createCommandFunction · 0.85
EqualMethod · 0.80
StringMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected