mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
test: batch 01 of refactoring CLI tests not to use PTY (#25871)
Part of https://github.com/coder/internal/issues/1400 Batch of refactored CLI tests to avoid creating PTYs.
This commit is contained in:
+9
-19
@@ -25,8 +25,8 @@ import (
|
||||
"github.com/coder/coder/v2/coderd/database/dbfake"
|
||||
"github.com/coder/coder/v2/coderd/database/dbtime"
|
||||
"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 TestPortForward_None(t *testing.T) {
|
||||
@@ -160,10 +160,7 @@ func TestPortForward(t *testing.T) {
|
||||
// the "local" listener.
|
||||
inv, root := clitest.New(t, "-v", "port-forward", workspace.Name, flag)
|
||||
clitest.SetupConfig(t, member, root)
|
||||
pty := ptytest.New(t)
|
||||
inv.Stdin = pty.Input()
|
||||
inv.Stdout = pty.Output()
|
||||
inv.Stderr = pty.Output()
|
||||
stdout := expecter.NewAttachedToInvocation(t, inv)
|
||||
|
||||
iNet := testutil.NewInProcNet()
|
||||
inv.Net = iNet
|
||||
@@ -175,7 +172,7 @@ func TestPortForward(t *testing.T) {
|
||||
t.Logf("command complete; err=%s", err.Error())
|
||||
errC <- err
|
||||
}()
|
||||
pty.ExpectMatchContext(ctx, "Ready!")
|
||||
stdout.ExpectMatchContext(ctx, "Ready!")
|
||||
|
||||
// Open two connections simultaneously and test them out of
|
||||
// sync.
|
||||
@@ -216,10 +213,7 @@ func TestPortForward(t *testing.T) {
|
||||
// the "local" listeners.
|
||||
inv, root := clitest.New(t, "-v", "port-forward", workspace.Name, flag1, flag2)
|
||||
clitest.SetupConfig(t, member, root)
|
||||
pty := ptytest.New(t)
|
||||
inv.Stdin = pty.Input()
|
||||
inv.Stdout = pty.Output()
|
||||
inv.Stderr = pty.Output()
|
||||
stdout := expecter.NewAttachedToInvocation(t, inv)
|
||||
|
||||
iNet := testutil.NewInProcNet()
|
||||
inv.Net = iNet
|
||||
@@ -229,7 +223,7 @@ func TestPortForward(t *testing.T) {
|
||||
go func() {
|
||||
errC <- inv.WithContext(ctx).Run()
|
||||
}()
|
||||
pty.ExpectMatchContext(ctx, "Ready!")
|
||||
stdout.ExpectMatchContext(ctx, "Ready!")
|
||||
|
||||
// Open a connection to both listener 1 and 2 simultaneously and
|
||||
// then test them out of order.
|
||||
@@ -277,8 +271,7 @@ func TestPortForward(t *testing.T) {
|
||||
// the "local" listeners.
|
||||
inv, root := clitest.New(t, append([]string{"-v", "port-forward", workspace.Name}, flags...)...)
|
||||
clitest.SetupConfig(t, member, root)
|
||||
pty := ptytest.New(t).Attach(inv)
|
||||
inv.Stderr = pty.Output()
|
||||
stdout := expecter.NewAttachedToInvocation(t, inv)
|
||||
|
||||
iNet := testutil.NewInProcNet()
|
||||
inv.Net = iNet
|
||||
@@ -288,7 +281,7 @@ func TestPortForward(t *testing.T) {
|
||||
go func() {
|
||||
errC <- inv.WithContext(ctx).Run()
|
||||
}()
|
||||
pty.ExpectMatchContext(ctx, "Ready!")
|
||||
stdout.ExpectMatchContext(ctx, "Ready!")
|
||||
|
||||
// Open connections to all items in the "dial" array.
|
||||
var (
|
||||
@@ -338,10 +331,7 @@ func TestPortForward(t *testing.T) {
|
||||
// the "local" listener.
|
||||
inv, root := clitest.New(t, "-v", "port-forward", workspace.Name, flag)
|
||||
clitest.SetupConfig(t, member, root)
|
||||
pty := ptytest.New(t)
|
||||
inv.Stdin = pty.Input()
|
||||
inv.Stdout = pty.Output()
|
||||
inv.Stderr = pty.Output()
|
||||
stdout := expecter.NewAttachedToInvocation(t, inv)
|
||||
|
||||
iNet := testutil.NewInProcNet()
|
||||
inv.Net = iNet
|
||||
@@ -359,7 +349,7 @@ func TestPortForward(t *testing.T) {
|
||||
t.Logf("command complete; err=%s", err.Error())
|
||||
errC <- err
|
||||
}()
|
||||
pty.ExpectMatchContext(ctx, "Ready!")
|
||||
stdout.ExpectMatchContext(ctx, "Ready!")
|
||||
|
||||
// Test IPv4 still works
|
||||
dialCtx, dialCtxCancel := context.WithTimeout(ctx, testutil.WaitShort)
|
||||
|
||||
Reference in New Issue
Block a user