test: batch 02 of refactoring CLI tests not to use PTY (#25931)

Part of [coder/internal#1400](https://github.com/coder/internal/issues/1400)

Batch of refactored CLI tests to avoid creating PTYs.
This commit is contained in:
Spike Curtis
2026-06-02 07:53:24 -04:00
committed by GitHub
parent 32aee9ea4c
commit bfa6ce32a6
8 changed files with 207 additions and 181 deletions
+12 -8
View File
@@ -9,8 +9,8 @@ import (
"github.com/coder/coder/v2/cli/clitest"
"github.com/coder/coder/v2/coderd/coderdtest"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/pty/ptytest"
"github.com/coder/coder/v2/testutil"
"github.com/coder/coder/v2/testutil/expecter"
)
func TestExpTaskResume(t *testing.T) {
@@ -99,6 +99,7 @@ func TestExpTaskResume(t *testing.T) {
t.Run("PromptConfirm", func(t *testing.T) {
t.Parallel()
logger := testutil.Logger(t)
// Given: A paused task
setupCtx := testutil.Context(t, testutil.WaitLong)
setup := setupCLITaskTest(setupCtx, t, nil)
@@ -111,13 +112,14 @@ func TestExpTaskResume(t *testing.T) {
// And: We confirm we want to resume the task
ctx := testutil.Context(t, testutil.WaitMedium)
inv = inv.WithContext(ctx)
pty := ptytest.New(t).Attach(inv)
stdout := expecter.NewAttachedToInvocation(t, inv)
stdin := testutil.NewWriterAttachedToInvocation(t, logger.Named("stdin"), inv)
w := clitest.StartWithWaiter(t, inv)
pty.ExpectMatchContext(ctx, "Resume task")
pty.WriteLine("yes")
stdout.ExpectMatchContext(ctx, "Resume task")
stdin.WriteLine("yes")
// Then: We expect the task to be resumed
pty.ExpectMatchContext(ctx, "has been resumed")
stdout.ExpectMatchContext(ctx, "has been resumed")
require.NoError(t, w.Wait())
updated, err := setup.userClient.TaskByIdentifier(ctx, setup.task.Name)
@@ -128,6 +130,7 @@ func TestExpTaskResume(t *testing.T) {
t.Run("PromptDecline", func(t *testing.T) {
t.Parallel()
logger := testutil.Logger(t)
// Given: A paused task
setupCtx := testutil.Context(t, testutil.WaitLong)
setup := setupCLITaskTest(setupCtx, t, nil)
@@ -140,10 +143,11 @@ func TestExpTaskResume(t *testing.T) {
// But: Say no at the confirmation screen
ctx := testutil.Context(t, testutil.WaitMedium)
inv = inv.WithContext(ctx)
pty := ptytest.New(t).Attach(inv)
stdout := expecter.NewAttachedToInvocation(t, inv)
stdin := testutil.NewWriterAttachedToInvocation(t, logger.Named("stdin"), inv)
w := clitest.StartWithWaiter(t, inv)
pty.ExpectMatchContext(ctx, "Resume task")
pty.WriteLine("no")
stdout.ExpectMatchContext(ctx, "Resume task")
stdin.WriteLine("no")
require.Error(t, w.Wait())
// Then: We expect the task to still be paused