Skip to content

Commit

Permalink
test: notifyContext
Browse files Browse the repository at this point in the history
Signed-off-by: Alano Terblanche <[email protected]>
  • Loading branch information
Benehiko committed Jan 24, 2025
1 parent 49b52e8 commit 8839f12
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cmd/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import (
"context"
"io"
"os"
"syscall"
"testing"
"time"

"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/debug"
platformsignals "github.com/docker/cli/cmd/docker/internal/signals"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
Expand Down Expand Up @@ -75,3 +79,16 @@ func TestVersion(t *testing.T) {
assert.NilError(t, err)
assert.Check(t, is.Contains(b.String(), "Docker version"))
}

func TestUserTerminatedError(t *testing.T) {
ctx, cancel := context.WithTimeoutCause(context.Background(), time.Millisecond*100, errors.New("test timeout"))
t.Cleanup(cancel)

notifyCtx, cancelNotify := notifyContext(ctx, platformsignals.TerminationSignals...)
t.Cleanup(cancelNotify)

syscall.Kill(syscall.Getpid(), syscall.SIGINT)

<-notifyCtx.Done()
assert.ErrorIs(t, context.Cause(notifyCtx), errCtxUserTerminated)
}

0 comments on commit 8839f12

Please sign in to comment.