diff --git a/cmd/docker-trust/internal/test/cmd.go b/cmd/docker-trust/internal/test/cmd.go index 8b98d2df623b..f3d36b69e5b8 100644 --- a/cmd/docker-trust/internal/test/cmd.go +++ b/cmd/docker-trust/internal/test/cmd.go @@ -27,8 +27,11 @@ func TerminatePrompt(ctx context.Context, t *testing.T, cmd *cobra.Command, cli })) cli.SetOut(outStream) - r, _, err := os.Pipe() + r, w, err := os.Pipe() assert.NilError(t, err) + + // Keep the write end alive for the duration of the test. + defer w.Close() cli.SetIn(streams.NewIn(r)) notifyCtx, notifyCancel := context.WithCancel(ctx) @@ -58,8 +61,6 @@ func TerminatePrompt(ctx context.Context, t *testing.T, cmd *cobra.Command, cli }() } - assert.Check(t, cli.OutBuffer().Len() > 0) - // a small delay to ensure the plugin is prompting time.Sleep(100 * time.Microsecond) diff --git a/internal/test/cmd.go b/internal/test/cmd.go index 8b98d2df623b..f3d36b69e5b8 100644 --- a/internal/test/cmd.go +++ b/internal/test/cmd.go @@ -27,8 +27,11 @@ func TerminatePrompt(ctx context.Context, t *testing.T, cmd *cobra.Command, cli })) cli.SetOut(outStream) - r, _, err := os.Pipe() + r, w, err := os.Pipe() assert.NilError(t, err) + + // Keep the write end alive for the duration of the test. + defer w.Close() cli.SetIn(streams.NewIn(r)) notifyCtx, notifyCancel := context.WithCancel(ctx) @@ -58,8 +61,6 @@ func TerminatePrompt(ctx context.Context, t *testing.T, cmd *cobra.Command, cli }() } - assert.Check(t, cli.OutBuffer().Len() > 0) - // a small delay to ensure the plugin is prompting time.Sleep(100 * time.Microsecond)