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

Function TestUserTerminatedError

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

Source from the content-addressed store, hash-verified

100}
101
102func TestUserTerminatedError(t *testing.T) {
103 ctx, cancel := context.WithTimeoutCause(context.Background(), time.Second*1, errors.New("test timeout"))
104 t.Cleanup(cancel)
105
106 notifyCtx, cancelNotify := notifyContext(ctx, platformsignals.TerminationSignals...)
107 t.Cleanup(cancelNotify)
108
109 assert.Check(t, syscall.Kill(syscall.Getpid(), syscall.SIGINT))
110
111 <-notifyCtx.Done()
112 assert.ErrorIs(t, context.Cause(notifyCtx), errCtxSignalTerminated{
113 signal: syscall.SIGINT,
114 })
115
116 assert.Equal(t, getExitCode(context.Cause(notifyCtx)), 130)
117
118 notifyCtx, cancelNotify = notifyContext(ctx, platformsignals.TerminationSignals...)
119 t.Cleanup(cancelNotify)
120
121 assert.Check(t, syscall.Kill(syscall.Getpid(), syscall.SIGTERM))
122
123 <-notifyCtx.Done()
124 assert.ErrorIs(t, context.Cause(notifyCtx), errCtxSignalTerminated{
125 signal: syscall.SIGTERM,
126 })
127
128 assert.Equal(t, getExitCode(context.Cause(notifyCtx)), 143)
129}
130
131func TestGetExitCode(t *testing.T) {
132 t.Run("nil error returns 0", func(t *testing.T) {

Callers

nothing calls this directly

Calls 3

notifyContextFunction · 0.85
CauseMethod · 0.80
getExitCodeFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…