(t *testing.T)
| 100 | } |
| 101 | |
| 102 | func 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 | |
| 131 | func TestGetExitCode(t *testing.T) { |
| 132 | t.Run("nil error returns 0", func(t *testing.T) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…