test: batch 04 of refactoring CLI tests not to use PTY (#25937)

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 10:50:27 -04:00
committed by GitHub
parent 170c33a475
commit cbaea49c02
6 changed files with 210 additions and 223 deletions
+8 -5
View File
@@ -15,25 +15,27 @@ import (
"github.com/coder/coder/v2/coderd/coderdtest"
"github.com/coder/coder/v2/coderd/rbac"
"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 TestUserList(t *testing.T) {
t.Parallel()
t.Run("Table", func(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitMedium)
client := coderdtest.New(t, nil)
owner := coderdtest.CreateFirstUser(t, client)
userAdmin, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.RoleUserAdmin())
inv, root := clitest.New(t, "users", "list")
clitest.SetupConfig(t, userAdmin, root)
pty := ptytest.New(t).Attach(inv)
stdout := expecter.NewAttachedToInvocation(t, inv)
errC := make(chan error)
go func() {
errC <- inv.Run()
}()
require.NoError(t, <-errC)
pty.ExpectMatch("coder.com")
stdout.ExpectMatchContext(ctx, "coder.com")
})
t.Run("JSON", func(t *testing.T) {
t.Parallel()
@@ -98,6 +100,7 @@ func TestUserShow(t *testing.T) {
t.Run("Table", func(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitMedium)
client := coderdtest.New(t, nil)
owner := coderdtest.CreateFirstUser(t, client)
userAdmin, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.RoleUserAdmin())
@@ -105,13 +108,13 @@ func TestUserShow(t *testing.T) {
inv, root := clitest.New(t, "users", "show", otherUser.Username)
clitest.SetupConfig(t, userAdmin, root)
doneChan := make(chan struct{})
pty := ptytest.New(t).Attach(inv)
stdout := expecter.NewAttachedToInvocation(t, inv)
go func() {
defer close(doneChan)
err := inv.Run()
assert.NoError(t, err)
}()
pty.ExpectMatch(otherUser.Email)
stdout.ExpectMatchContext(ctx, otherUser.Email)
<-doneChan
})