mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
test: rename ExpectMatchContext to ExpectMatch (#25998)
Cleans the last few instances of ExpectMatch that didn't use the new `(ctx, ...)` variant, then deletes the deprecated method and renames `ExpectMatchContext` to drop the `Context` suffix.
This commit is contained in:
@@ -49,8 +49,8 @@ func TestExternalAuth(t *testing.T) {
|
||||
err := inv.Run()
|
||||
assert.NoError(t, err)
|
||||
}()
|
||||
stdout.ExpectMatchContext(ctx, "You must authenticate with")
|
||||
stdout.ExpectMatchContext(ctx, "https://example.com/gitauth/github")
|
||||
stdout.ExpectMatchContext(ctx, "Successfully authenticated with GitHub")
|
||||
stdout.ExpectMatch(ctx, "You must authenticate with")
|
||||
stdout.ExpectMatch(ctx, "https://example.com/gitauth/github")
|
||||
stdout.ExpectMatch(ctx, "Successfully authenticated with GitHub")
|
||||
<-done
|
||||
}
|
||||
|
||||
+11
-10
@@ -33,7 +33,7 @@ func TestPrompt(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
msgChan <- resp
|
||||
}()
|
||||
ptty.ExpectMatch("Example")
|
||||
ptty.ExpectMatch(ctx, "Example")
|
||||
ptty.WriteLine("hello")
|
||||
resp := testutil.TryReceive(ctx, t, msgChan)
|
||||
require.Equal(t, "hello", resp)
|
||||
@@ -52,7 +52,7 @@ func TestPrompt(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
doneChan <- resp
|
||||
}()
|
||||
ptty.ExpectMatch("Example")
|
||||
ptty.ExpectMatch(ctx, "Example")
|
||||
ptty.WriteLine("yes")
|
||||
resp := testutil.TryReceive(ctx, t, doneChan)
|
||||
require.Equal(t, "yes", resp)
|
||||
@@ -113,7 +113,7 @@ func TestPrompt(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
doneChan <- resp
|
||||
}()
|
||||
ptty.ExpectMatch("Example")
|
||||
ptty.ExpectMatch(ctx, "Example")
|
||||
ptty.WriteLine("{}")
|
||||
resp := testutil.TryReceive(ctx, t, doneChan)
|
||||
require.Equal(t, "{}", resp)
|
||||
@@ -131,7 +131,7 @@ func TestPrompt(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
doneChan <- resp
|
||||
}()
|
||||
ptty.ExpectMatch("Example")
|
||||
ptty.ExpectMatch(ctx, "Example")
|
||||
ptty.WriteLine("{a")
|
||||
resp := testutil.TryReceive(ctx, t, doneChan)
|
||||
require.Equal(t, "{a", resp)
|
||||
@@ -149,7 +149,7 @@ func TestPrompt(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
doneChan <- resp
|
||||
}()
|
||||
ptty.ExpectMatch("Example")
|
||||
ptty.ExpectMatch(ctx, "Example")
|
||||
ptty.WriteLine(`{
|
||||
"test": "wow"
|
||||
}`)
|
||||
@@ -176,7 +176,7 @@ func TestPrompt(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
doneChan <- resp
|
||||
}()
|
||||
ptty.ExpectMatch("Example")
|
||||
ptty.ExpectMatch(ctx, "Example")
|
||||
ptty.WriteLine("foo\nbar\nbaz\n\n\nvalid\n")
|
||||
resp := testutil.TryReceive(ctx, t, doneChan)
|
||||
require.Equal(t, "valid", resp)
|
||||
@@ -195,7 +195,7 @@ func TestPrompt(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
doneChan <- resp
|
||||
}()
|
||||
ptty.ExpectMatch("Password: ")
|
||||
ptty.ExpectMatch(ctx, "Password: ")
|
||||
|
||||
ptty.WriteLine("test")
|
||||
|
||||
@@ -216,7 +216,7 @@ func TestPrompt(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
doneChan <- resp
|
||||
}()
|
||||
ptty.ExpectMatch("Password: ")
|
||||
ptty.ExpectMatch(ctx, "Password: ")
|
||||
|
||||
ptty.WriteLine("和製漢字")
|
||||
|
||||
@@ -257,6 +257,7 @@ func TestPasswordTerminalState(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ptty := ptytest.New(t)
|
||||
ctx := testutil.Context(t, testutil.WaitShort)
|
||||
|
||||
cmd := exec.Command(os.Args[0], "-test.run=TestPasswordTerminalState") //nolint:gosec
|
||||
cmd.Env = append(os.Environ(), "TEST_SUBPROCESS=1")
|
||||
@@ -269,12 +270,12 @@ func TestPasswordTerminalState(t *testing.T) {
|
||||
process := cmd.Process
|
||||
defer process.Kill()
|
||||
|
||||
ptty.ExpectMatch("Password: ")
|
||||
ptty.ExpectMatch(ctx, "Password: ")
|
||||
ptty.Write('t')
|
||||
ptty.Write('e')
|
||||
ptty.Write('s')
|
||||
ptty.Write('t')
|
||||
ptty.ExpectMatch("****")
|
||||
ptty.ExpectMatch(ctx, "****")
|
||||
|
||||
err = process.Signal(os.Interrupt)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -48,12 +48,12 @@ func TestProvisionerJob(t *testing.T) {
|
||||
test.JobMutex.Unlock()
|
||||
})
|
||||
testutil.Eventually(ctx, t, func(ctx context.Context) (done bool) {
|
||||
test.Stdout.ExpectMatchContext(ctx, cliui.ProvisioningStateQueued)
|
||||
test.Stdout.ExpectMatch(ctx, cliui.ProvisioningStateQueued)
|
||||
test.Next <- struct{}{}
|
||||
test.Stdout.ExpectMatchContext(ctx, cliui.ProvisioningStateQueued)
|
||||
test.Stdout.ExpectMatchContext(ctx, cliui.ProvisioningStateRunning)
|
||||
test.Stdout.ExpectMatch(ctx, cliui.ProvisioningStateQueued)
|
||||
test.Stdout.ExpectMatch(ctx, cliui.ProvisioningStateRunning)
|
||||
test.Next <- struct{}{}
|
||||
test.Stdout.ExpectMatchContext(ctx, cliui.ProvisioningStateRunning)
|
||||
test.Stdout.ExpectMatch(ctx, cliui.ProvisioningStateRunning)
|
||||
return true
|
||||
}, testutil.IntervalFast)
|
||||
})
|
||||
@@ -85,12 +85,12 @@ func TestProvisionerJob(t *testing.T) {
|
||||
test.JobMutex.Unlock()
|
||||
})
|
||||
testutil.Eventually(ctx, t, func(ctx context.Context) (done bool) {
|
||||
test.Stdout.ExpectMatchContext(ctx, cliui.ProvisioningStateQueued)
|
||||
test.Stdout.ExpectMatch(ctx, cliui.ProvisioningStateQueued)
|
||||
test.Next <- struct{}{}
|
||||
test.Stdout.ExpectMatchContext(ctx, cliui.ProvisioningStateQueued)
|
||||
test.Stdout.ExpectMatchContext(ctx, "Something")
|
||||
test.Stdout.ExpectMatch(ctx, cliui.ProvisioningStateQueued)
|
||||
test.Stdout.ExpectMatch(ctx, "Something")
|
||||
test.Next <- struct{}{}
|
||||
test.Stdout.ExpectMatchContext(ctx, "Something")
|
||||
test.Stdout.ExpectMatch(ctx, "Something")
|
||||
return true
|
||||
}, testutil.IntervalFast)
|
||||
})
|
||||
@@ -151,12 +151,12 @@ func TestProvisionerJob(t *testing.T) {
|
||||
test.JobMutex.Unlock()
|
||||
})
|
||||
testutil.Eventually(ctx, t, func(ctx context.Context) (done bool) {
|
||||
test.Stdout.ExpectRegexMatchContext(ctx, tc.expected)
|
||||
test.Stdout.ExpectRegexMatch(ctx, tc.expected)
|
||||
test.Next <- struct{}{}
|
||||
test.Stdout.ExpectMatchContext(ctx, cliui.ProvisioningStateQueued) // step completed
|
||||
test.Stdout.ExpectMatchContext(ctx, cliui.ProvisioningStateRunning)
|
||||
test.Stdout.ExpectMatch(ctx, cliui.ProvisioningStateQueued) // step completed
|
||||
test.Stdout.ExpectMatch(ctx, cliui.ProvisioningStateRunning)
|
||||
test.Next <- struct{}{}
|
||||
test.Stdout.ExpectMatchContext(ctx, cliui.ProvisioningStateRunning)
|
||||
test.Stdout.ExpectMatch(ctx, cliui.ProvisioningStateRunning)
|
||||
return true
|
||||
}, testutil.IntervalFast)
|
||||
})
|
||||
@@ -193,11 +193,11 @@ func TestProvisionerJob(t *testing.T) {
|
||||
test.JobMutex.Unlock()
|
||||
})
|
||||
testutil.Eventually(ctx, t, func(ctx context.Context) (done bool) {
|
||||
test.Stdout.ExpectMatchContext(ctx, cliui.ProvisioningStateQueued)
|
||||
test.Stdout.ExpectMatch(ctx, cliui.ProvisioningStateQueued)
|
||||
test.Next <- struct{}{}
|
||||
test.Stdout.ExpectMatchContext(ctx, "Gracefully canceling")
|
||||
test.Stdout.ExpectMatch(ctx, "Gracefully canceling")
|
||||
test.Next <- struct{}{}
|
||||
test.Stdout.ExpectMatchContext(ctx, cliui.ProvisioningStateQueued)
|
||||
test.Stdout.ExpectMatch(ctx, cliui.ProvisioningStateQueued)
|
||||
return true
|
||||
}, testutil.IntervalFast)
|
||||
})
|
||||
|
||||
+13
-10
@@ -10,12 +10,14 @@ import (
|
||||
"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"
|
||||
)
|
||||
|
||||
func TestWorkspaceResources(t *testing.T) {
|
||||
t.Parallel()
|
||||
t.Run("SingleAgentSSH", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := testutil.Context(t, testutil.WaitMedium)
|
||||
ptty := ptytest.New(t)
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
@@ -37,12 +39,13 @@ func TestWorkspaceResources(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
close(done)
|
||||
}()
|
||||
ptty.ExpectMatch("coder ssh example")
|
||||
ptty.ExpectMatch(ctx, "coder ssh example")
|
||||
<-done
|
||||
})
|
||||
|
||||
t.Run("MultipleStates", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := testutil.Context(t, testutil.WaitMedium)
|
||||
ptty := ptytest.New(t)
|
||||
disconnected := dbtime.Now().Add(-4 * time.Second)
|
||||
done := make(chan struct{})
|
||||
@@ -99,15 +102,15 @@ func TestWorkspaceResources(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
close(done)
|
||||
}()
|
||||
ptty.ExpectMatch("google_compute_disk.root")
|
||||
ptty.ExpectMatch("google_compute_instance.dev")
|
||||
ptty.ExpectMatch("healthy")
|
||||
ptty.ExpectMatch("coder ssh dev.dev")
|
||||
ptty.ExpectMatch("kubernetes_pod.dev")
|
||||
ptty.ExpectMatch("healthy")
|
||||
ptty.ExpectMatch("coder ssh dev.go")
|
||||
ptty.ExpectMatch("agent has lost connection")
|
||||
ptty.ExpectMatch("coder ssh dev.postgres")
|
||||
ptty.ExpectMatch(ctx, "google_compute_disk.root")
|
||||
ptty.ExpectMatch(ctx, "google_compute_instance.dev")
|
||||
ptty.ExpectMatch(ctx, "healthy")
|
||||
ptty.ExpectMatch(ctx, "coder ssh dev.dev")
|
||||
ptty.ExpectMatch(ctx, "kubernetes_pod.dev")
|
||||
ptty.ExpectMatch(ctx, "healthy")
|
||||
ptty.ExpectMatch(ctx, "coder ssh dev.go")
|
||||
ptty.ExpectMatch(ctx, "agent has lost connection")
|
||||
ptty.ExpectMatch(ctx, "coder ssh dev.postgres")
|
||||
<-done
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user