MCPcopy Index your code
hub / github.com/docker/cli / TestGetExitCode

Function TestGetExitCode

cmd/docker/docker_test.go:131–164  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

129}
130
131func TestGetExitCode(t *testing.T) {
132 t.Run("nil error returns 0", func(t *testing.T) {
133 assert.Equal(t, getExitCode(nil), 0)
134 })
135
136 t.Run("generic error returns 1", func(t *testing.T) {
137 assert.Equal(t, getExitCode(errors.New("some failure")), 1)
138 })
139
140 t.Run("StatusError with code", func(t *testing.T) {
141 err := dockercli.StatusError{StatusCode: 42}
142 assert.Equal(t, getExitCode(err), 42)
143 })
144
145 t.Run("StatusError with zero code falls back to 1", func(t *testing.T) {
146 err := dockercli.StatusError{StatusCode: 0, Status: "something went wrong"}
147 assert.Equal(t, getExitCode(err), 1)
148 })
149
150 t.Run("wrapped StatusError", func(t *testing.T) {
151 err := fmt.Errorf("wrapper: %w", dockercli.StatusError{StatusCode: 99})
152 assert.Equal(t, getExitCode(err), 99)
153 })
154
155 t.Run("SIGINT returns 130", func(t *testing.T) {
156 err := errCtxSignalTerminated{signal: syscall.SIGINT}
157 assert.Equal(t, getExitCode(err), 130)
158 })
159
160 t.Run("SIGTERM returns 143", func(t *testing.T) {
161 err := errCtxSignalTerminated{signal: syscall.SIGTERM}
162 assert.Equal(t, getExitCode(err), 143)
163 })
164}
165
166func TestCmdErrorMessage(t *testing.T) {
167 t.Run("nil error returns empty string", func(t *testing.T) {

Callers

nothing calls this directly

Calls 1

getExitCodeFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…