diff --git a/agent/agent_test.go b/agent/agent_test.go index 1fe8ad2725..df237e6443 100644 --- a/agent/agent_test.go +++ b/agent/agent_test.go @@ -673,7 +673,7 @@ func TestAgent_SessionTTYShell(t *testing.T) { require.NoError(t, err) _ = ptty.Peek(ctx, 1) // wait for the prompt ptty.WriteLine("echo test") - ptty.ExpectMatch("test") + ptty.ExpectMatch(ctx, "test") ptty.WriteLine("exit") err = session.Wait() require.NoError(t, err) diff --git a/agent/agentssh/agentssh_test.go b/agent/agentssh/agentssh_test.go index c2b439eeca..fceed50abe 100644 --- a/agent/agentssh/agentssh_test.go +++ b/agent/agentssh/agentssh_test.go @@ -203,7 +203,7 @@ func TestNewServer_CloseActiveConnections(t *testing.T) { assert.NoError(t, err) // Allow the session to settle (i.e. reach echo). - pty.ExpectMatchContext(ctx, "started") + pty.ExpectMatch(ctx, "started") // Sleep a bit to ensure the sleep has started. time.Sleep(testutil.IntervalMedium) diff --git a/cli/clitest/clitest_test.go b/cli/clitest/clitest_test.go index d683af8d34..673fa779dc 100644 --- a/cli/clitest/clitest_test.go +++ b/cli/clitest/clitest_test.go @@ -24,5 +24,5 @@ func TestCli(t *testing.T) { clitest.SetupConfig(t, client, config) stdout := expecter.NewAttachedToInvocation(t, i) clitest.Start(t, i) - stdout.ExpectMatchContext(ctx, "coder") + stdout.ExpectMatch(ctx, "coder") } diff --git a/cli/cliui/externalauth_test.go b/cli/cliui/externalauth_test.go index 3a7359a485..ed89b8e7c6 100644 --- a/cli/cliui/externalauth_test.go +++ b/cli/cliui/externalauth_test.go @@ -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 } diff --git a/cli/cliui/prompt_test.go b/cli/cliui/prompt_test.go index 8b5a3e98ea..90f6fade9b 100644 --- a/cli/cliui/prompt_test.go +++ b/cli/cliui/prompt_test.go @@ -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) diff --git a/cli/cliui/provisionerjob_test.go b/cli/cliui/provisionerjob_test.go index b2ad8eb293..d6a149a89e 100644 --- a/cli/cliui/provisionerjob_test.go +++ b/cli/cliui/provisionerjob_test.go @@ -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) }) diff --git a/cli/cliui/resources_test.go b/cli/cliui/resources_test.go index fb9bea8773..c7e69e5fa1 100644 --- a/cli/cliui/resources_test.go +++ b/cli/cliui/resources_test.go @@ -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 }) } diff --git a/cli/configssh_test.go b/cli/configssh_test.go index 61588e4fb9..82791f02b2 100644 --- a/cli/configssh_test.go +++ b/cli/configssh_test.go @@ -144,7 +144,7 @@ func TestConfigSSH(t *testing.T) { {match: "Continue?", write: "yes"}, } for _, m := range matches { - stdout.ExpectMatchContext(ctx, m.match) + stdout.ExpectMatch(ctx, m.match) stdin.WriteLine(m.write) } @@ -731,7 +731,7 @@ func TestConfigSSH_FileWriteAndOptionsFlow(t *testing.T) { }) for _, m := range tt.matches { - stdout.ExpectMatchContext(ctx, m.match) + stdout.ExpectMatch(ctx, m.match) stdin.WriteLine(m.write) } diff --git a/cli/create_test.go b/cli/create_test.go index 043148d178..73778be1d6 100644 --- a/cli/create_test.go +++ b/cli/create_test.go @@ -81,7 +81,7 @@ func TestCreateDynamic(t *testing.T) { doneChan <- inv.Run() }() - stdout.ExpectMatchContext(ctx, "has been created") + stdout.ExpectMatch(ctx, "has been created") err := testutil.RequireReceive(ctx, t, doneChan) require.NoError(t, err) @@ -110,7 +110,7 @@ func TestCreateDynamic(t *testing.T) { doneChan <- inv.Run() }() - stdout.ExpectMatchContext(ctx, "has been created") + stdout.ExpectMatch(ctx, "has been created") err = testutil.RequireReceive(ctx, t, doneChan) require.NoError(t, err) @@ -153,14 +153,14 @@ func TestCreateDynamic(t *testing.T) { }() // CLI should prompt for the region parameter since enable_region=true - stdout.ExpectMatchContext(ctx, "region") + stdout.ExpectMatch(ctx, "region") stdin.WriteLine("eu-west") // Confirm creation - stdout.ExpectMatchContext(ctx, "Confirm create?") + stdout.ExpectMatch(ctx, "Confirm create?") stdin.WriteLine("yes") - stdout.ExpectMatchContext(ctx, "has been created") + stdout.ExpectMatch(ctx, "has been created") err := <-doneChan require.NoError(t, err) @@ -314,7 +314,7 @@ func TestCreateDynamic(t *testing.T) { doneChan <- inv.Run() }() - stdout.ExpectMatchContext(ctx, "has been created") + stdout.ExpectMatch(ctx, "has been created") err = <-doneChan require.NoError(t, err, "slider=8 should succeed when max_slider=10") @@ -368,7 +368,7 @@ func TestCreate(t *testing.T) { {match: "Confirm create", write: "yes"}, } for _, m := range matches { - stdout.ExpectMatchContext(ctx, m.match) + stdout.ExpectMatch(ctx, m.match) if len(m.write) > 0 { stdin.WriteLine(m.write) } @@ -426,7 +426,7 @@ func TestCreate(t *testing.T) { {match: "Confirm create", write: "yes"}, } for _, m := range matches { - stdout.ExpectMatchContext(ctx, m.match) + stdout.ExpectMatch(ctx, m.match) if len(m.write) > 0 { stdin.WriteLine(m.write) } @@ -493,7 +493,7 @@ func TestCreate(t *testing.T) { {match: "Confirm create", write: "yes"}, } for _, m := range matches { - stdout.ExpectMatchContext(ctx, m.match) + stdout.ExpectMatch(ctx, m.match) if len(m.write) > 0 { stdin.WriteLine(m.write) } @@ -547,7 +547,7 @@ func TestCreate(t *testing.T) { {match: "Confirm create", write: "yes"}, } for _, m := range matches { - stdout.ExpectMatchContext(ctx, m.match) + stdout.ExpectMatch(ctx, m.match) if len(m.write) > 0 { stdin.WriteLine(m.write) } @@ -609,7 +609,7 @@ func TestCreate(t *testing.T) { for i := 0; i < len(matches); i += 2 { match := matches[i] value := matches[i+1] - stdout.ExpectMatchContext(ctx, match) + stdout.ExpectMatch(ctx, match) stdin.WriteLine(value) } <-doneChan @@ -645,7 +645,7 @@ func TestCreate(t *testing.T) { assert.NoError(t, err) }() - stdout.ExpectMatchContext(ctx, "building in the background") + stdout.ExpectMatch(ctx, "building in the background") _ = testutil.TryReceive(ctx, t, doneChan) // Verify workspace was actually created. @@ -682,7 +682,7 @@ func TestCreate(t *testing.T) { assert.NoError(t, err) }() - stdout.ExpectMatchContext(ctx, "building in the background") + stdout.ExpectMatch(ctx, "building in the background") _ = testutil.TryReceive(ctx, t, doneChan) // Verify workspace was created and parameters were applied. @@ -730,7 +730,7 @@ func TestCreate(t *testing.T) { assert.NoError(t, err) }() - stdout.ExpectMatchContext(ctx, "building in the background") + stdout.ExpectMatch(ctx, "building in the background") _ = testutil.TryReceive(ctx, t, doneChan) ws, err := member.WorkspaceByOwnerAndName(ctx, codersdk.Me, "my-workspace", codersdk.WorkspaceOptions{}) @@ -838,11 +838,11 @@ func TestCreateWithRichParameters(t *testing.T) { handlePty: func(ctx context.Context, stdout *expecter.Expecter, stdin *testutil.Writer) { // Enter the value for each parameter as prompted. for _, param := range params { - stdout.ExpectMatchContext(ctx, param.name) + stdout.ExpectMatch(ctx, param.name) stdin.WriteLine(param.value) } // Confirm the creation. - stdout.ExpectMatchContext(ctx, "Confirm create?") + stdout.ExpectMatch(ctx, "Confirm create?") stdin.WriteLine("yes") }, }, @@ -859,12 +859,12 @@ func TestCreateWithRichParameters(t *testing.T) { handlePty: func(ctx context.Context, stdout *expecter.Expecter, stdin *testutil.Writer) { // Simply accept the defaults. for _, param := range params { - stdout.ExpectMatchContext(ctx, param.name) - stdout.ExpectMatchContext(ctx, `Enter a value (default: "`+param.value+`")`) + stdout.ExpectMatch(ctx, param.name) + stdout.ExpectMatch(ctx, `Enter a value (default: "`+param.value+`")`) stdin.WriteLine("") } // Confirm the creation. - stdout.ExpectMatchContext(ctx, "Confirm create?") + stdout.ExpectMatch(ctx, "Confirm create?") stdin.WriteLine("yes") }, }, @@ -884,7 +884,7 @@ func TestCreateWithRichParameters(t *testing.T) { }, handlePty: func(ctx context.Context, stdout *expecter.Expecter, stdin *testutil.Writer) { // No prompts, we only need to confirm. - stdout.ExpectMatchContext(ctx, "Confirm create?") + stdout.ExpectMatch(ctx, "Confirm create?") stdin.WriteLine("yes") }, }, @@ -900,7 +900,7 @@ func TestCreateWithRichParameters(t *testing.T) { }, handlePty: func(ctx context.Context, stdout *expecter.Expecter, stdin *testutil.Writer) { // No prompts, we only need to confirm. - stdout.ExpectMatchContext(ctx, "Confirm create?") + stdout.ExpectMatch(ctx, "Confirm create?") stdin.WriteLine("yes") }, }, @@ -976,12 +976,12 @@ func TestCreateWithRichParameters(t *testing.T) { handlePty: func(ctx context.Context, stdout *expecter.Expecter, stdin *testutil.Writer) { // Simply accept the defaults. for _, param := range params { - stdout.ExpectMatchContext(ctx, param.name) - stdout.ExpectMatchContext(ctx, `Enter a value (default: "`+param.value+`")`) + stdout.ExpectMatch(ctx, param.name) + stdout.ExpectMatch(ctx, `Enter a value (default: "`+param.value+`")`) stdin.WriteLine("") } // Confirm the creation. - stdout.ExpectMatchContext(ctx, "Confirm create?") + stdout.ExpectMatch(ctx, "Confirm create?") stdin.WriteLine("yes") }, withDefaults: true, @@ -994,10 +994,10 @@ func TestCreateWithRichParameters(t *testing.T) { handlePty: func(ctx context.Context, stdout *expecter.Expecter, stdin *testutil.Writer) { // Default values should get printed. for _, param := range params { - stdout.ExpectMatchContext(ctx, fmt.Sprintf("%s: '%s'", param.name, param.value)) + stdout.ExpectMatch(ctx, fmt.Sprintf("%s: '%s'", param.name, param.value)) } // No prompts, we only need to confirm. - stdout.ExpectMatchContext(ctx, "Confirm create?") + stdout.ExpectMatch(ctx, "Confirm create?") stdin.WriteLine("yes") }, withDefaults: true, @@ -1015,10 +1015,10 @@ func TestCreateWithRichParameters(t *testing.T) { handlePty: func(ctx context.Context, stdout *expecter.Expecter, stdin *testutil.Writer) { // Default values should get printed. for _, param := range params { - stdout.ExpectMatchContext(ctx, fmt.Sprintf("%s: '%s'", param.name, param.value)) + stdout.ExpectMatch(ctx, fmt.Sprintf("%s: '%s'", param.name, param.value)) } // No prompts, we only need to confirm. - stdout.ExpectMatchContext(ctx, "Confirm create?") + stdout.ExpectMatch(ctx, "Confirm create?") stdin.WriteLine("yes") }, }, @@ -1044,11 +1044,11 @@ cli_param: from file`) }, handlePty: func(ctx context.Context, stdout *expecter.Expecter, stdin *testutil.Writer) { // Should get prompted for the input param since it has no default. - stdout.ExpectMatchContext(ctx, "input_param") + stdout.ExpectMatch(ctx, "input_param") stdin.WriteLine("from input") // Confirm the creation. - stdout.ExpectMatchContext(ctx, "Confirm create?") + stdout.ExpectMatch(ctx, "Confirm create?") stdin.WriteLine("yes") }, withDefaults: true, @@ -1284,9 +1284,9 @@ func TestCreateWithPreset(t *testing.T) { // Should: display the selected preset as well as its parameters presetName := fmt.Sprintf("Preset '%s' applied:", preset.Name) - stdout.ExpectMatchContext(ctx, presetName) - stdout.ExpectMatchContext(ctx, fmt.Sprintf("%s: '%s'", firstParameterName, secondOptionalParameterValue)) - stdout.ExpectMatchContext(ctx, fmt.Sprintf("%s: '%s'", thirdParameterName, thirdParameterValue)) + stdout.ExpectMatch(ctx, presetName) + stdout.ExpectMatch(ctx, fmt.Sprintf("%s: '%s'", firstParameterName, secondOptionalParameterValue)) + stdout.ExpectMatch(ctx, fmt.Sprintf("%s: '%s'", thirdParameterName, thirdParameterValue)) // Verify if the new workspace uses expected parameters. ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort) @@ -1360,9 +1360,9 @@ func TestCreateWithPreset(t *testing.T) { // Should: display the default preset as well as its parameters presetName := fmt.Sprintf("Preset '%s' (default) applied:", defaultPreset.Name) - stdout.ExpectMatchContext(ctx, presetName) - stdout.ExpectMatchContext(ctx, fmt.Sprintf("%s: '%s'", firstParameterName, secondOptionalParameterValue)) - stdout.ExpectMatchContext(ctx, fmt.Sprintf("%s: '%s'", thirdParameterName, thirdParameterValue)) + stdout.ExpectMatch(ctx, presetName) + stdout.ExpectMatch(ctx, fmt.Sprintf("%s: '%s'", firstParameterName, secondOptionalParameterValue)) + stdout.ExpectMatch(ctx, fmt.Sprintf("%s: '%s'", thirdParameterName, thirdParameterValue)) // Verify if the new workspace uses expected parameters. tvPresets, err := client.TemplateVersionPresets(ctx, version.ID) @@ -1434,11 +1434,11 @@ func TestCreateWithPreset(t *testing.T) { }() // Should: prompt the user for the preset - stdout.ExpectMatchContext(ctx, "Select a preset below:") + stdout.ExpectMatch(ctx, "Select a preset below:") // We don't actually have to respond to the selector, since we hardcode the cliui.Select to return the // first option in test scenarios (c.f. cliui/select.go) - stdout.ExpectMatchContext(ctx, "Preset 'preset-test' applied") - stdout.ExpectMatchContext(ctx, "Confirm create?") + stdout.ExpectMatch(ctx, "Preset 'preset-test' applied") + stdout.ExpectMatch(ctx, "Confirm create?") stdin.WriteLine("yes") <-doneChan @@ -1490,7 +1490,7 @@ func TestCreateWithPreset(t *testing.T) { stdout := expecter.NewAttachedToInvocation(t, inv) err := inv.Run() require.NoError(t, err) - stdout.ExpectMatchContext(ctx, "No preset applied.") + stdout.ExpectMatch(ctx, "No preset applied.") // Verify if the new workspace uses expected parameters. workspaces, err := client.Workspaces(ctx, codersdk.WorkspaceFilter{ @@ -1543,7 +1543,7 @@ func TestCreateWithPreset(t *testing.T) { stdout := expecter.NewAttachedToInvocation(t, inv) err := inv.Run() require.NoError(t, err) - stdout.ExpectMatchContext(ctx, "No preset applied.") + stdout.ExpectMatch(ctx, "No preset applied.") // Verify that the new workspace doesn't use the preset parameters. tvPresets, err := client.TemplateVersionPresets(ctx, version.ID) @@ -1639,8 +1639,8 @@ func TestCreateWithPreset(t *testing.T) { // Should: display the selected preset as well as its parameter presetName := fmt.Sprintf("Preset '%s' applied:", preset.Name) - stdout.ExpectMatchContext(ctx, presetName) - stdout.ExpectMatchContext(ctx, fmt.Sprintf("%s: '%s'", firstParameterName, secondOptionalParameterValue)) + stdout.ExpectMatch(ctx, presetName) + stdout.ExpectMatch(ctx, fmt.Sprintf("%s: '%s'", firstParameterName, secondOptionalParameterValue)) // Verify if the new workspace uses expected parameters. tvPresets, err := client.TemplateVersionPresets(ctx, version.ID) @@ -1709,8 +1709,8 @@ func TestCreateWithPreset(t *testing.T) { // Should: display the selected preset as well as its parameter presetName := fmt.Sprintf("Preset '%s' applied:", preset.Name) - stdout.ExpectMatchContext(ctx, presetName) - stdout.ExpectMatchContext(ctx, fmt.Sprintf("%s: '%s'", firstParameterName, secondOptionalParameterValue)) + stdout.ExpectMatch(ctx, presetName) + stdout.ExpectMatch(ctx, fmt.Sprintf("%s: '%s'", firstParameterName, secondOptionalParameterValue)) // Verify if the new workspace uses expected parameters. tvPresets, err := client.TemplateVersionPresets(ctx, version.ID) @@ -1771,13 +1771,13 @@ func TestCreateWithPreset(t *testing.T) { // Should: display the selected preset as well as its parameters presetName := fmt.Sprintf("Preset '%s' applied:", preset.Name) - stdout.ExpectMatchContext(ctx, presetName) - stdout.ExpectMatchContext(ctx, fmt.Sprintf("%s: '%s'", firstParameterName, secondOptionalParameterValue)) + stdout.ExpectMatch(ctx, presetName) + stdout.ExpectMatch(ctx, fmt.Sprintf("%s: '%s'", firstParameterName, secondOptionalParameterValue)) // Should: prompt for the missing parameter - stdout.ExpectMatchContext(ctx, thirdParameterDescription) + stdout.ExpectMatch(ctx, thirdParameterDescription) stdin.WriteLine(thirdParameterValue) - stdout.ExpectMatchContext(ctx, "Confirm create?") + stdout.ExpectMatch(ctx, "Confirm create?") stdin.WriteLine("yes") <-doneChan @@ -1877,7 +1877,7 @@ func TestCreateValidateRichParameters(t *testing.T) { for i := 0; i < len(matches); i += 2 { match := matches[i] value := matches[i+1] - stdout.ExpectMatchContext(ctx, match) + stdout.ExpectMatch(ctx, match) if value != "" { stdin.WriteLine(value) } @@ -1918,7 +1918,7 @@ func TestCreateValidateRichParameters(t *testing.T) { for i := 0; i < len(matches); i += 2 { match := matches[i] value := matches[i+1] - stdout.ExpectMatchContext(ctx, match) + stdout.ExpectMatch(ctx, match) if value != "" { stdin.WriteLine(value) } @@ -1959,7 +1959,7 @@ func TestCreateValidateRichParameters(t *testing.T) { for i := 0; i < len(matches); i += 2 { match := matches[i] value := matches[i+1] - stdout.ExpectMatchContext(ctx, match) + stdout.ExpectMatch(ctx, match) if value != "" { stdin.WriteLine(value) } @@ -2000,7 +2000,7 @@ func TestCreateValidateRichParameters(t *testing.T) { for i := 0; i < len(matches); i += 2 { match := matches[i] value := matches[i+1] - stdout.ExpectMatchContext(ctx, match) + stdout.ExpectMatch(ctx, match) if value != "" { stdin.WriteLine(value) } @@ -2027,9 +2027,9 @@ func TestCreateValidateRichParameters(t *testing.T) { stdin := testutil.NewWriterAttachedToInvocation(t, logger.Named("stdin"), inv) clitest.Start(t, inv) - stdout.ExpectMatchContext(ctx, listOfStringsParameterName) - stdout.ExpectMatchContext(ctx, "aaa, bbb, ccc") - stdout.ExpectMatchContext(ctx, "Confirm create?") + stdout.ExpectMatch(ctx, listOfStringsParameterName) + stdout.ExpectMatch(ctx, "aaa, bbb, ccc") + stdout.ExpectMatch(ctx, "Confirm create?") stdin.WriteLine("yes") }) @@ -2082,7 +2082,7 @@ func TestCreateValidateRichParameters(t *testing.T) { for i := 0; i < len(matches); i += 2 { match := matches[i] value := matches[i+1] - stdout.ExpectMatchContext(ctx, match) + stdout.ExpectMatch(ctx, match) if value != "" { stdin.WriteLine(value) } @@ -2132,10 +2132,10 @@ func TestCreateWithGitAuth(t *testing.T) { stdin := testutil.NewWriterAttachedToInvocation(t, logger.Named("stdin"), inv) clitest.Start(t, inv) - stdout.ExpectMatchContext(ctx, "You must authenticate with GitHub to create a workspace") + stdout.ExpectMatch(ctx, "You must authenticate with GitHub to create a workspace") resp := coderdtest.RequestExternalAuthCallback(t, "github", member) _ = resp.Body.Close() require.Equal(t, http.StatusTemporaryRedirect, resp.StatusCode) - stdout.ExpectMatchContext(ctx, "Confirm create?") + stdout.ExpectMatch(ctx, "Confirm create?") stdin.WriteLine("yes") } diff --git a/cli/delete_test.go b/cli/delete_test.go index c8dff9646a..ec9a626cf9 100644 --- a/cli/delete_test.go +++ b/cli/delete_test.go @@ -52,7 +52,7 @@ func TestDelete(t *testing.T) { assert.ErrorIs(t, err, io.EOF) } }() - stdout.ExpectMatchContext(ctx, "has been deleted") + stdout.ExpectMatch(ctx, "has been deleted") <-doneChan }) @@ -81,7 +81,7 @@ func TestDelete(t *testing.T) { assert.ErrorIs(t, err, io.EOF) } }() - stdout.ExpectMatchContext(ctx, "has been deleted") + stdout.ExpectMatch(ctx, "has been deleted") testutil.TryReceive(ctx, t, doneChan) _, err := client.Workspace(ctx, workspace.ID) @@ -126,7 +126,7 @@ func TestDelete(t *testing.T) { assert.ErrorIs(t, err, io.EOF) } }() - stdout.ExpectMatchContext(ctx, "has been deleted") + stdout.ExpectMatch(ctx, "has been deleted") <-doneChan }) @@ -160,7 +160,7 @@ func TestDelete(t *testing.T) { } }() - stdout.ExpectMatchContext(ctx, "has been deleted") + stdout.ExpectMatch(ctx, "has been deleted") <-doneChan workspace, err = client.Workspace(context.Background(), workspace.ID) @@ -216,7 +216,7 @@ func TestDelete(t *testing.T) { defer close(doneChan) _ = inv.WithContext(ctx).Run() }() - stdout.ExpectMatchContext(ctx, "there are no provisioners that accept the required tags") + stdout.ExpectMatch(ctx, "there are no provisioners that accept the required tags") cancel() <-doneChan }) @@ -324,7 +324,7 @@ func TestDelete(t *testing.T) { require.Error(t, runErr) require.Contains(t, runErr.Error(), expectedErr) } else { - stdout.ExpectMatchContext(ctx, "has been deleted") + stdout.ExpectMatch(ctx, "has been deleted") <-doneChan // When running with the race detector on, we sometimes get an EOF. diff --git a/cli/exp_mcp_test.go b/cli/exp_mcp_test.go index 5293f87d4b..39bced032e 100644 --- a/cli/exp_mcp_test.go +++ b/cli/exp_mcp_test.go @@ -685,7 +685,7 @@ func TestExpMcpReporter(t *testing.T) { assert.Error(t, err) }() - stderr.ExpectMatchContext(ctx, "Failed to connect to agent socket") + stderr.ExpectMatch(ctx, "Failed to connect to agent socket") cancel() <-cmdDone }) diff --git a/cli/exp_rpty_test.go b/cli/exp_rpty_test.go index 72548188ea..df37ca704e 100644 --- a/cli/exp_rpty_test.go +++ b/cli/exp_rpty_test.go @@ -63,7 +63,7 @@ func TestExpRpty(t *testing.T) { assert.NoError(t, err) }) - stdout.ExpectMatchContext(ctx, randStr) + stdout.ExpectMatch(ctx, randStr) <-cmdDone }) @@ -134,9 +134,9 @@ func TestExpRpty(t *testing.T) { assert.NoError(t, err) }) - stdout.ExpectMatchContext(ctx, " #") + stdout.ExpectMatch(ctx, " #") stdin.WriteLine("hostname") - stdout.ExpectMatchContext(ctx, ct.Container.Config.Hostname) + stdout.ExpectMatch(ctx, ct.Container.Config.Hostname) stdin.WriteLine("exit") <-cmdDone }) diff --git a/cli/externalauth_test.go b/cli/externalauth_test.go index 65409b55d8..614505f309 100644 --- a/cli/externalauth_test.go +++ b/cli/externalauth_test.go @@ -29,7 +29,7 @@ func TestExternalAuth(t *testing.T) { inv, _ := clitest.New(t, "--agent-url", url, "--agent-token", "foo", "external-auth", "access-token", "github") stdout := expecter.NewAttachedToInvocation(t, inv) waiter := clitest.StartWithWaiter(t, inv) - stdout.ExpectMatchContext(ctx, "https://github.com") + stdout.ExpectMatch(ctx, "https://github.com") waiter.RequireIs(cliui.ErrCanceled) }) t.Run("SuccessWithToken", func(t *testing.T) { @@ -45,7 +45,7 @@ func TestExternalAuth(t *testing.T) { inv, _ := clitest.New(t, "--agent-url", url, "--agent-token", "foo", "external-auth", "access-token", "github") stdout := expecter.NewAttachedToInvocation(t, inv) clitest.Start(t, inv) - stdout.ExpectMatchContext(ctx, "bananas") + stdout.ExpectMatch(ctx, "bananas") }) t.Run("NoArgs", func(t *testing.T) { t.Parallel() @@ -76,6 +76,6 @@ func TestExternalAuth(t *testing.T) { inv, _ := clitest.New(t, "--agent-url", url, "--agent-token", "foo", "external-auth", "access-token", "github", "--extra", "hey") stdout := expecter.NewAttachedToInvocation(t, inv) clitest.Start(t, inv) - stdout.ExpectMatchContext(ctx, "there") + stdout.ExpectMatch(ctx, "there") }) } diff --git a/cli/gitaskpass_test.go b/cli/gitaskpass_test.go index f903194a6b..2592952422 100644 --- a/cli/gitaskpass_test.go +++ b/cli/gitaskpass_test.go @@ -37,14 +37,14 @@ func TestGitAskpass(t *testing.T) { inv.Environ.Set("CODER_AGENT_TOKEN", "fake-token") stdout := expecter.NewAttachedToInvocation(t, inv) clitest.Start(t, inv) - stdout.ExpectMatchContext(ctx, "something") + stdout.ExpectMatch(ctx, "something") inv, _ = clitest.New(t, "--agent-url", url, "Password for 'https://potato@github.com':") inv.Environ.Set("GIT_PREFIX", "/") inv.Environ.Set("CODER_AGENT_TOKEN", "fake-token") stdout = expecter.NewAttachedToInvocation(t, inv) clitest.Start(t, inv) - stdout.ExpectMatchContext(ctx, "bananas") + stdout.ExpectMatch(ctx, "bananas") }) t.Run("NoHost", func(t *testing.T) { @@ -63,7 +63,7 @@ func TestGitAskpass(t *testing.T) { stdout := expecter.NewAttachedToInvocation(t, inv) err := inv.Run() require.ErrorIs(t, err, cliui.ErrCanceled) - stdout.ExpectMatchContext(ctx, "Nope!") + stdout.ExpectMatch(ctx, "Nope!") }) t.Run("Poll", func(t *testing.T) { @@ -99,11 +99,11 @@ func TestGitAskpass(t *testing.T) { assert.NoError(t, err) }() testutil.RequireReceive(ctx, t, poll) - stderr.ExpectMatchContext(ctx, "Open the following URL to authenticate") + stderr.ExpectMatch(ctx, "Open the following URL to authenticate") resp.Store(&agentsdk.ExternalAuthResponse{ Username: "username", Password: "password", }) - stdout.ExpectMatchContext(ctx, "username") + stdout.ExpectMatch(ctx, "username") }) } diff --git a/cli/keyring_test.go b/cli/keyring_test.go index b05d46ed81..fb93291cee 100644 --- a/cli/keyring_test.go +++ b/cli/keyring_test.go @@ -92,9 +92,9 @@ func TestUseKeyring(t *testing.T) { }() // Provide the token when prompted - stdout.ExpectMatchContext(ctx, "Paste your token here:") + stdout.ExpectMatch(ctx, "Paste your token here:") stdin.WriteLine(client.SessionToken()) - stdout.ExpectMatchContext(ctx, "Welcome to Coder") + stdout.ExpectMatch(ctx, "Welcome to Coder") <-doneChan // Verify that session file was NOT created (using keyring instead) @@ -139,9 +139,9 @@ func TestUseKeyring(t *testing.T) { assert.NoError(t, err) }() - stdout.ExpectMatchContext(ctx, "Paste your token here:") + stdout.ExpectMatch(ctx, "Paste your token here:") stdin.WriteLine(client.SessionToken()) - stdout.ExpectMatchContext(ctx, "Welcome to Coder") + stdout.ExpectMatch(ctx, "Welcome to Coder") <-doneChan // Verify credential exists in OS keyring @@ -203,9 +203,9 @@ func TestUseKeyring(t *testing.T) { assert.NoError(t, err) }() - stdout.ExpectMatchContext(ctx, "Paste your token here:") + stdout.ExpectMatch(ctx, "Paste your token here:") stdin.WriteLine(client.SessionToken()) - stdout.ExpectMatchContext(ctx, "Welcome to Coder") + stdout.ExpectMatch(ctx, "Welcome to Coder") <-doneChan // Verify that session file WAS created (not using keyring) @@ -248,9 +248,9 @@ func TestUseKeyring(t *testing.T) { assert.NoError(t, err) }() - stdout.ExpectMatchContext(ctx, "Paste your token here:") + stdout.ExpectMatch(ctx, "Paste your token here:") stdin.WriteLine(client.SessionToken()) - stdout.ExpectMatchContext(ctx, "Welcome to Coder") + stdout.ExpectMatch(ctx, "Welcome to Coder") <-doneChan // Verify that session file WAS created (not using keyring) @@ -292,9 +292,9 @@ func TestUseKeyring(t *testing.T) { assert.NoError(t, err) }() - stdout.ExpectMatchContext(ctx, "Paste your token here:") + stdout.ExpectMatch(ctx, "Paste your token here:") stdin.WriteLine(client.SessionToken()) - stdout.ExpectMatchContext(ctx, "Welcome to Coder") + stdout.ExpectMatch(ctx, "Welcome to Coder") <-doneChan // Verify that session file WAS created (not using keyring) @@ -344,9 +344,9 @@ func TestUseKeyringUnsupportedOS(t *testing.T) { assert.NoError(t, err) }() - stdout.ExpectMatchContext(ctx, "Paste your token here:") + stdout.ExpectMatch(ctx, "Paste your token here:") stdin.WriteLine(client.SessionToken()) - stdout.ExpectMatchContext(ctx, "Welcome to Coder") + stdout.ExpectMatch(ctx, "Welcome to Coder") <-doneChan // Verify that session file WAS created (automatic fallback to file storage) @@ -385,9 +385,9 @@ func TestUseKeyringUnsupportedOS(t *testing.T) { assert.NoError(t, err) }() - stdout.ExpectMatchContext(ctx, "Paste your token here:") + stdout.ExpectMatch(ctx, "Paste your token here:") stdin.WriteLine(client.SessionToken()) - stdout.ExpectMatchContext(ctx, "Welcome to Coder") + stdout.ExpectMatch(ctx, "Welcome to Coder") <-doneChan // Verify session file exists diff --git a/cli/list_test.go b/cli/list_test.go index 201188ad1e..eecd54c8f3 100644 --- a/cli/list_test.go +++ b/cli/list_test.go @@ -44,8 +44,8 @@ func TestList(t *testing.T) { assert.NoError(t, errC) close(done) }() - stdout.ExpectMatchContext(ctx, r.Workspace.Name) - stdout.ExpectMatchContext(ctx, "Started") + stdout.ExpectMatch(ctx, r.Workspace.Name) + stdout.ExpectMatch(ctx, "Started") cancelFunc() <-done }) diff --git a/cli/login_test.go b/cli/login_test.go index 5768a68127..06abc6d7e1 100644 --- a/cli/login_test.go +++ b/cli/login_test.go @@ -107,10 +107,10 @@ func TestLogin(t *testing.T) { for i := 0; i < len(matches); i += 2 { match := matches[i] value := matches[i+1] - stdout.ExpectMatchContext(ctx, match) + stdout.ExpectMatch(ctx, match) stdin.WriteLine(value) } - stdout.ExpectMatchContext(ctx, "Welcome to Coder") + stdout.ExpectMatch(ctx, "Welcome to Coder") <-doneChan resp, err := client.LoginWithPassword(ctx, codersdk.LoginWithPasswordRequest{ Email: coderdtest.FirstUserParams.Email, @@ -155,10 +155,10 @@ func TestLogin(t *testing.T) { for i := 0; i < len(matches); i += 2 { match := matches[i] value := matches[i+1] - stdout.ExpectMatchContext(ctx, match) + stdout.ExpectMatch(ctx, match) stdin.WriteLine(value) } - stdout.ExpectMatchContext(ctx, "Welcome to Coder") + stdout.ExpectMatch(ctx, "Welcome to Coder") <-doneChan resp, err := client.LoginWithPassword(ctx, codersdk.LoginWithPasswordRequest{ Email: coderdtest.FirstUserParams.Email, @@ -209,10 +209,10 @@ func TestLogin(t *testing.T) { for i := 0; i < len(matches); i += 2 { match := matches[i] value := matches[i+1] - stdout.ExpectMatchContext(ctx, match) + stdout.ExpectMatch(ctx, match) stdin.WriteLine(value) } - stdout.ExpectMatchContext(ctx, "Welcome to Coder") + stdout.ExpectMatch(ctx, "Welcome to Coder") <-doneChan resp, err := client.LoginWithPassword(ctx, codersdk.LoginWithPasswordRequest{ Email: coderdtest.FirstUserParams.Email, @@ -241,7 +241,7 @@ func TestLogin(t *testing.T) { clitest.Start(t, inv) - stdout.ExpectMatchContext(ctx, fmt.Sprintf("Attempting to authenticate with flag URL: '%s'", client.URL.String())) + stdout.ExpectMatch(ctx, fmt.Sprintf("Attempting to authenticate with flag URL: '%s'", client.URL.String())) matches := []string{ "first user?", "yes", "username", coderdtest.FirstUserParams.Username, @@ -260,10 +260,10 @@ func TestLogin(t *testing.T) { for i := 0; i < len(matches); i += 2 { match := matches[i] value := matches[i+1] - stdout.ExpectMatchContext(ctx, match) + stdout.ExpectMatch(ctx, match) stdin.WriteLine(value) } - stdout.ExpectMatchContext(ctx, "Welcome to Coder") + stdout.ExpectMatch(ctx, "Welcome to Coder") resp, err := client.LoginWithPassword(ctx, codersdk.LoginWithPasswordRequest{ Email: coderdtest.FirstUserParams.Email, Password: coderdtest.FirstUserParams.Password, @@ -293,18 +293,18 @@ func TestLogin(t *testing.T) { stdin := testutil.NewWriterAttachedToInvocation(t, logger.Named("stdin"), inv) ctx := testutil.Context(t, testutil.WaitMedium) w := clitest.StartWithWaiter(t, inv) - stdout.ExpectMatchContext(ctx, "firstName") + stdout.ExpectMatch(ctx, "firstName") stdin.WriteLine(coderdtest.TrialUserParams.FirstName) - stdout.ExpectMatchContext(ctx, "lastName") + stdout.ExpectMatch(ctx, "lastName") stdin.WriteLine(coderdtest.TrialUserParams.LastName) - stdout.ExpectMatchContext(ctx, "phoneNumber") + stdout.ExpectMatch(ctx, "phoneNumber") stdin.WriteLine(coderdtest.TrialUserParams.PhoneNumber) - stdout.ExpectMatchContext(ctx, "jobTitle") + stdout.ExpectMatch(ctx, "jobTitle") stdin.WriteLine(coderdtest.TrialUserParams.JobTitle) - stdout.ExpectMatchContext(ctx, "companyName") + stdout.ExpectMatch(ctx, "companyName") stdin.WriteLine(coderdtest.TrialUserParams.CompanyName) // `developers` and `country` `cliui.Select` automatically selects the first option during tests. - stdout.ExpectMatchContext(ctx, "Welcome to Coder") + stdout.ExpectMatch(ctx, "Welcome to Coder") w.RequireSuccess() resp, err := client.LoginWithPassword(ctx, codersdk.LoginWithPasswordRequest{ Email: coderdtest.FirstUserParams.Email, @@ -334,18 +334,18 @@ func TestLogin(t *testing.T) { stdin := testutil.NewWriterAttachedToInvocation(t, logger.Named("stdin"), inv) ctx := testutil.Context(t, testutil.WaitMedium) w := clitest.StartWithWaiter(t, inv) - stdout.ExpectMatchContext(ctx, "firstName") + stdout.ExpectMatch(ctx, "firstName") stdin.WriteLine(coderdtest.TrialUserParams.FirstName) - stdout.ExpectMatchContext(ctx, "lastName") + stdout.ExpectMatch(ctx, "lastName") stdin.WriteLine(coderdtest.TrialUserParams.LastName) - stdout.ExpectMatchContext(ctx, "phoneNumber") + stdout.ExpectMatch(ctx, "phoneNumber") stdin.WriteLine(coderdtest.TrialUserParams.PhoneNumber) - stdout.ExpectMatchContext(ctx, "jobTitle") + stdout.ExpectMatch(ctx, "jobTitle") stdin.WriteLine(coderdtest.TrialUserParams.JobTitle) - stdout.ExpectMatchContext(ctx, "companyName") + stdout.ExpectMatch(ctx, "companyName") stdin.WriteLine(coderdtest.TrialUserParams.CompanyName) // `developers` and `country` `cliui.Select` automatically selects the first option during tests. - stdout.ExpectMatchContext(ctx, "Welcome to Coder") + stdout.ExpectMatch(ctx, "Welcome to Coder") w.RequireSuccess() resp, err := client.LoginWithPassword(ctx, codersdk.LoginWithPasswordRequest{ Email: coderdtest.FirstUserParams.Email, @@ -390,29 +390,29 @@ func TestLogin(t *testing.T) { for i := 0; i < len(matches); i += 2 { match := matches[i] value := matches[i+1] - stdout.ExpectMatchContext(ctx, match) + stdout.ExpectMatch(ctx, match) stdin.WriteLine(value) } // Validate that we reprompt for matching passwords. - stdout.ExpectMatchContext(ctx, "Passwords do not match") - stdout.ExpectMatchContext(ctx, "Enter a "+pretty.Sprint(cliui.DefaultStyles.Field, "password")) + stdout.ExpectMatch(ctx, "Passwords do not match") + stdout.ExpectMatch(ctx, "Enter a "+pretty.Sprint(cliui.DefaultStyles.Field, "password")) stdin.WriteLine(coderdtest.FirstUserParams.Password) - stdout.ExpectMatchContext(ctx, "Confirm") + stdout.ExpectMatch(ctx, "Confirm") stdin.WriteLine(coderdtest.FirstUserParams.Password) - stdout.ExpectMatchContext(ctx, "trial") + stdout.ExpectMatch(ctx, "trial") stdin.WriteLine("yes") - stdout.ExpectMatchContext(ctx, "firstName") + stdout.ExpectMatch(ctx, "firstName") stdin.WriteLine(coderdtest.TrialUserParams.FirstName) - stdout.ExpectMatchContext(ctx, "lastName") + stdout.ExpectMatch(ctx, "lastName") stdin.WriteLine(coderdtest.TrialUserParams.LastName) - stdout.ExpectMatchContext(ctx, "phoneNumber") + stdout.ExpectMatch(ctx, "phoneNumber") stdin.WriteLine(coderdtest.TrialUserParams.PhoneNumber) - stdout.ExpectMatchContext(ctx, "jobTitle") + stdout.ExpectMatch(ctx, "jobTitle") stdin.WriteLine(coderdtest.TrialUserParams.JobTitle) - stdout.ExpectMatchContext(ctx, "companyName") + stdout.ExpectMatch(ctx, "companyName") stdin.WriteLine(coderdtest.TrialUserParams.CompanyName) - stdout.ExpectMatchContext(ctx, "Welcome to Coder") + stdout.ExpectMatch(ctx, "Welcome to Coder") <-doneChan }) @@ -433,10 +433,10 @@ func TestLogin(t *testing.T) { assert.NoError(t, err) }() - stdout.ExpectMatchContext(ctx, fmt.Sprintf("Attempting to authenticate with argument URL: '%s'", client.URL.String())) - stdout.ExpectMatchContext(ctx, "Paste your token here:") + stdout.ExpectMatch(ctx, fmt.Sprintf("Attempting to authenticate with argument URL: '%s'", client.URL.String())) + stdout.ExpectMatch(ctx, "Paste your token here:") stdin.WriteLine(client.SessionToken()) - stdout.ExpectMatchContext(ctx, "Welcome to Coder") + stdout.ExpectMatch(ctx, "Welcome to Coder") <-doneChan }) @@ -460,8 +460,8 @@ func TestLogin(t *testing.T) { assert.NoError(t, err) }() - stdout.ExpectMatchContext(ctx, fmt.Sprintf("Attempting to authenticate with config URL: '%s'", url)) - stdout.ExpectMatchContext(ctx, "Paste your token here:") + stdout.ExpectMatch(ctx, fmt.Sprintf("Attempting to authenticate with config URL: '%s'", url)) + stdout.ExpectMatch(ctx, "Paste your token here:") stdin.WriteLine(client.SessionToken()) <-doneChan }) @@ -486,8 +486,8 @@ func TestLogin(t *testing.T) { assert.NoError(t, err) }() - stdout.ExpectMatchContext(ctx, fmt.Sprintf("Attempting to authenticate with environment URL: '%s'", url)) - stdout.ExpectMatchContext(ctx, "Paste your token here:") + stdout.ExpectMatch(ctx, fmt.Sprintf("Attempting to authenticate with environment URL: '%s'", url)) + stdout.ExpectMatch(ctx, "Paste your token here:") stdin.WriteLine(client.SessionToken()) <-doneChan }) @@ -511,9 +511,9 @@ func TestLogin(t *testing.T) { assert.Error(t, err) }() - stdout.ExpectMatchContext(ctx, "Paste your token here:") + stdout.ExpectMatch(ctx, "Paste your token here:") stdin.WriteLine("an-invalid-token") - stdout.ExpectMatchContext(ctx, "That's not a valid token!") + stdout.ExpectMatch(ctx, "That's not a valid token!") cancelFunc() <-doneChan }) @@ -603,7 +603,7 @@ func TestLoginToken(t *testing.T) { err := inv.WithContext(ctx).Run() require.NoError(t, err) - stdout.ExpectMatchContext(ctx, client.SessionToken()) + stdout.ExpectMatch(ctx, client.SessionToken()) }) t.Run("NoTokenStored", func(t *testing.T) { diff --git a/cli/logout_test.go b/cli/logout_test.go index 01d0fcd2cb..977d121b39 100644 --- a/cli/logout_test.go +++ b/cli/logout_test.go @@ -43,9 +43,9 @@ func TestLogout(t *testing.T) { assert.NoFileExists(t, string(config.Session())) }() - stdout.ExpectMatchContext(ctx, "Are you sure you want to log out?") + stdout.ExpectMatch(ctx, "Are you sure you want to log out?") stdin.WriteLine("yes") - stdout.ExpectMatchContext(ctx, "You are no longer logged in. You can log in using 'coder login '.") + stdout.ExpectMatch(ctx, "You are no longer logged in. You can log in using 'coder login '.") <-logoutChan }) t.Run("SkipPrompt", func(t *testing.T) { @@ -70,7 +70,7 @@ func TestLogout(t *testing.T) { assert.NoFileExists(t, string(config.Session())) }() - stdout.ExpectMatchContext(ctx, "You are no longer logged in. You can log in using 'coder login '.") + stdout.ExpectMatch(ctx, "You are no longer logged in. You can log in using 'coder login '.") <-logoutChan }) t.Run("NoURLFile", func(t *testing.T) { @@ -148,7 +148,7 @@ func TestLogout(t *testing.T) { stdin := testutil.NewWriterAttachedToInvocation(t, logger.Named("stdin"), logout) go func() { - stdout.ExpectMatchContext(ctx, "Are you sure you want to log out?") + stdout.ExpectMatch(ctx, "Are you sure you want to log out?") stdin.WriteLine("yes") }() err = logout.Run() @@ -183,9 +183,9 @@ func login(ctx context.Context, t *testing.T) config.Root { assert.NoError(t, err) }() - stdout.ExpectMatchContext(ctx, "Paste your token here:") + stdout.ExpectMatch(ctx, "Paste your token here:") stdin.WriteLine(client.SessionToken()) - stdout.ExpectMatchContext(ctx, "Welcome to Coder") + stdout.ExpectMatch(ctx, "Welcome to Coder") testutil.TryReceive(ctx, t, doneChan) return cfg diff --git a/cli/organization_test.go b/cli/organization_test.go index ab5751b513..2b240ed20b 100644 --- a/cli/organization_test.go +++ b/cli/organization_test.go @@ -57,7 +57,7 @@ func TestCurrentOrganization(t *testing.T) { errC <- inv.Run() }() require.NoError(t, <-errC) - stdout.ExpectMatchContext(ctx, orgID.String()) + stdout.ExpectMatch(ctx, orgID.String()) }) } @@ -179,7 +179,7 @@ func TestOrganizationDelete(t *testing.T) { execDone <- inv.Run() }() - stdout.ExpectMatchContext(ctx, fmt.Sprintf("Delete organization %s?", pretty.Sprint(cliui.DefaultStyles.Code, "my-org"))) + stdout.ExpectMatch(ctx, fmt.Sprintf("Delete organization %s?", pretty.Sprint(cliui.DefaultStyles.Code, "my-org"))) stdin.WriteLine("yes") require.NoError(t, <-execDone) diff --git a/cli/ping_test.go b/cli/ping_test.go index df532bda57..5ede893509 100644 --- a/cli/ping_test.go +++ b/cli/ping_test.go @@ -35,7 +35,7 @@ func TestPing(t *testing.T) { assert.NoError(t, err) }) - stdout.ExpectMatchContext(ctx, "pong from "+workspace.Name) + stdout.ExpectMatch(ctx, "pong from "+workspace.Name) cancel() <-cmdDone }) @@ -59,7 +59,7 @@ func TestPing(t *testing.T) { assert.NoError(t, err) }) - stdout.ExpectMatchContext(ctx, "pong from "+workspace.Name) + stdout.ExpectMatch(ctx, "pong from "+workspace.Name) cancel() <-cmdDone }) @@ -110,7 +110,7 @@ func TestPing(t *testing.T) { rfc3339 += `(?:Z|[+-]\d{2}:\d{2})` } - stdout.ExpectRegexMatchContext(ctx, `\[`+rfc3339+`\] pong from `+workspace.Name) + stdout.ExpectRegexMatch(ctx, `\[`+rfc3339+`\] pong from `+workspace.Name) cancel() <-cmdDone }) diff --git a/cli/portforward_test.go b/cli/portforward_test.go index d0cfeeb8fb..ac4146ef28 100644 --- a/cli/portforward_test.go +++ b/cli/portforward_test.go @@ -172,7 +172,7 @@ func TestPortForward(t *testing.T) { t.Logf("command complete; err=%s", err.Error()) errC <- err }() - stdout.ExpectMatchContext(ctx, "Ready!") + stdout.ExpectMatch(ctx, "Ready!") // Open two connections simultaneously and test them out of // sync. @@ -223,7 +223,7 @@ func TestPortForward(t *testing.T) { go func() { errC <- inv.WithContext(ctx).Run() }() - stdout.ExpectMatchContext(ctx, "Ready!") + stdout.ExpectMatch(ctx, "Ready!") // Open a connection to both listener 1 and 2 simultaneously and // then test them out of order. @@ -281,7 +281,7 @@ func TestPortForward(t *testing.T) { go func() { errC <- inv.WithContext(ctx).Run() }() - stdout.ExpectMatchContext(ctx, "Ready!") + stdout.ExpectMatch(ctx, "Ready!") // Open connections to all items in the "dial" array. var ( @@ -349,7 +349,7 @@ func TestPortForward(t *testing.T) { t.Logf("command complete; err=%s", err.Error()) errC <- err }() - stdout.ExpectMatchContext(ctx, "Ready!") + stdout.ExpectMatch(ctx, "Ready!") // Test IPv4 still works dialCtx, dialCtxCancel := context.WithTimeout(ctx, testutil.WaitShort) diff --git a/cli/rename_test.go b/cli/rename_test.go index e9aa8d480d..a14305e47a 100644 --- a/cli/rename_test.go +++ b/cli/rename_test.go @@ -35,9 +35,9 @@ func TestRename(t *testing.T) { stdin := testutil.NewWriterAttachedToInvocation(t, logger.Named("stdin"), inv) clitest.Start(t, inv) - stdout.ExpectMatchContext(ctx, "confirm rename:") + stdout.ExpectMatch(ctx, "confirm rename:") stdin.WriteLine(workspace.Name) - stdout.ExpectMatchContext(ctx, "renamed to") + stdout.ExpectMatch(ctx, "renamed to") ws, err := client.Workspace(ctx, workspace.ID) assert.NoError(t, err) diff --git a/cli/resetpassword_test.go b/cli/resetpassword_test.go index e71b26248f..73a4fed692 100644 --- a/cli/resetpassword_test.go +++ b/cli/resetpassword_test.go @@ -86,7 +86,7 @@ func TestResetPassword(t *testing.T) { {"Confirm", newPassword}, } for _, match := range matches { - stdout.ExpectMatchContext(ctx, match.output) + stdout.ExpectMatch(ctx, match.output) stdin.WriteLine(match.input) } <-cmdDone diff --git a/cli/restart_test.go b/cli/restart_test.go index 3506d313a2..a97fcf3df5 100644 --- a/cli/restart_test.go +++ b/cli/restart_test.go @@ -54,9 +54,9 @@ func TestRestart(t *testing.T) { go func() { done <- inv.WithContext(ctx).Run() }() - stdout.ExpectMatchContext(ctx, "Stopping workspace") - stdout.ExpectMatchContext(ctx, "Starting workspace") - stdout.ExpectMatchContext(ctx, "workspace has been restarted") + stdout.ExpectMatch(ctx, "Stopping workspace") + stdout.ExpectMatch(ctx, "Starting workspace") + stdout.ExpectMatch(ctx, "workspace has been restarted") err := <-done require.NoError(t, err, "execute failed") @@ -103,7 +103,7 @@ func TestRestart(t *testing.T) { for i := 0; i < len(matches); i += 2 { match := matches[i] value := matches[i+1] - stdout.ExpectMatchContext(ctx, match) + stdout.ExpectMatch(ctx, match) if value != "" { stdin.WriteLine(value) @@ -161,7 +161,7 @@ func TestRestart(t *testing.T) { for i := 0; i < len(matches); i += 2 { match := matches[i] value := matches[i+1] - stdout.ExpectMatchContext(ctx, match) + stdout.ExpectMatch(ctx, match) if value != "" { stdin.WriteLine(value) @@ -221,7 +221,7 @@ func TestRestart(t *testing.T) { for i := 0; i < len(matches); i += 2 { match := matches[i] value := matches[i+1] - stdout.ExpectMatchContext(ctx, match) + stdout.ExpectMatch(ctx, match) if value != "" { stdin.WriteLine(value) @@ -279,7 +279,7 @@ func TestRestart(t *testing.T) { for i := 0; i < len(matches); i += 2 { match := matches[i] value := matches[i+1] - stdout.ExpectMatchContext(ctx, match) + stdout.ExpectMatch(ctx, match) if value != "" { stdin.WriteLine(value) @@ -356,7 +356,7 @@ func TestRestartWithParameters(t *testing.T) { }() ctx := testutil.Context(t, testutil.WaitShort) - stdout.ExpectMatchContext(ctx, "workspace has been restarted") + stdout.ExpectMatch(ctx, "workspace has been restarted") <-doneChan // Verify if immutable parameter is set @@ -405,9 +405,9 @@ func TestRestartWithParameters(t *testing.T) { // We should be prompted for the parameters again. newValue := "xyz" - stdout.ExpectMatchContext(ctx, mutableParameterName) + stdout.ExpectMatch(ctx, mutableParameterName) stdin.WriteLine(newValue) - stdout.ExpectMatchContext(ctx, "workspace has been restarted") + stdout.ExpectMatch(ctx, "workspace has been restarted") <-doneChan // Verify that the updated values are persisted. diff --git a/cli/root_test.go b/cli/root_test.go index 5850a77da0..cd2c10a781 100644 --- a/cli/root_test.go +++ b/cli/root_test.go @@ -283,7 +283,7 @@ func TestDERPHeaders(t *testing.T) { assert.NoError(t, err) }) - stdout.ExpectMatchContext(ctx, "pong from "+workspace.Name) + stdout.ExpectMatch(ctx, "pong from "+workspace.Name) <-cmdDone require.Greater(t, derpCalled.Load(), int64(0), "expected /derp to be called at least once") diff --git a/cli/schedule_test.go b/cli/schedule_test.go index c9f61345a1..1c48c23278 100644 --- a/cli/schedule_test.go +++ b/cli/schedule_test.go @@ -103,15 +103,15 @@ func TestScheduleShow(t *testing.T) { // Then: they should see their own workspaces. // 1st workspace: a-owner-ws1 has both autostart and autostop enabled. - stdout.ExpectMatchContext(ctx, ws[0].OwnerName+"/"+ws[0].Name) - stdout.ExpectMatchContext(ctx, sched.Humanize()) - stdout.ExpectMatchContext(ctx, sched.Next(now).In(loc).Format(time.RFC3339)) - stdout.ExpectMatchContext(ctx, "8h") - stdout.ExpectMatchContext(ctx, ws[0].LatestBuild.Deadline.Time.In(loc).Format(time.RFC3339)) + stdout.ExpectMatch(ctx, ws[0].OwnerName+"/"+ws[0].Name) + stdout.ExpectMatch(ctx, sched.Humanize()) + stdout.ExpectMatch(ctx, sched.Next(now).In(loc).Format(time.RFC3339)) + stdout.ExpectMatch(ctx, "8h") + stdout.ExpectMatch(ctx, ws[0].LatestBuild.Deadline.Time.In(loc).Format(time.RFC3339)) // 2nd workspace: b-owner-ws2 has only autostart enabled. - stdout.ExpectMatchContext(ctx, ws[1].OwnerName+"/"+ws[1].Name) - stdout.ExpectMatchContext(ctx, sched.Humanize()) - stdout.ExpectMatchContext(ctx, sched.Next(now).In(loc).Format(time.RFC3339)) + stdout.ExpectMatch(ctx, ws[1].OwnerName+"/"+ws[1].Name) + stdout.ExpectMatch(ctx, sched.Humanize()) + stdout.ExpectMatch(ctx, sched.Next(now).In(loc).Format(time.RFC3339)) }) t.Run("OwnerAll", func(t *testing.T) { @@ -125,21 +125,21 @@ func TestScheduleShow(t *testing.T) { // Then: they should see all workspaces // 1st workspace: a-owner-ws1 has both autostart and autostop enabled. - stdout.ExpectMatchContext(ctx, ws[0].OwnerName+"/"+ws[0].Name) - stdout.ExpectMatchContext(ctx, sched.Humanize()) - stdout.ExpectMatchContext(ctx, sched.Next(now).In(loc).Format(time.RFC3339)) - stdout.ExpectMatchContext(ctx, "8h") - stdout.ExpectMatchContext(ctx, ws[0].LatestBuild.Deadline.Time.In(loc).Format(time.RFC3339)) + stdout.ExpectMatch(ctx, ws[0].OwnerName+"/"+ws[0].Name) + stdout.ExpectMatch(ctx, sched.Humanize()) + stdout.ExpectMatch(ctx, sched.Next(now).In(loc).Format(time.RFC3339)) + stdout.ExpectMatch(ctx, "8h") + stdout.ExpectMatch(ctx, ws[0].LatestBuild.Deadline.Time.In(loc).Format(time.RFC3339)) // 2nd workspace: b-owner-ws2 has only autostart enabled. - stdout.ExpectMatchContext(ctx, ws[1].OwnerName+"/"+ws[1].Name) - stdout.ExpectMatchContext(ctx, sched.Humanize()) - stdout.ExpectMatchContext(ctx, sched.Next(now).In(loc).Format(time.RFC3339)) + stdout.ExpectMatch(ctx, ws[1].OwnerName+"/"+ws[1].Name) + stdout.ExpectMatch(ctx, sched.Humanize()) + stdout.ExpectMatch(ctx, sched.Next(now).In(loc).Format(time.RFC3339)) // 3rd workspace: c-member-ws3 has only autostop enabled. - stdout.ExpectMatchContext(ctx, ws[2].OwnerName+"/"+ws[2].Name) - stdout.ExpectMatchContext(ctx, "8h") - stdout.ExpectMatchContext(ctx, ws[2].LatestBuild.Deadline.Time.In(loc).Format(time.RFC3339)) + stdout.ExpectMatch(ctx, ws[2].OwnerName+"/"+ws[2].Name) + stdout.ExpectMatch(ctx, "8h") + stdout.ExpectMatch(ctx, ws[2].LatestBuild.Deadline.Time.In(loc).Format(time.RFC3339)) // 4th workspace: d-member-ws4 has neither autostart nor autostop enabled. - stdout.ExpectMatchContext(ctx, ws[3].OwnerName+"/"+ws[3].Name) + stdout.ExpectMatch(ctx, ws[3].OwnerName+"/"+ws[3].Name) }) t.Run("OwnerSearchByName", func(t *testing.T) { @@ -153,9 +153,9 @@ func TestScheduleShow(t *testing.T) { // Then: they should see workspaces matching that query // 2nd workspace: b-owner-ws2 has only autostart enabled. - stdout.ExpectMatchContext(ctx, ws[1].OwnerName+"/"+ws[1].Name) - stdout.ExpectMatchContext(ctx, sched.Humanize()) - stdout.ExpectMatchContext(ctx, sched.Next(now).In(loc).Format(time.RFC3339)) + stdout.ExpectMatch(ctx, ws[1].OwnerName+"/"+ws[1].Name) + stdout.ExpectMatch(ctx, sched.Humanize()) + stdout.ExpectMatch(ctx, sched.Next(now).In(loc).Format(time.RFC3339)) }) t.Run("OwnerOneArg", func(t *testing.T) { @@ -169,9 +169,9 @@ func TestScheduleShow(t *testing.T) { // Then: they should see that workspace // 3rd workspace: c-member-ws3 has only autostop enabled. - stdout.ExpectMatchContext(ctx, ws[2].OwnerName+"/"+ws[2].Name) - stdout.ExpectMatchContext(ctx, "8h") - stdout.ExpectMatchContext(ctx, ws[2].LatestBuild.Deadline.Time.In(loc).Format(time.RFC3339)) + stdout.ExpectMatch(ctx, ws[2].OwnerName+"/"+ws[2].Name) + stdout.ExpectMatch(ctx, "8h") + stdout.ExpectMatch(ctx, ws[2].LatestBuild.Deadline.Time.In(loc).Format(time.RFC3339)) }) t.Run("MemberNoArgs", func(t *testing.T) { @@ -184,11 +184,11 @@ func TestScheduleShow(t *testing.T) { // Then: they should see their own workspaces // 1st workspace: c-member-ws3 has only autostop enabled. - stdout.ExpectMatchContext(ctx, ws[2].OwnerName+"/"+ws[2].Name) - stdout.ExpectMatchContext(ctx, "8h") - stdout.ExpectMatchContext(ctx, ws[2].LatestBuild.Deadline.Time.In(loc).Format(time.RFC3339)) + stdout.ExpectMatch(ctx, ws[2].OwnerName+"/"+ws[2].Name) + stdout.ExpectMatch(ctx, "8h") + stdout.ExpectMatch(ctx, ws[2].LatestBuild.Deadline.Time.In(loc).Format(time.RFC3339)) // 2nd workspace: d-member-ws4 has neither autostart nor autostop enabled. - stdout.ExpectMatchContext(ctx, ws[3].OwnerName+"/"+ws[3].Name) + stdout.ExpectMatch(ctx, ws[3].OwnerName+"/"+ws[3].Name) }) t.Run("MemberAll", func(t *testing.T) { @@ -205,11 +205,11 @@ func TestScheduleShow(t *testing.T) { // Then: they should only see their own // 1st workspace: c-member-ws3 has only autostop enabled. - stdout.ExpectMatchContext(ctx, ws[2].OwnerName+"/"+ws[2].Name) - stdout.ExpectMatchContext(ctx, "8h") - stdout.ExpectMatchContext(ctx, ws[2].LatestBuild.Deadline.Time.In(loc).Format(time.RFC3339)) + stdout.ExpectMatch(ctx, ws[2].OwnerName+"/"+ws[2].Name) + stdout.ExpectMatch(ctx, "8h") + stdout.ExpectMatch(ctx, ws[2].LatestBuild.Deadline.Time.In(loc).Format(time.RFC3339)) // 2nd workspace: d-member-ws4 has neither autostart nor autostop enabled. - stdout.ExpectMatchContext(ctx, ws[3].OwnerName+"/"+ws[3].Name) + stdout.ExpectMatch(ctx, ws[3].OwnerName+"/"+ws[3].Name) }) t.Run("JSON", func(t *testing.T) { @@ -286,9 +286,9 @@ func TestScheduleModify(t *testing.T) { require.NoError(t, inv.Run()) // Then: the updated schedule should be shown - stdout.ExpectMatchContext(ctx, ws[3].OwnerName+"/"+ws[3].Name) - stdout.ExpectMatchContext(ctx, sched.Humanize()) - stdout.ExpectMatchContext(ctx, sched.Next(now).In(loc).Format(time.RFC3339)) + stdout.ExpectMatch(ctx, ws[3].OwnerName+"/"+ws[3].Name) + stdout.ExpectMatch(ctx, sched.Humanize()) + stdout.ExpectMatch(ctx, sched.Next(now).In(loc).Format(time.RFC3339)) }) t.Run("SetStop", func(t *testing.T) { @@ -303,9 +303,9 @@ func TestScheduleModify(t *testing.T) { require.NoError(t, inv.Run()) // Then: the updated schedule should be shown - stdout.ExpectMatchContext(ctx, ws[2].OwnerName+"/"+ws[2].Name) - stdout.ExpectMatchContext(ctx, "8h30m") - stdout.ExpectMatchContext(ctx, ws[2].LatestBuild.Deadline.Time.In(loc).Format(time.RFC3339)) + stdout.ExpectMatch(ctx, ws[2].OwnerName+"/"+ws[2].Name) + stdout.ExpectMatch(ctx, "8h30m") + stdout.ExpectMatch(ctx, ws[2].LatestBuild.Deadline.Time.In(loc).Format(time.RFC3339)) }) t.Run("UnsetStart", func(t *testing.T) { @@ -320,7 +320,7 @@ func TestScheduleModify(t *testing.T) { require.NoError(t, inv.Run()) // Then: the updated schedule should be shown - stdout.ExpectMatchContext(ctx, ws[1].OwnerName+"/"+ws[1].Name) + stdout.ExpectMatch(ctx, ws[1].OwnerName+"/"+ws[1].Name) }) t.Run("UnsetStop", func(t *testing.T) { @@ -335,7 +335,7 @@ func TestScheduleModify(t *testing.T) { require.NoError(t, inv.Run()) // Then: the updated schedule should be shown - stdout.ExpectMatchContext(ctx, ws[0].OwnerName+"/"+ws[0].Name) + stdout.ExpectMatch(ctx, ws[0].OwnerName+"/"+ws[0].Name) }) } @@ -386,11 +386,11 @@ func TestScheduleOverride(t *testing.T) { expectedDeadline := updated.LatestBuild.Deadline.Time.In(loc).Format(time.RFC3339) // Then: the updated schedule should be shown - stdout.ExpectMatchContext(ctx, ws[0].OwnerName+"/"+ws[0].Name) - stdout.ExpectMatchContext(ctx, sched.Humanize()) - stdout.ExpectMatchContext(ctx, sched.Next(now).In(loc).Format(time.RFC3339)) - stdout.ExpectMatchContext(ctx, "8h") - stdout.ExpectMatchContext(ctx, expectedDeadline) + stdout.ExpectMatch(ctx, ws[0].OwnerName+"/"+ws[0].Name) + stdout.ExpectMatch(ctx, sched.Humanize()) + stdout.ExpectMatch(ctx, sched.Next(now).In(loc).Format(time.RFC3339)) + stdout.ExpectMatch(ctx, "8h") + stdout.ExpectMatch(ctx, expectedDeadline) }) } } @@ -438,8 +438,8 @@ func TestScheduleStart_TemplateAutostartRequirement(t *testing.T) { // Then: warning should be shown // In AGPL, this will show all days (enterprise feature defaults to all days allowed) - stdout.ExpectMatchContext(ctx, "Warning") - stdout.ExpectMatchContext(ctx, "may only autostart") + stdout.ExpectMatch(ctx, "Warning") + stdout.ExpectMatch(ctx, "may only autostart") }) t.Run("NoWarningWhenManual", func(t *testing.T) { diff --git a/cli/secret_test.go b/cli/secret_test.go index 06224d45c6..be3d993db5 100644 --- a/cli/secret_test.go +++ b/cli/secret_test.go @@ -520,10 +520,10 @@ func TestSecretDelete(t *testing.T) { stdout := expecter.NewAttachedToInvocation(t, inv) stdin := testutil.NewWriterAttachedToInvocation(t, logger.Named("stdin"), inv) waiter := clitest.StartWithWaiter(t, inv) - stdout.ExpectMatchContext(ctx, "Delete secret") - stdout.ExpectMatchContext(ctx, "service-token") + stdout.ExpectMatch(ctx, "Delete secret") + stdout.ExpectMatch(ctx, "service-token") stdin.WriteLine("yes") - stdout.ExpectMatchContext(ctx, "Deleted secret") + stdout.ExpectMatch(ctx, "Deleted secret") require.NoError(t, waiter.Wait()) @@ -580,8 +580,8 @@ func TestSecretDelete(t *testing.T) { stdout := expecter.NewAttachedToInvocation(t, inv) stdin := testutil.NewWriterAttachedToInvocation(t, logger.Named("stdin"), inv) waiter := clitest.StartWithWaiter(t, inv) - stdout.ExpectMatchContext(ctx, "Delete secret") - stdout.ExpectMatchContext(ctx, "missing-secret") + stdout.ExpectMatch(ctx, "Delete secret") + stdout.ExpectMatch(ctx, "missing-secret") stdin.WriteLine("yes") err := waiter.Wait() diff --git a/cli/server_createadminuser_test.go b/cli/server_createadminuser_test.go index c458ab5dda..a8f34250fe 100644 --- a/cli/server_createadminuser_test.go +++ b/cli/server_createadminuser_test.go @@ -131,14 +131,14 @@ func TestServerCreateAdminUser(t *testing.T) { stdout := expecter.NewAttachedToInvocation(t, inv) clitest.Start(t, inv) - stdout.ExpectMatchContext(ctx, "Creating user...") - stdout.ExpectMatchContext(ctx, "Generating user SSH key...") - stdout.ExpectMatchContext(ctx, fmt.Sprintf("Adding user to organization %q (%s) as admin...", org1Name, org1ID.String())) - stdout.ExpectMatchContext(ctx, fmt.Sprintf("Adding user to organization %q (%s) as admin...", org2Name, org2ID.String())) - stdout.ExpectMatchContext(ctx, "User created successfully.") - stdout.ExpectMatchContext(ctx, username) - stdout.ExpectMatchContext(ctx, email) - stdout.ExpectMatchContext(ctx, "****") + stdout.ExpectMatch(ctx, "Creating user...") + stdout.ExpectMatch(ctx, "Generating user SSH key...") + stdout.ExpectMatch(ctx, fmt.Sprintf("Adding user to organization %q (%s) as admin...", org1Name, org1ID.String())) + stdout.ExpectMatch(ctx, fmt.Sprintf("Adding user to organization %q (%s) as admin...", org2Name, org2ID.String())) + stdout.ExpectMatch(ctx, "User created successfully.") + stdout.ExpectMatch(ctx, username) + stdout.ExpectMatch(ctx, email) + stdout.ExpectMatch(ctx, "****") verifyUser(t, connectionURL, username, email, password) }) @@ -165,10 +165,10 @@ func TestServerCreateAdminUser(t *testing.T) { stdout := expecter.NewAttachedToInvocation(t, inv) clitest.Start(t, inv) - stdout.ExpectMatchContext(ctx, "User created successfully.") - stdout.ExpectMatchContext(ctx, username) - stdout.ExpectMatchContext(ctx, email) - stdout.ExpectMatchContext(ctx, "****") + stdout.ExpectMatch(ctx, "User created successfully.") + stdout.ExpectMatch(ctx, username) + stdout.ExpectMatch(ctx, email) + stdout.ExpectMatch(ctx, "****") verifyUser(t, connectionURL, username, email, password) }) @@ -197,19 +197,19 @@ func TestServerCreateAdminUser(t *testing.T) { clitest.Start(t, inv) - stdout.ExpectMatchContext(ctx, "Username") + stdout.ExpectMatch(ctx, "Username") stdin.WriteLine(username) - stdout.ExpectMatchContext(ctx, "Email") + stdout.ExpectMatch(ctx, "Email") stdin.WriteLine(email) - stdout.ExpectMatchContext(ctx, "Password") + stdout.ExpectMatch(ctx, "Password") stdin.WriteLine(password) - stdout.ExpectMatchContext(ctx, "Confirm password") + stdout.ExpectMatch(ctx, "Confirm password") stdin.WriteLine(password) - stdout.ExpectMatchContext(ctx, "User created successfully.") - stdout.ExpectMatchContext(ctx, username) - stdout.ExpectMatchContext(ctx, email) - stdout.ExpectMatchContext(ctx, "****") + stdout.ExpectMatch(ctx, "User created successfully.") + stdout.ExpectMatch(ctx, username) + stdout.ExpectMatch(ctx, email) + stdout.ExpectMatch(ctx, "****") verifyUser(t, connectionURL, username, email, password) }) diff --git a/cli/server_regenerate_vapid_keypair_test.go b/cli/server_regenerate_vapid_keypair_test.go index a52978173a..2864b6aaee 100644 --- a/cli/server_regenerate_vapid_keypair_test.go +++ b/cli/server_regenerate_vapid_keypair_test.go @@ -42,11 +42,11 @@ func TestRegenerateVapidKeypair(t *testing.T) { stdout := expecter.NewAttachedToInvocation(t, inv) clitest.Start(t, inv) - stdout.ExpectMatchContext(ctx, "Regenerating VAPID keypair...") - stdout.ExpectMatchContext(ctx, "This will delete all existing webpush subscriptions.") - stdout.ExpectMatchContext(ctx, "Are you sure you want to continue? (y/N)") + stdout.ExpectMatch(ctx, "Regenerating VAPID keypair...") + stdout.ExpectMatch(ctx, "This will delete all existing webpush subscriptions.") + stdout.ExpectMatch(ctx, "Are you sure you want to continue? (y/N)") // don't need to write to stdin because we passed --yes - stdout.ExpectMatchContext(ctx, "VAPID keypair regenerated successfully.") + stdout.ExpectMatch(ctx, "VAPID keypair regenerated successfully.") // Ensure the VAPID keypair was created. keys, err := db.GetWebpushVAPIDKeys(ctx) @@ -85,11 +85,11 @@ func TestRegenerateVapidKeypair(t *testing.T) { stdout := expecter.NewAttachedToInvocation(t, inv) clitest.Start(t, inv) - stdout.ExpectMatchContext(ctx, "Regenerating VAPID keypair...") - stdout.ExpectMatchContext(ctx, "This will delete all existing webpush subscriptions.") - stdout.ExpectMatchContext(ctx, "Are you sure you want to continue? (y/N)") + stdout.ExpectMatch(ctx, "Regenerating VAPID keypair...") + stdout.ExpectMatch(ctx, "This will delete all existing webpush subscriptions.") + stdout.ExpectMatch(ctx, "Are you sure you want to continue? (y/N)") // don't need to write to stdin because we passed --yes - stdout.ExpectMatchContext(ctx, "VAPID keypair regenerated successfully.") + stdout.ExpectMatch(ctx, "VAPID keypair regenerated successfully.") // Ensure the VAPID keypair was created. keys, err := db.GetWebpushVAPIDKeys(ctx) diff --git a/cli/server_test.go b/cli/server_test.go index 6776e84424..08af5d7efe 100644 --- a/cli/server_test.go +++ b/cli/server_test.go @@ -241,7 +241,7 @@ func TestServer(t *testing.T) { }() matchCh1 := make(chan string, 1) go func() { - matchCh1 <- stdout.ExpectMatchContext(ctx, "Using an ephemeral deployment directory") + matchCh1 <- stdout.ExpectMatch(ctx, "Using an ephemeral deployment directory") }() select { case err := <-errCh: @@ -260,7 +260,7 @@ func TestServer(t *testing.T) { matchCh2 := make(chan string, 1) go func() { // The "View the Web UI" log is a decent indicator that the server was successfully started. - matchCh2 <- stdout.ExpectMatchContext(ctx, "View the Web UI") + matchCh2 <- stdout.ExpectMatch(ctx, "View the Web UI") }() select { case err := <-errCh: @@ -282,7 +282,7 @@ func TestServer(t *testing.T) { err := root.Run() require.NoError(t, err) - stdout.ExpectMatchContext(ctx, "psql") + stdout.ExpectMatch(ctx, "psql") }) t.Run("BuiltinPostgresURLRaw", func(t *testing.T) { t.Parallel() @@ -522,9 +522,9 @@ func TestServer(t *testing.T) { // Just wait for startup _ = waitAccessURL(t, cfg) - stdout.ExpectMatchContext(ctx, "this may cause unexpected problems when creating workspaces") - stdout.ExpectMatchContext(ctx, "View the Web UI:") - stdout.ExpectMatchContext(ctx, "http://localhost:3000/") + stdout.ExpectMatch(ctx, "this may cause unexpected problems when creating workspaces") + stdout.ExpectMatch(ctx, "View the Web UI:") + stdout.ExpectMatch(ctx, "http://localhost:3000/") }) // Validate that an https scheme is prepended to a remote access URL @@ -549,9 +549,9 @@ func TestServer(t *testing.T) { // Just wait for startup _ = waitAccessURL(t, cfg) - stdout.ExpectMatchContext(ctx, "this may cause unexpected problems when creating workspaces") - stdout.ExpectMatchContext(ctx, "View the Web UI:") - stdout.ExpectMatchContext(ctx, "https://foobarbaz.mydomain") + stdout.ExpectMatch(ctx, "this may cause unexpected problems when creating workspaces") + stdout.ExpectMatch(ctx, "View the Web UI:") + stdout.ExpectMatch(ctx, "https://foobarbaz.mydomain") }) t.Run("NoWarningWithRemoteAccessURL", func(t *testing.T) { @@ -572,8 +572,8 @@ func TestServer(t *testing.T) { // Just wait for startup _ = waitAccessURL(t, cfg) - stdout.ExpectMatchContext(ctx, "View the Web UI:") - stdout.ExpectMatchContext(ctx, "https://google.com") + stdout.ExpectMatch(ctx, "View the Web UI:") + stdout.ExpectMatch(ctx, "https://google.com") }) t.Run("NoSchemeAccessURL", func(t *testing.T) { @@ -820,12 +820,12 @@ func TestServer(t *testing.T) { // We can't use waitAccessURL as it will only return the HTTP URL. const httpLinePrefix = "Started HTTP listener at" - stdout.ExpectMatchContext(ctx, httpLinePrefix) + stdout.ExpectMatch(ctx, httpLinePrefix) httpLine := stdout.ReadLine(ctx) httpAddr := strings.TrimSpace(strings.TrimPrefix(httpLine, httpLinePrefix)) require.NotEmpty(t, httpAddr) const tlsLinePrefix = "Started TLS/HTTPS listener at " - stdout.ExpectMatchContext(ctx, tlsLinePrefix) + stdout.ExpectMatch(ctx, tlsLinePrefix) tlsLine := stdout.ReadLine(ctx) tlsAddr := strings.TrimSpace(strings.TrimPrefix(tlsLine, tlsLinePrefix)) require.NotEmpty(t, tlsAddr) @@ -963,14 +963,14 @@ func TestServer(t *testing.T) { // We can't use waitAccessURL as it will only return the HTTP URL. if c.httpListener { const httpLinePrefix = "Started HTTP listener at" - stdout.ExpectMatchContext(ctx, httpLinePrefix) + stdout.ExpectMatch(ctx, httpLinePrefix) httpLine := stdout.ReadLine(ctx) httpAddr = strings.TrimSpace(strings.TrimPrefix(httpLine, httpLinePrefix)) require.NotEmpty(t, httpAddr) } if c.tlsListener { const tlsLinePrefix = "Started TLS/HTTPS listener at" - stdout.ExpectMatchContext(ctx, tlsLinePrefix) + stdout.ExpectMatch(ctx, tlsLinePrefix) tlsLine := stdout.ReadLine(ctx) tlsAddr = strings.TrimSpace(strings.TrimPrefix(tlsLine, tlsLinePrefix)) require.NotEmpty(t, tlsAddr) @@ -1054,8 +1054,8 @@ func TestServer(t *testing.T) { // our initial interactions with PostgreSQL are complete. So, ignore errors of that type for this test. startIgnoringPostgresQueryCancel(t, inv) - stdout.ExpectMatchContext(ctx, "Started HTTP listener") - stdout.ExpectMatchContext(ctx, "http://0.0.0.0:") + stdout.ExpectMatch(ctx, "Started HTTP listener") + stdout.ExpectMatch(ctx, "http://0.0.0.0:") }) t.Run("CanListenUnspecifiedv6", func(t *testing.T) { @@ -1074,8 +1074,8 @@ func TestServer(t *testing.T) { // our initial interactions with PostgreSQL are complete. So, ignore errors of that type for this test. startIgnoringPostgresQueryCancel(t, inv) - stdout.ExpectMatchContext(ctx, "Started HTTP listener at") - stdout.ExpectMatchContext(ctx, "http://[::]:") + stdout.ExpectMatch(ctx, "Started HTTP listener at") + stdout.ExpectMatch(ctx, "http://[::]:") }) t.Run("NoAddress", func(t *testing.T) { @@ -1133,7 +1133,7 @@ func TestServer(t *testing.T) { stdout := expecter.NewAttachedToInvocation(t, inv) clitest.Start(t, inv.WithContext(ctx)) - stdout.ExpectMatchContext(ctx, "is deprecated") + stdout.ExpectMatch(ctx, "is deprecated") accessURL := waitAccessURL(t, cfg) require.Equal(t, "http", accessURL.Scheme) @@ -1161,7 +1161,7 @@ func TestServer(t *testing.T) { stdout := expecter.NewAttachedToInvocation(t, root) clitest.Start(t, root.WithContext(ctx)) - stdout.ExpectMatchContext(ctx, "is deprecated") + stdout.ExpectMatch(ctx, "is deprecated") accessURL := waitAccessURL(t, cfg) require.Equal(t, "https", accessURL.Scheme) @@ -1263,7 +1263,7 @@ func TestServer(t *testing.T) { // Wait until we see the prometheus address in the logs. addrMatchExpr := `http server listening\s+addr=(\S+)\s+name=prometheus` - lineMatch := stdout.ExpectRegexMatchContext(ctx, addrMatchExpr) + lineMatch := stdout.ExpectRegexMatch(ctx, addrMatchExpr) promAddr := regexp.MustCompile(addrMatchExpr).FindStringSubmatch(lineMatch)[1] testutil.Eventually(ctx, t, func(ctx context.Context) bool { @@ -1324,7 +1324,7 @@ func TestServer(t *testing.T) { // Wait until we see the prometheus address in the logs. addrMatchExpr := `http server listening\s+addr=(\S+)\s+name=prometheus` - lineMatch := stdout.ExpectRegexMatchContext(ctx, addrMatchExpr) + lineMatch := stdout.ExpectRegexMatch(ctx, addrMatchExpr) promAddr := regexp.MustCompile(addrMatchExpr).FindStringSubmatch(lineMatch)[1] testutil.Eventually(ctx, t, func(ctx context.Context) bool { @@ -2020,7 +2020,7 @@ func TestServer_Logging_NoParallel(t *testing.T) { // Wait for server to listen on HTTP, this is a good // starting point for expecting logs. - _ = stdout.ExpectMatchContext(ctx, "Started HTTP listener at") + _ = stdout.ExpectMatch(ctx, "Started HTTP listener at") loggingWaitFile(t, fi, testutil.WaitSuperLong) }) @@ -2057,7 +2057,7 @@ func TestServer_Logging_NoParallel(t *testing.T) { // Wait for server to listen on HTTP, this is a good // starting point for expecting logs. - _ = stdout.ExpectMatchContext(ctx, "Started HTTP listener at") + _ = stdout.ExpectMatch(ctx, "Started HTTP listener at") loggingWaitFile(t, fi1, testutil.WaitSuperLong) loggingWaitFile(t, fi2, testutil.WaitSuperLong) @@ -2259,7 +2259,7 @@ func TestServer_GracefulShutdown(t *testing.T) { // It's fair to assume `stopFunc` isn't nil here, because the server // has started and access URL is propagated. stopFunc() - stdout.ExpectMatchContext(ctx, "waiting for provisioner jobs to complete") + stdout.ExpectMatch(ctx, "waiting for provisioner jobs to complete") err := <-serverErr require.NoError(t, err) } @@ -2503,10 +2503,10 @@ func TestServer_TelemetryDisabled_FinalReport(t *testing.T) { }() if opts.waitForSnapshot { - stdout.ExpectMatchContext(testutil.Context(t, testutil.WaitLong), "submitted snapshot") + stdout.ExpectMatch(testutil.Context(t, testutil.WaitLong), "submitted snapshot") } if opts.waitForTelemetryDisabledCheck { - stdout.ExpectMatchContext(testutil.Context(t, testutil.WaitLong), "finished telemetry status check") + stdout.ExpectMatch(testutil.Context(t, testutil.WaitLong), "finished telemetry status check") } return errChan, cancelFunc } diff --git a/cli/show_test.go b/cli/show_test.go index cb4ab0293c..2e8799088a 100644 --- a/cli/show_test.go +++ b/cli/show_test.go @@ -60,7 +60,7 @@ func TestShow(t *testing.T) { {match: "coder ssh " + workspace.Name}, } for _, m := range matches { - stdout.ExpectMatchContext(ctx, m.match) + stdout.ExpectMatch(ctx, m.match) if len(m.write) > 0 { stdin.WriteLine(m.write) } @@ -115,7 +115,7 @@ func TestShow(t *testing.T) { {match: "coder ssh " + workspace.Name}, } for _, m := range matches { - stdout.ExpectMatchContext(ctx, m.match) + stdout.ExpectMatch(ctx, m.match) if len(m.write) > 0 { stdin.WriteLine(m.write) } diff --git a/cli/ssh_test.go b/cli/ssh_test.go index 0cf5a83665..eb31dc801e 100644 --- a/cli/ssh_test.go +++ b/cli/ssh_test.go @@ -96,7 +96,7 @@ func TestSSH(t *testing.T) { err := inv.WithContext(ctx).Run() assert.NoError(t, err) }) - stdout.ExpectMatchContext(ctx, "Waiting") + stdout.ExpectMatch(ctx, "Waiting") _ = agenttest.New(t, client.URL, agentToken) coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID) @@ -138,7 +138,7 @@ func TestSSH(t *testing.T) { err := inv.WithContext(ctx).Run() assert.NoError(t, err) }) - stdout.ExpectMatchContext(ctx, "Waiting") + stdout.ExpectMatch(ctx, "Waiting") _ = agenttest.New(t, client.URL, agentToken) coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID) @@ -271,7 +271,7 @@ func TestSSH(t *testing.T) { } for _, stdout := range stdouts { - stdout.ExpectMatchContext(ctx, "Workspace was stopped, starting workspace to allow connecting to") + stdout.ExpectMatch(ctx, "Workspace was stopped, starting workspace to allow connecting to") } // Allow one build to complete. @@ -287,7 +287,7 @@ func TestSSH(t *testing.T) { for _, stdout := range stdouts { // Either allow the command to start the workspace or fail // due to conflict (race), in which case it retries. - match := stdout.ExpectRegexMatchContext(ctx, "Waiting for the workspace agent to connect") + match := stdout.ExpectRegexMatch(ctx, "Waiting for the workspace agent to connect") if strings.Contains(match, "Unable to start the workspace due to conflict, the workspace may be starting, retrying without autostart...") { foundConflict++ } @@ -388,7 +388,7 @@ func TestSSH(t *testing.T) { err := inv.WithContext(ctx).Run() assert.ErrorIs(t, err, cliui.ErrCanceled) }) - stdout.ExpectMatchContext(ctx, wantURL) + stdout.ExpectMatch(ctx, wantURL) cancel() <-cmdDone }) @@ -421,14 +421,14 @@ func TestSSH(t *testing.T) { err := inv.WithContext(ctx).Run() assert.Error(t, err) }) - stdout.ExpectMatchContext(ctx, "Waiting") + stdout.ExpectMatch(ctx, "Waiting") _ = agenttest.New(t, client.URL, r.AgentToken) coderdtest.AwaitWorkspaceAgents(t, client, r.Workspace.ID) // Ensure the agent is connected. stdin.WriteLine("echo hell'o'") - stdout.ExpectMatchContext(ctx, "hello") + stdout.ExpectMatch(ctx, "hello") _ = dbfake.WorkspaceBuild(t, store, r.Workspace). Seed(database.WorkspaceBuild{ @@ -1188,12 +1188,12 @@ func TestSSH(t *testing.T) { // Linux: /tmp/auth-agent3167016167/listener.sock // macOS: /var/folders/ng/m1q0wft14hj0t3rtjxrdnzsr0000gn/T/auth-agent3245553419/listener.sock stdin.WriteLine(`env | grep SSH_AUTH_SOCK=`) - stdout.ExpectMatchContext(ctx, "SSH_AUTH_SOCK=") + stdout.ExpectMatch(ctx, "SSH_AUTH_SOCK=") // Ensure that ssh-add lists our key. stdin.WriteLine("ssh-add -L") keys, err := kr.List() require.NoError(t, err, "list keys failed") - stdout.ExpectMatchContext(ctx, keys[0].String()) + stdout.ExpectMatch(ctx, keys[0].String()) // And we're done. stdin.WriteLine("exit") @@ -1295,7 +1295,7 @@ func TestSSH(t *testing.T) { // Ensure the SSH connection is ready by testing the shell // input/output. stdin.WriteLine("echo $foo $baz") - stdout.ExpectMatchContext(ctx, "bar qux") + stdout.ExpectMatch(ctx, "bar qux") // And we're done. stdin.WriteLine("exit") @@ -1342,7 +1342,7 @@ func TestSSH(t *testing.T) { // Ensure the SSH connection is ready by testing the shell // input/output. stdin.WriteLine("echo ping' 'pong") - stdout.ExpectMatchContext(ctx, "ping pong") + stdout.ExpectMatch(ctx, "ping pong") // Start the listener on the "local machine". l, err := net.Listen("unix", localSock) @@ -1463,7 +1463,7 @@ func TestSSH(t *testing.T) { // Ensure the SSH connection is ready by testing the shell // input/output. stdin.WriteLine("echo ping' 'pong") - stdout.ExpectMatchContext(ctx, "ping pong") + stdout.ExpectMatch(ctx, "ping pong") d := &net.Dialer{} fd, err := d.DialContext(ctx, "unix", remoteSock) @@ -1557,7 +1557,7 @@ func TestSSH(t *testing.T) { // Ensure the SSH connection is ready by testing the shell // input/output. stdin.WriteLine("echo ping' 'pong") - stdout.ExpectMatchContext(ctx, "ping pong") + stdout.ExpectMatch(ctx, "ping pong") for i, sock := range sockets { // Start the listener on the "local machine". @@ -1619,7 +1619,7 @@ func TestSSH(t *testing.T) { stdin := testutil.NewWriterAttachedToInvocation(t, logger.Named("stdin"), inv) w := clitest.StartWithWaiter(t, inv) - stdout.ExpectMatchContext(ctx, "Waiting") + stdout.ExpectMatch(ctx, "Waiting") agenttest.New(t, client.URL, agentToken) coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID) @@ -1726,7 +1726,7 @@ func TestSSH(t *testing.T) { err := inv.WithContext(ctx).Run() assert.NoError(t, err) }) - stdout.ExpectMatchContext(ctx, "Waiting") + stdout.ExpectMatch(ctx, "Waiting") _ = agenttest.New(t, client.URL, agentToken) coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID) @@ -2013,21 +2013,21 @@ Expire-Date: 0 _ = invOut.Peek(ctx, 1) invIn.WriteLine("echo hello 'world'") - invOut.ExpectMatchContext(ctx, "hello world") + invOut.ExpectMatch(ctx, "hello world") // Check the GNUPGHOME was correctly inherited via shell. invIn.WriteLine("env && echo env-''-command-done") - match := invOut.ExpectMatchContext(ctx, "env--command-done") + match := invOut.ExpectMatch(ctx, "env--command-done") require.Contains(t, match, "GNUPGHOME="+gnupgHomeWorkspace, match) // Get the agent extra socket path in the "workspace" via shell. invIn.WriteLine("gpgconf --list-dir agent-socket && echo gpgconf-''-agentsocket-command-done") - invOut.ExpectMatchContext(ctx, workspaceAgentSocketPath) - invOut.ExpectMatchContext(ctx, "gpgconf--agentsocket-command-done") + invOut.ExpectMatch(ctx, workspaceAgentSocketPath) + invOut.ExpectMatch(ctx, "gpgconf--agentsocket-command-done") // List the keys in the "workspace". invIn.WriteLine("gpg --list-keys && echo gpg-''-listkeys-command-done") - listKeysOutput := invOut.ExpectMatchContext(ctx, "gpg--listkeys-command-done") + listKeysOutput := invOut.ExpectMatch(ctx, "gpg--listkeys-command-done") require.Contains(t, listKeysOutput, "[ultimate] Coder Test ") // It's fine that this key is expired. We're just testing that the key trust // gets synced properly. @@ -2037,10 +2037,10 @@ Expire-Date: 0 // working as expected, since the workspace doesn't have access to the // private key directly and must use the forwarded agent. invIn.WriteLine("echo 'hello world' | gpg --clearsign && echo gpg-''-sign-command-done") - invOut.ExpectMatchContext(ctx, "BEGIN PGP SIGNED MESSAGE") - invOut.ExpectMatchContext(ctx, "Hash:") - invOut.ExpectMatchContext(ctx, "hello world") - invOut.ExpectMatchContext(ctx, "gpg--sign-command-done") + invOut.ExpectMatch(ctx, "BEGIN PGP SIGNED MESSAGE") + invOut.ExpectMatch(ctx, "Hash:") + invOut.ExpectMatch(ctx, "hello world") + invOut.ExpectMatch(ctx, "gpg--sign-command-done") // And we're done. invIn.WriteLine("exit") @@ -2099,9 +2099,9 @@ func TestSSH_Container(t *testing.T) { assert.NoError(t, err) }) - stdout.ExpectMatchContext(ctx, " #") + stdout.ExpectMatch(ctx, " #") stdin.WriteLine("hostname") - stdout.ExpectMatchContext(ctx, ct.Container.Config.Hostname) + stdout.ExpectMatch(ctx, ct.Container.Config.Hostname) stdin.WriteLine("exit") <-cmdDone }) @@ -2142,8 +2142,8 @@ func TestSSH_Container(t *testing.T) { assert.NoError(t, err) }) - stdout.ExpectMatchContext(ctx, fmt.Sprintf("Container not found: %q", cID)) - stdout.ExpectMatchContext(ctx, "Available containers: [something_completely_different]") + stdout.ExpectMatch(ctx, fmt.Sprintf("Container not found: %q", cID)) + stdout.ExpectMatch(ctx, "Available containers: [something_completely_different]") <-cmdDone }) diff --git a/cli/start_test.go b/cli/start_test.go index 8e8ac70c0c..ef6c2dd3ab 100644 --- a/cli/start_test.go +++ b/cli/start_test.go @@ -148,7 +148,7 @@ func TestStart(t *testing.T) { for i := 0; i < len(matches); i += 2 { match := matches[i] value := matches[i+1] - stdout.ExpectMatchContext(ctx, match) + stdout.ExpectMatch(ctx, match) if value != "" { stdin.WriteLine(value) @@ -202,7 +202,7 @@ func TestStart(t *testing.T) { assert.NoError(t, err) }() - stdout.ExpectMatchContext(ctx, "workspace has been started") + stdout.ExpectMatch(ctx, "workspace has been started") <-doneChan // Verify if ephemeral parameter is set @@ -256,7 +256,7 @@ func TestStartWithParameters(t *testing.T) { assert.NoError(t, err) }() - stdout.ExpectMatchContext(ctx, "workspace has been started") + stdout.ExpectMatch(ctx, "workspace has been started") <-doneChan // Verify if immutable parameter is set @@ -309,9 +309,9 @@ func TestStartWithParameters(t *testing.T) { }() newValue := "xyz" - stdout.ExpectMatchContext(ctx, mutableParameterName) + stdout.ExpectMatch(ctx, mutableParameterName) stdin.WriteLine(newValue) - stdout.ExpectMatchContext(ctx, "workspace has been started") + stdout.ExpectMatch(ctx, "workspace has been started") <-doneChan // Verify that the updated values are persisted. @@ -371,7 +371,7 @@ func TestStartUseParameterDefaults(t *testing.T) { assert.NoError(t, err) }() - stdout.ExpectMatchContext(ctx, "workspace has been started") + stdout.ExpectMatch(ctx, "workspace has been started") _ = testutil.TryReceive(ctx, t, doneChan) // Verify the new parameter was resolved to its default. @@ -451,7 +451,7 @@ func TestStartAutoUpdate(t *testing.T) { assert.NoError(t, err) }() - stdout.ExpectMatchContext(ctx, stringParameterName) + stdout.ExpectMatch(ctx, stringParameterName) stdin.WriteLine(stringParameterValue) <-doneChan @@ -483,7 +483,7 @@ func TestStart_AlreadyRunning(t *testing.T) { assert.NoError(t, err) }() - stdout.ExpectMatchContext(ctx, "workspace is already running") + stdout.ExpectMatch(ctx, "workspace is already running") _ = testutil.TryReceive(ctx, t, doneChan) } @@ -512,10 +512,10 @@ func TestStart_Starting(t *testing.T) { assert.NoError(t, err) }() - stdout.ExpectMatchContext(ctx, "workspace is already starting") + stdout.ExpectMatch(ctx, "workspace is already starting") _ = dbfake.JobComplete(t, store, r.Build.JobID).Pubsub(ps).Do() - stdout.ExpectMatchContext(ctx, "workspace has been started") + stdout.ExpectMatch(ctx, "workspace has been started") _ = testutil.TryReceive(ctx, t, doneChan) } @@ -549,7 +549,7 @@ func TestStart_NoWait(t *testing.T) { assert.NoError(t, err) }() - stdout.ExpectMatchContext(ctx, "workspace has been started in no-wait mode") + stdout.ExpectMatch(ctx, "workspace has been started in no-wait mode") _ = testutil.TryReceive(ctx, t, doneChan) } @@ -582,7 +582,7 @@ func TestStart_WithReason(t *testing.T) { assert.NoError(t, err) }() - stdout.ExpectMatchContext(ctx, "workspace has been started") + stdout.ExpectMatch(ctx, "workspace has been started") _ = testutil.TryReceive(ctx, t, doneChan) workspace = coderdtest.MustWorkspace(t, member, workspace.ID) @@ -635,8 +635,8 @@ func TestStart_FailedStartCleansUp(t *testing.T) { }() // The CLI should detect the failed start and clean up first. - stdout.ExpectMatchContext(ctx, "Cleaning up before retrying") - stdout.ExpectMatchContext(ctx, "workspace has been started") + stdout.ExpectMatch(ctx, "Cleaning up before retrying") + stdout.ExpectMatch(ctx, "workspace has been started") _ = testutil.TryReceive(ctx, t, doneChan) } diff --git a/cli/task_delete_test.go b/cli/task_delete_test.go index c105f9f0fa..1bc20817ef 100644 --- a/cli/task_delete_test.go +++ b/cli/task_delete_test.go @@ -205,7 +205,7 @@ func TestExpTaskDelete(t *testing.T) { stdout := expecter.NewAttachedToInvocation(t, inv) stdin := testutil.NewWriterAttachedToInvocation(t, logger.Named("stdin"), inv) w := clitest.StartWithWaiter(t, inv) - stdout.ExpectMatchContext(ctx, "Delete these tasks:") + stdout.ExpectMatch(ctx, "Delete these tasks:") stdin.WriteLine("yes") runErr = w.Wait() outBuf.Write(stdout.ReadAll()) diff --git a/cli/task_list_test.go b/cli/task_list_test.go index 6e2b984dd9..35b47b9595 100644 --- a/cli/task_list_test.go +++ b/cli/task_list_test.go @@ -77,7 +77,7 @@ func TestExpTaskList(t *testing.T) { err := inv.WithContext(ctx).Run() require.NoError(t, err) - stdout.ExpectMatchContext(ctx, "No tasks found.") + stdout.ExpectMatch(ctx, "No tasks found.") }) t.Run("Single_Table", func(t *testing.T) { @@ -102,9 +102,9 @@ func TestExpTaskList(t *testing.T) { require.NoError(t, err) // Validate the table includes the task and status. - stdout.ExpectMatchContext(ctx, task.Name) - stdout.ExpectMatchContext(ctx, "initializing") - stdout.ExpectMatchContext(ctx, wantPrompt) + stdout.ExpectMatch(ctx, task.Name) + stdout.ExpectMatch(ctx, "initializing") + stdout.ExpectMatch(ctx, wantPrompt) }) t.Run("StatusFilter_JSON", func(t *testing.T) { @@ -162,7 +162,7 @@ func TestExpTaskList(t *testing.T) { err := inv.WithContext(ctx).Run() require.NoError(t, err) - stdout.ExpectMatchContext(ctx, task.Name) + stdout.ExpectMatch(ctx, task.Name) }) t.Run("Quiet", func(t *testing.T) { diff --git a/cli/task_pause_test.go b/cli/task_pause_test.go index a8e24d130f..7d3e6f9b4b 100644 --- a/cli/task_pause_test.go +++ b/cli/task_pause_test.go @@ -82,11 +82,11 @@ func TestExpTaskPause(t *testing.T) { stdout := expecter.NewAttachedToInvocation(t, inv) stdin := testutil.NewWriterAttachedToInvocation(t, logger.Named("stdin"), inv) w := clitest.StartWithWaiter(t, inv) - stdout.ExpectMatchContext(ctx, "Pause task") + stdout.ExpectMatch(ctx, "Pause task") stdin.WriteLine("yes") // Then: We expect the task to be paused - stdout.ExpectMatchContext(ctx, "has been paused") + stdout.ExpectMatch(ctx, "has been paused") require.NoError(t, w.Wait()) updated, err := setup.userClient.TaskByIdentifier(ctx, setup.task.Name) @@ -112,7 +112,7 @@ func TestExpTaskPause(t *testing.T) { stdout := expecter.NewAttachedToInvocation(t, inv) stdin := testutil.NewWriterAttachedToInvocation(t, logger.Named("stdin"), inv) w := clitest.StartWithWaiter(t, inv) - stdout.ExpectMatchContext(ctx, "Pause task") + stdout.ExpectMatch(ctx, "Pause task") stdin.WriteLine("no") require.Error(t, w.Wait()) diff --git a/cli/task_resume_test.go b/cli/task_resume_test.go index 94ebd0fa97..e4522f8c76 100644 --- a/cli/task_resume_test.go +++ b/cli/task_resume_test.go @@ -115,11 +115,11 @@ func TestExpTaskResume(t *testing.T) { stdout := expecter.NewAttachedToInvocation(t, inv) stdin := testutil.NewWriterAttachedToInvocation(t, logger.Named("stdin"), inv) w := clitest.StartWithWaiter(t, inv) - stdout.ExpectMatchContext(ctx, "Resume task") + stdout.ExpectMatch(ctx, "Resume task") stdin.WriteLine("yes") // Then: We expect the task to be resumed - stdout.ExpectMatchContext(ctx, "has been resumed") + stdout.ExpectMatch(ctx, "has been resumed") require.NoError(t, w.Wait()) updated, err := setup.userClient.TaskByIdentifier(ctx, setup.task.Name) @@ -146,7 +146,7 @@ func TestExpTaskResume(t *testing.T) { stdout := expecter.NewAttachedToInvocation(t, inv) stdin := testutil.NewWriterAttachedToInvocation(t, logger.Named("stdin"), inv) w := clitest.StartWithWaiter(t, inv) - stdout.ExpectMatchContext(ctx, "Resume task") + stdout.ExpectMatch(ctx, "Resume task") stdin.WriteLine("no") require.Error(t, w.Wait()) diff --git a/cli/task_send_test.go b/cli/task_send_test.go index e32f435242..230f6a8e6c 100644 --- a/cli/task_send_test.go +++ b/cli/task_send_test.go @@ -157,7 +157,7 @@ func Test_TaskSend(t *testing.T) { // Wait for the command to observe the initializing state and // start watching the workspace build. This ensures the command // has entered the waiting code path. - stdout.ExpectMatchContext(ctx, "Queued") + stdout.ExpectMatch(ctx, "Queued") // Connect a new agent so the task can transition to active. agentClient := agentsdk.New(setup.userClient.URL, agentsdk.WithFixedToken(setup.agentToken)) @@ -208,7 +208,7 @@ func Test_TaskSend(t *testing.T) { // Wait for the command to observe the paused state, trigger // a resume, and start watching the workspace build. - stdout.ExpectMatchContext(ctx, "Queued") + stdout.ExpectMatch(ctx, "Queued") // Connect a new agent so the task can transition to active. agentClient := agentsdk.New(setup.userClient.URL, agentsdk.WithFixedToken(setup.agentToken)) @@ -265,7 +265,7 @@ func Test_TaskSend(t *testing.T) { // Wait for the command to enter the build-watching phase // of waitForTaskIdle. - stdout.ExpectMatchContext(ctx, "Waiting for task to become idle") + stdout.ExpectMatch(ctx, "Waiting for task to become idle") // Wait for ticker creation and release it. tickCall := tickTrap.MustWait(ctx) diff --git a/cli/templatecreate_test.go b/cli/templatecreate_test.go index bd0f9db0bf..cb74480043 100644 --- a/cli/templatecreate_test.go +++ b/cli/templatecreate_test.go @@ -52,7 +52,7 @@ func TestCliTemplateCreate(t *testing.T) { {match: "Confirm create?", write: "yes"}, } for _, m := range matches { - stdout.ExpectMatchContext(ctx, m.match) + stdout.ExpectMatch(ctx, m.match) if len(m.write) > 0 { stdin.WriteLine(m.write) } @@ -92,7 +92,7 @@ func TestCliTemplateCreate(t *testing.T) { {match: "Upload", write: "no"}, } for _, m := range matches { - stdout.ExpectMatchContext(ctx, m.match) + stdout.ExpectMatch(ctx, m.match) if len(m.write) > 0 { stdin.WriteLine(m.write) } @@ -248,7 +248,7 @@ func TestCliTemplateCreate(t *testing.T) { {match: "Confirm create?", write: "yes"}, } for _, m := range matches { - stdout.ExpectMatchContext(ctx, m.match) + stdout.ExpectMatch(ctx, m.match) if len(m.write) > 0 { stdin.WriteLine(m.write) } @@ -288,7 +288,7 @@ func TestCliTemplateCreate(t *testing.T) { {match: "Confirm create?", write: "yes"}, } for _, m := range matches { - stdout.ExpectMatchContext(ctx, m.match) + stdout.ExpectMatch(ctx, m.match) if len(m.write) > 0 { stdin.WriteLine(m.write) } diff --git a/cli/templatedelete_test.go b/cli/templatedelete_test.go index a98be32e29..a85bce090a 100644 --- a/cli/templatedelete_test.go +++ b/cli/templatedelete_test.go @@ -44,7 +44,7 @@ func TestTemplateDelete(t *testing.T) { execDone <- inv.Run() }() - stdout.ExpectMatchContext(ctx, fmt.Sprintf("Delete these templates: %s?", pretty.Sprint(cliui.DefaultStyles.Code, template.Name))) + stdout.ExpectMatch(ctx, fmt.Sprintf("Delete these templates: %s?", pretty.Sprint(cliui.DefaultStyles.Code, template.Name))) stdin.WriteLine("yes") require.NoError(t, <-execDone) @@ -107,7 +107,7 @@ func TestTemplateDelete(t *testing.T) { execDone <- inv.Run() }() - stdout.ExpectMatchContext(ctx, + stdout.ExpectMatch(ctx, fmt.Sprintf("Delete these templates: %s?", pretty.Sprint(cliui.DefaultStyles.Code, strings.Join(templateNames, ", ")))) stdin.WriteLine("yes") diff --git a/cli/templatelist_test.go b/cli/templatelist_test.go index 60e6c7a346..9b7aed576a 100644 --- a/cli/templatelist_test.go +++ b/cli/templatelist_test.go @@ -52,7 +52,7 @@ func TestTemplateList(t *testing.T) { require.NoError(t, <-errC) for _, name := range templatesList { - stdout.ExpectMatchContext(ctx, name) + stdout.ExpectMatch(ctx, name) } }) t.Run("ListTemplatesJSON", func(t *testing.T) { @@ -105,7 +105,7 @@ func TestTemplateList(t *testing.T) { require.NoError(t, <-errC) - stdout.ExpectMatchContext(ctx, "No templates found") - stdout.ExpectMatchContext(ctx, "Create one:") + stdout.ExpectMatch(ctx, "No templates found") + stdout.ExpectMatch(ctx, "Create one:") }) } diff --git a/cli/templatepresets_test.go b/cli/templatepresets_test.go index 893c37b0ea..4ab409c9b9 100644 --- a/cli/templatepresets_test.go +++ b/cli/templatepresets_test.go @@ -50,7 +50,7 @@ func TestTemplatePresets(t *testing.T) { // Should return a message when no presets are found for the given template and version. notFoundMessage := fmt.Sprintf("No presets found for template %q and template-version %q.", template.Name, version.Name) - stdout.ExpectRegexMatchContext(ctx, notFoundMessage) + stdout.ExpectRegexMatch(ctx, notFoundMessage) }) t.Run("ListsPresetsForDefaultTemplateVersion", func(t *testing.T) { @@ -119,11 +119,11 @@ func TestTemplatePresets(t *testing.T) { // Should: return the active version's presets sorted by name message := fmt.Sprintf("Showing presets for template %q and template version %q.", template.Name, version.Name) - stdout.ExpectMatchContext(ctx, message) - stdout.ExpectRegexMatchContext(ctx, `preset-default\s+k1=v2\s+true\s+0`) + stdout.ExpectMatch(ctx, message) + stdout.ExpectRegexMatch(ctx, `preset-default\s+k1=v2\s+true\s+0`) // The parameter order is not guaranteed in the output, so we match both possible orders - stdout.ExpectRegexMatchContext(ctx, `preset-multiple-params\s+(k1=v1,k2=v2)|(k2=v2,k1=v1)\s+false\s+-`) - stdout.ExpectRegexMatchContext(ctx, `preset-prebuilds\s+Preset without parameters and 2 prebuild instances.\s+\s+false\s+2`) + stdout.ExpectRegexMatch(ctx, `preset-multiple-params\s+(k1=v1,k2=v2)|(k2=v2,k1=v1)\s+false\s+-`) + stdout.ExpectRegexMatch(ctx, `preset-prebuilds\s+Preset without parameters and 2 prebuild instances.\s+\s+false\s+2`) }) t.Run("ListsPresetsForSpecifiedTemplateVersion", func(t *testing.T) { @@ -211,11 +211,11 @@ func TestTemplatePresets(t *testing.T) { // Should: return the specified version's presets sorted by name message := fmt.Sprintf("Showing presets for template %q and template version %q.", template.Name, version.Name) - stdout.ExpectMatchContext(ctx, message) - stdout.ExpectRegexMatchContext(ctx, `preset-default\s+k1=v2\s+true\s+0`) + stdout.ExpectMatch(ctx, message) + stdout.ExpectRegexMatch(ctx, `preset-default\s+k1=v2\s+true\s+0`) // The parameter order is not guaranteed in the output, so we match both possible orders - stdout.ExpectRegexMatchContext(ctx, `preset-multiple-params\s+(k1=v1,k2=v2)|(k2=v2,k1=v1)\s+false\s+-`) - stdout.ExpectRegexMatchContext(ctx, `preset-prebuilds\s+Preset without parameters and 2 prebuild instances.\s+\s+false\s+2`) + stdout.ExpectRegexMatch(ctx, `preset-multiple-params\s+(k1=v1,k2=v2)|(k2=v2,k1=v1)\s+false\s+-`) + stdout.ExpectRegexMatch(ctx, `preset-prebuilds\s+Preset without parameters and 2 prebuild instances.\s+\s+false\s+2`) }) t.Run("ListsPresetsJSON", func(t *testing.T) { diff --git a/cli/templatepull_test.go b/cli/templatepull_test.go index 5495bf0637..086a18702f 100644 --- a/cli/templatepull_test.go +++ b/cli/templatepull_test.go @@ -395,7 +395,7 @@ func TestTemplatePull_FolderConflict(t *testing.T) { waiter := clitest.StartWithWaiter(t, inv) - stdout.ExpectMatchContext(ctx, "not empty") + stdout.ExpectMatch(ctx, "not empty") stdin.WriteLine("no") waiter.RequireError() diff --git a/cli/templatepush_test.go b/cli/templatepush_test.go index d93dc1d7ce..04bcbb34f0 100644 --- a/cli/templatepush_test.go +++ b/cli/templatepush_test.go @@ -65,7 +65,7 @@ func TestTemplatePush(t *testing.T) { {match: "Upload", write: "yes"}, } for _, m := range matches { - stdout.ExpectMatchContext(ctx, m.match) + stdout.ExpectMatch(ctx, m.match) stdin.WriteLine(m.write) } @@ -154,7 +154,7 @@ func TestTemplatePush(t *testing.T) { inv = inv.WithContext(ctx) w := clitest.StartWithWaiter(t, inv) - stdout.ExpectMatchContext(ctx, tt.wantMatch) + stdout.ExpectMatch(ctx, tt.wantMatch) w.RequireSuccess() @@ -209,7 +209,7 @@ func TestTemplatePush(t *testing.T) { {match: "Upload", write: "no"}, } for _, m := range matches { - stdout.ExpectMatchContext(ctx, m.match) + stdout.ExpectMatch(ctx, m.match) if m.write != "" { stdin.WriteLine(m.write) } @@ -298,7 +298,7 @@ func TestTemplatePush(t *testing.T) { {match: "Upload", write: "yes"}, } for _, m := range matches { - stdout.ExpectMatchContext(ctx, m.match) + stdout.ExpectMatch(ctx, m.match) stdin.WriteLine(m.write) } @@ -361,7 +361,7 @@ func TestTemplatePush(t *testing.T) { {match: "Upload", write: "yes"}, } for _, m := range matches { - stdout.ExpectMatchContext(ctx, m.match) + stdout.ExpectMatch(ctx, m.match) stdin.WriteLine(m.write) } @@ -568,7 +568,7 @@ func TestTemplatePush(t *testing.T) { }, testutil.WaitShort, testutil.IntervalFast) if tt.expectOutput != "" { - stdout.ExpectMatchContext(ctx, tt.expectOutput) + stdout.ExpectMatch(ctx, tt.expectOutput) } }) } @@ -627,7 +627,7 @@ func TestTemplatePush(t *testing.T) { {match: "Upload", write: "yes"}, } for _, m := range matches { - stdout.ExpectMatchContext(ctx, m.match) + stdout.ExpectMatch(ctx, m.match) stdin.WriteLine(m.write) } @@ -695,7 +695,7 @@ func TestTemplatePush(t *testing.T) { {match: "Upload", write: "yes"}, } for _, m := range matches { - stdout.ExpectMatchContext(ctx, m.match) + stdout.ExpectMatch(ctx, m.match) stdin.WriteLine(m.write) } @@ -754,7 +754,7 @@ func TestTemplatePush(t *testing.T) { {match: "Upload", write: "yes"}, } for _, m := range matches { - stdout.ExpectMatchContext(ctx, m.match) + stdout.ExpectMatch(ctx, m.match) stdin.WriteLine(m.write) } @@ -831,7 +831,7 @@ func TestTemplatePush(t *testing.T) { {match: "Upload", write: "yes"}, } for _, m := range matches { - stdout.ExpectMatchContext(ctx, m.match) + stdout.ExpectMatch(ctx, m.match) stdin.WriteLine(m.write) } @@ -896,7 +896,7 @@ func TestTemplatePush(t *testing.T) { {match: "Upload", write: "yes"}, } for _, m := range matches { - stdout.ExpectMatchContext(ctx, m.match) + stdout.ExpectMatch(ctx, m.match) stdin.WriteLine(m.write) } @@ -963,7 +963,7 @@ func TestTemplatePush(t *testing.T) { {match: "Upload", write: "yes"}, } for _, m := range matches { - stdout.ExpectMatchContext(ctx, m.match) + stdout.ExpectMatch(ctx, m.match) stdin.WriteLine(m.write) } @@ -1018,7 +1018,7 @@ func TestTemplatePush(t *testing.T) { {match: "template has been created"}, } for _, m := range matches { - stdout.ExpectMatchContext(ctx, m.match) + stdout.ExpectMatch(ctx, m.match) if m.write != "" { stdin.WriteLine(m.write) } @@ -1115,23 +1115,23 @@ func TestTemplatePush(t *testing.T) { w := clitest.StartWithWaiter(t, inv) // Select "Yes" for the "Upload " prompt - stdout.ExpectMatchContext(ctx, "Upload") + stdout.ExpectMatch(ctx, "Upload") stdin.WriteLine("yes") // Variables are prompted in alphabetical order. // Boolean variable automatically selects the first option ("true") - stdout.ExpectMatchContext(ctx, "var.bool_var") + stdout.ExpectMatch(ctx, "var.bool_var") - stdout.ExpectMatchContext(ctx, "var.number_var") - stdout.ExpectMatchContext(ctx, "Enter value:") + stdout.ExpectMatch(ctx, "var.number_var") + stdout.ExpectMatch(ctx, "Enter value:") stdin.WriteLine("42") - stdout.ExpectMatchContext(ctx, "var.sensitive_var") - stdout.ExpectMatchContext(ctx, "Enter value:") + stdout.ExpectMatch(ctx, "var.sensitive_var") + stdout.ExpectMatch(ctx, "Enter value:") stdin.WriteLine("secret-value") - stdout.ExpectMatchContext(ctx, "var.string_var") - stdout.ExpectMatchContext(ctx, "Enter value:") + stdout.ExpectMatch(ctx, "var.string_var") + stdout.ExpectMatch(ctx, "Enter value:") stdin.WriteLine("test-string") w.RequireSuccess() @@ -1164,13 +1164,13 @@ func TestTemplatePush(t *testing.T) { w := clitest.StartWithWaiter(t, inv) // Select "Yes" for the "Upload " prompt - stdout.ExpectMatchContext(ctx, "Upload") + stdout.ExpectMatch(ctx, "Upload") stdin.WriteLine("yes") - stdout.ExpectMatchContext(ctx, "var.number_var") + stdout.ExpectMatch(ctx, "var.number_var") stdin.WriteLine("not-a-number") - stdout.ExpectMatchContext(ctx, "must be a valid number") + stdout.ExpectMatch(ctx, "must be a valid number") stdin.WriteLine("123.45") @@ -1209,10 +1209,10 @@ func TestTemplatePush(t *testing.T) { w := clitest.StartWithWaiter(t, inv) // Select "Yes" for the "Upload " prompt - stdout.ExpectMatchContext(ctx, "Upload") + stdout.ExpectMatch(ctx, "Upload") stdin.WriteLine("yes") - stdout.ExpectMatchContext(ctx, "var.without_default") + stdout.ExpectMatch(ctx, "var.without_default") stdin.WriteLine("test-value") w.RequireSuccess() @@ -1280,12 +1280,12 @@ cli_overrides_file_var: from-file`) w := clitest.StartWithWaiter(t, inv) // Select "Yes" for the "Upload " prompt - stdout.ExpectMatchContext(ctx, "Upload") + stdout.ExpectMatch(ctx, "Upload") stdin.WriteLine("yes") // Only check for prompt_var, other variables should not prompt - stdout.ExpectMatchContext(ctx, "var.prompt_var") - stdout.ExpectMatchContext(ctx, "Enter value:") + stdout.ExpectMatch(ctx, "var.prompt_var") + stdout.ExpectMatch(ctx, "Enter value:") stdin.WriteLine("from-prompt") w.RequireSuccess() diff --git a/cli/templateversions_test.go b/cli/templateversions_test.go index 732055f633..ce3a3782a2 100644 --- a/cli/templateversions_test.go +++ b/cli/templateversions_test.go @@ -40,9 +40,9 @@ func TestTemplateVersions(t *testing.T) { require.NoError(t, <-errC) - stdout.ExpectMatchContext(ctx, version.Name) - stdout.ExpectMatchContext(ctx, version.CreatedBy.Username) - stdout.ExpectMatchContext(ctx, "Active") + stdout.ExpectMatch(ctx, version.Name) + stdout.ExpectMatch(ctx, version.CreatedBy.Username) + stdout.ExpectMatch(ctx, "Active") }) t.Run("ListVersionsJSON", func(t *testing.T) { diff --git a/cli/update_test.go b/cli/update_test.go index f5287bbdf5..d52a125655 100644 --- a/cli/update_test.go +++ b/cli/update_test.go @@ -273,7 +273,7 @@ func TestUpdateWithRichParameters(t *testing.T) { for i := 0; i < len(matches); i += 2 { match := matches[i] value := matches[i+1] - stdout.ExpectMatchContext(ctx, match) + stdout.ExpectMatch(ctx, match) if value != "" { stdin.WriteLine(value) } @@ -328,7 +328,7 @@ func TestUpdateWithRichParameters(t *testing.T) { for i := 0; i < len(matches); i += 2 { match := matches[i] value := matches[i+1] - stdout.ExpectMatchContext(ctx, match) + stdout.ExpectMatch(ctx, match) if value != "" { stdin.WriteLine(value) } @@ -383,7 +383,7 @@ func TestUpdateWithRichParameters(t *testing.T) { assert.NoError(t, err) }() - stdout.ExpectMatchContext(ctx, "Planning workspace") + stdout.ExpectMatch(ctx, "Planning workspace") <-doneChan // Verify if ephemeral parameter is set @@ -462,14 +462,14 @@ func TestUpdateValidateRichParameters(t *testing.T) { assert.NoError(t, err) }() - stdout.ExpectMatchContext(ctx, stringParameterName) - stdout.ExpectMatchContext(ctx, "> Enter a value: ") + stdout.ExpectMatch(ctx, stringParameterName) + stdout.ExpectMatch(ctx, "> Enter a value: ") stdin.WriteLine("$$") - stdout.ExpectMatchContext(ctx, "does not match") - stdout.ExpectMatchContext(ctx, "> Enter a value: ") + stdout.ExpectMatch(ctx, "does not match") + stdout.ExpectMatch(ctx, "> Enter a value: ") stdin.WriteLine("ABC") - stdout.ExpectMatchContext(ctx, "does not match") - stdout.ExpectMatchContext(ctx, "> Enter a value: ") + stdout.ExpectMatch(ctx, "does not match") + stdout.ExpectMatch(ctx, "> Enter a value: ") stdin.WriteLine("abc") _ = testutil.TryReceive(ctx, t, doneChan) }) @@ -510,14 +510,14 @@ func TestUpdateValidateRichParameters(t *testing.T) { assert.NoError(t, err) }() - stdout.ExpectMatchContext(ctx, numberParameterName) - stdout.ExpectMatchContext(ctx, "> Enter a value: ") + stdout.ExpectMatch(ctx, numberParameterName) + stdout.ExpectMatch(ctx, "> Enter a value: ") stdin.WriteLine("12") - stdout.ExpectMatchContext(ctx, "is more than the maximum") - stdout.ExpectMatchContext(ctx, "> Enter a value: ") + stdout.ExpectMatch(ctx, "is more than the maximum") + stdout.ExpectMatch(ctx, "> Enter a value: ") stdin.WriteLine("notanumber") - stdout.ExpectMatchContext(ctx, "is not a number") - stdout.ExpectMatchContext(ctx, "> Enter a value: ") + stdout.ExpectMatch(ctx, "is not a number") + stdout.ExpectMatch(ctx, "> Enter a value: ") stdin.WriteLine("8") _ = testutil.TryReceive(ctx, t, doneChan) }) @@ -558,14 +558,14 @@ func TestUpdateValidateRichParameters(t *testing.T) { assert.NoError(t, err) }() - stdout.ExpectMatchContext(ctx, boolParameterName) - stdout.ExpectMatchContext(ctx, "> Enter a value: ") + stdout.ExpectMatch(ctx, boolParameterName) + stdout.ExpectMatch(ctx, "> Enter a value: ") stdin.WriteLine("cat") - stdout.ExpectMatchContext(ctx, "boolean value can be either \"true\" or \"false\"") - stdout.ExpectMatchContext(ctx, "> Enter a value: ") + stdout.ExpectMatch(ctx, "boolean value can be either \"true\" or \"false\"") + stdout.ExpectMatch(ctx, "> Enter a value: ") stdin.WriteLine("dog") - stdout.ExpectMatchContext(ctx, "boolean value can be either \"true\" or \"false\"") - stdout.ExpectMatchContext(ctx, "> Enter a value: ") + stdout.ExpectMatch(ctx, "boolean value can be either \"true\" or \"false\"") + stdout.ExpectMatch(ctx, "> Enter a value: ") stdin.WriteLine("false") _ = testutil.TryReceive(ctx, t, doneChan) }) @@ -634,7 +634,7 @@ func TestUpdateValidateRichParameters(t *testing.T) { for i := 0; i < len(matches); i += 2 { match := matches[i] value := matches[i+1] - stdout.ExpectMatchContext(ctx, match) + stdout.ExpectMatch(ctx, match) if value != "" { stdin.WriteLine(value) @@ -699,7 +699,7 @@ func TestUpdateValidateRichParameters(t *testing.T) { assert.NoError(t, err) }() - stdout.ExpectMatchContext(ctx, "Planning workspace...") + stdout.ExpectMatch(ctx, "Planning workspace...") _ = testutil.TryReceive(ctx, t, doneChan) }) @@ -798,7 +798,7 @@ func TestUpdateValidateRichParameters(t *testing.T) { for i := 0; i < len(matches); i += 2 { match := matches[i] value := matches[i+1] - stdout.ExpectMatchContext(ctx, match) + stdout.ExpectMatch(ctx, match) if value != "" { stdin.WriteLine(value) @@ -862,7 +862,7 @@ func TestUpdateValidateRichParameters(t *testing.T) { } for i := 0; i < len(matches); i += 2 { match := matches[i] - stdout.ExpectMatchContext(ctx, match) + stdout.ExpectMatch(ctx, match) } _ = testutil.TryReceive(ctx, t, doneChan) @@ -928,7 +928,7 @@ func TestUpdateValidateRichParameters(t *testing.T) { for i := 0; i < len(matches); i += 2 { match := matches[i] value := matches[i+1] - stdout.ExpectMatchContext(ctx, match) + stdout.ExpectMatch(ctx, match) if value != "" { stdin.WriteLine(value) @@ -1002,7 +1002,7 @@ func TestUpdateValidateRichParameters(t *testing.T) { for i := 0; i < len(matches); i += 2 { match := matches[i] value := matches[i+1] - stdout.ExpectMatchContext(ctx, match) + stdout.ExpectMatch(ctx, match) if value != "" { stdin.WriteLine(value) @@ -1067,7 +1067,7 @@ func TestUpdateValidateRichParameters(t *testing.T) { assert.NoError(t, err) }() - stdout.ExpectMatchContext(ctx, "Planning workspace") + stdout.ExpectMatch(ctx, "Planning workspace") _ = testutil.TryReceive(ctx, t, doneChan) diff --git a/cli/user_delete_test.go b/cli/user_delete_test.go index a835268021..24adcb25f6 100644 --- a/cli/user_delete_test.go +++ b/cli/user_delete_test.go @@ -44,7 +44,7 @@ func TestUserDelete(t *testing.T) { errC <- inv.Run() }() require.NoError(t, <-errC) - stdout.ExpectMatchContext(ctx, "coolin") + stdout.ExpectMatch(ctx, "coolin") }) t.Run("UserID", func(t *testing.T) { @@ -74,7 +74,7 @@ func TestUserDelete(t *testing.T) { errC <- inv.Run() }() require.NoError(t, <-errC) - stdout.ExpectMatchContext(ctx, "coolin") + stdout.ExpectMatch(ctx, "coolin") }) t.Run("UserID", func(t *testing.T) { @@ -104,7 +104,7 @@ func TestUserDelete(t *testing.T) { errC <- inv.Run() }() require.NoError(t, <-errC) - stdout.ExpectMatchContext(ctx, "coolin") + stdout.ExpectMatch(ctx, "coolin") }) // TODO: reenable this test case. Fetching users without perms returns a diff --git a/cli/usercreate_test.go b/cli/usercreate_test.go index d06a76f8a9..7453d37123 100644 --- a/cli/usercreate_test.go +++ b/cli/usercreate_test.go @@ -39,7 +39,7 @@ func TestUserCreate(t *testing.T) { for i := 0; i < len(matches); i += 2 { match := matches[i] value := matches[i+1] - stdout.ExpectMatchContext(ctx, match) + stdout.ExpectMatch(ctx, match) stdin.WriteLine(value) } _ = testutil.TryReceive(ctx, t, doneChan) @@ -74,7 +74,7 @@ func TestUserCreate(t *testing.T) { for i := 0; i < len(matches); i += 2 { match := matches[i] value := matches[i+1] - stdout.ExpectMatchContext(ctx, match) + stdout.ExpectMatch(ctx, match) stdin.WriteLine(value) } _ = testutil.TryReceive(ctx, t, doneChan) diff --git a/cli/userlist_test.go b/cli/userlist_test.go index d595a580fa..3ee18faa36 100644 --- a/cli/userlist_test.go +++ b/cli/userlist_test.go @@ -35,7 +35,7 @@ func TestUserList(t *testing.T) { errC <- inv.Run() }() require.NoError(t, <-errC) - stdout.ExpectMatchContext(ctx, "coder.com") + stdout.ExpectMatch(ctx, "coder.com") }) t.Run("JSON", func(t *testing.T) { t.Parallel() @@ -114,7 +114,7 @@ func TestUserShow(t *testing.T) { err := inv.Run() assert.NoError(t, err) }() - stdout.ExpectMatchContext(ctx, otherUser.Email) + stdout.ExpectMatch(ctx, otherUser.Email) <-doneChan }) diff --git a/enterprise/cli/create_test.go b/enterprise/cli/create_test.go index 21ef591b72..94a04a5501 100644 --- a/enterprise/cli/create_test.go +++ b/enterprise/cli/create_test.go @@ -450,9 +450,9 @@ func TestEnterpriseCreateWithPreset(t *testing.T) { // Should: display the selected preset as well as its parameters presetName := fmt.Sprintf("Preset '%s' applied:", preset.Name) - stdout.ExpectMatchContext(ctx, presetName) - stdout.ExpectMatchContext(ctx, fmt.Sprintf("%s: '%s'", firstParameterName, secondOptionalParameterValue)) - stdout.ExpectMatchContext(ctx, fmt.Sprintf("%s: '%s'", thirdParameterName, thirdParameterValue)) + stdout.ExpectMatch(ctx, presetName) + stdout.ExpectMatch(ctx, fmt.Sprintf("%s: '%s'", firstParameterName, secondOptionalParameterValue)) + stdout.ExpectMatch(ctx, fmt.Sprintf("%s: '%s'", thirdParameterName, thirdParameterValue)) // Verify if the new workspace uses expected parameters. ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort) @@ -561,7 +561,7 @@ func TestEnterpriseCreateWithPreset(t *testing.T) { stdout := expecter.NewAttachedToInvocation(t, inv) err = inv.Run() require.NoError(t, err) - stdout.ExpectMatchContext(ctx, "No preset applied.") + stdout.ExpectMatch(ctx, "No preset applied.") // Verify if the new workspace uses expected parameters. ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort) diff --git a/enterprise/cli/externalworkspaces_test.go b/enterprise/cli/externalworkspaces_test.go index 9efdd4e349..00a334ca3d 100644 --- a/enterprise/cli/externalworkspaces_test.go +++ b/enterprise/cli/externalworkspaces_test.go @@ -117,14 +117,14 @@ func TestExternalWorkspaces(t *testing.T) { }() // Expect the workspace creation confirmation - stdout.ExpectMatchContext(ctx, "coder_external_agent.main") - stdout.ExpectMatchContext(ctx, "external-agent (linux, amd64)") - stdout.ExpectMatchContext(ctx, "Confirm create") + stdout.ExpectMatch(ctx, "coder_external_agent.main") + stdout.ExpectMatch(ctx, "external-agent (linux, amd64)") + stdout.ExpectMatch(ctx, "Confirm create") stdin.WriteLine("yes") // Expect the external agent instructions - stdout.ExpectMatchContext(ctx, "Please run the following command to attach external agent") - stdout.ExpectRegexMatchContext(ctx, "curl -fsSL .* | CODER_AGENT_TOKEN=.* sh") + stdout.ExpectMatch(ctx, "Please run the following command to attach external agent") + stdout.ExpectRegexMatch(ctx, "curl -fsSL .* | CODER_AGENT_TOKEN=.* sh") testutil.TryReceive(ctx, t, doneChan) @@ -229,8 +229,8 @@ func TestExternalWorkspaces(t *testing.T) { assert.NoError(t, errC) close(done) }() - stdout.ExpectMatchContext(ctx, ws.Name) - stdout.ExpectMatchContext(ctx, template.Name) + stdout.ExpectMatch(ctx, ws.Name) + stdout.ExpectMatch(ctx, template.Name) cancelFunc() <-done }) @@ -308,8 +308,8 @@ func TestExternalWorkspaces(t *testing.T) { assert.NoError(t, errC) close(done) }() - stdout.ExpectMatchContext(ctx, "No workspaces found!") - stdout.ExpectMatchContext(ctx, "coder external-workspaces create") + stdout.ExpectMatch(ctx, "No workspaces found!") + stdout.ExpectMatch(ctx, "coder external-workspaces create") cancelFunc() <-done }) @@ -352,8 +352,8 @@ func TestExternalWorkspaces(t *testing.T) { assert.NoError(t, errC) close(done) }() - stdout.ExpectMatchContext(ctx, "Please run the following command to attach external agent to the workspace") - stdout.ExpectRegexMatchContext(ctx, "curl -fsSL .* | CODER_AGENT_TOKEN=.* sh") + stdout.ExpectMatch(ctx, "Please run the following command to attach external agent to the workspace") + stdout.ExpectRegexMatch(ctx, "curl -fsSL .* | CODER_AGENT_TOKEN=.* sh") cancelFunc() ctx = testutil.Context(t, testutil.WaitLong) @@ -503,12 +503,12 @@ func TestExternalWorkspaces(t *testing.T) { }() // Expect the workspace creation confirmation - stdout.ExpectMatchContext(ctx, "coder_external_agent.main") - stdout.ExpectMatchContext(ctx, "external-agent (linux, amd64)") + stdout.ExpectMatch(ctx, "coder_external_agent.main") + stdout.ExpectMatch(ctx, "external-agent (linux, amd64)") // Expect the external agent instructions - stdout.ExpectMatchContext(ctx, "Please run the following command to attach external agent") - stdout.ExpectRegexMatchContext(ctx, "curl -fsSL .* | CODER_AGENT_TOKEN=.* sh") + stdout.ExpectMatch(ctx, "Please run the following command to attach external agent") + stdout.ExpectRegexMatch(ctx, "curl -fsSL .* | CODER_AGENT_TOKEN=.* sh") testutil.TryReceive(ctx, t, doneChan) diff --git a/enterprise/cli/features_test.go b/enterprise/cli/features_test.go index 472bd863cb..5b227d0bf3 100644 --- a/enterprise/cli/features_test.go +++ b/enterprise/cli/features_test.go @@ -27,8 +27,8 @@ func TestFeaturesList(t *testing.T) { clitest.SetupConfig(t, anotherClient, conf) stdout := expecter.NewAttachedToInvocation(t, inv) clitest.Start(t, inv) - stdout.ExpectMatchContext(ctx, "user_limit") - stdout.ExpectMatchContext(ctx, "not_entitled") + stdout.ExpectMatch(ctx, "user_limit") + stdout.ExpectMatch(ctx, "not_entitled") }) t.Run("JSON", func(t *testing.T) { t.Parallel() diff --git a/enterprise/cli/groupcreate_test.go b/enterprise/cli/groupcreate_test.go index 84adaca77a..923bd5d5e4 100644 --- a/enterprise/cli/groupcreate_test.go +++ b/enterprise/cli/groupcreate_test.go @@ -48,6 +48,6 @@ func TestCreateGroup(t *testing.T) { err := inv.Run() require.NoError(t, err) - stdout.ExpectMatchContext(ctx, fmt.Sprintf("Successfully created group %s!", pretty.Sprint(cliui.DefaultStyles.Keyword, groupName))) + stdout.ExpectMatch(ctx, fmt.Sprintf("Successfully created group %s!", pretty.Sprint(cliui.DefaultStyles.Keyword, groupName))) }) } diff --git a/enterprise/cli/groupdelete_test.go b/enterprise/cli/groupdelete_test.go index ef5670bea8..cd4a3942d9 100644 --- a/enterprise/cli/groupdelete_test.go +++ b/enterprise/cli/groupdelete_test.go @@ -44,7 +44,7 @@ func TestGroupDelete(t *testing.T) { err := inv.Run() require.NoError(t, err) - stdout.ExpectMatchContext(ctx, fmt.Sprintf("Successfully deleted group %s", pretty.Sprint(cliui.DefaultStyles.Keyword, group.Name))) + stdout.ExpectMatch(ctx, fmt.Sprintf("Successfully deleted group %s", pretty.Sprint(cliui.DefaultStyles.Keyword, group.Name))) }) t.Run("NoArg", func(t *testing.T) { diff --git a/enterprise/cli/groupedit_test.go b/enterprise/cli/groupedit_test.go index defcd0f5b9..e7969ed07d 100644 --- a/enterprise/cli/groupedit_test.go +++ b/enterprise/cli/groupedit_test.go @@ -56,7 +56,7 @@ func TestGroupEdit(t *testing.T) { err := inv.Run() require.NoError(t, err) - stdout.ExpectMatchContext(ctx, fmt.Sprintf("Successfully patched group %s", pretty.Sprint(cliui.DefaultStyles.Keyword, expectedName))) + stdout.ExpectMatch(ctx, fmt.Sprintf("Successfully patched group %s", pretty.Sprint(cliui.DefaultStyles.Keyword, expectedName))) }) t.Run("InvalidUserInput", func(t *testing.T) { diff --git a/enterprise/cli/grouplist_test.go b/enterprise/cli/grouplist_test.go index a92f9e99d2..13f075e033 100644 --- a/enterprise/cli/grouplist_test.go +++ b/enterprise/cli/grouplist_test.go @@ -55,7 +55,7 @@ func TestGroupList(t *testing.T) { } for _, match := range matches { - stdout.ExpectMatchContext(ctx, match) + stdout.ExpectMatch(ctx, match) } }) @@ -84,7 +84,7 @@ func TestGroupList(t *testing.T) { } for _, match := range matches { - stdout.ExpectMatchContext(ctx, match) + stdout.ExpectMatch(ctx, match) } }) diff --git a/enterprise/cli/licenses_test.go b/enterprise/cli/licenses_test.go index b3b2199dd0..bed9108617 100644 --- a/enterprise/cli/licenses_test.go +++ b/enterprise/cli/licenses_test.go @@ -40,7 +40,7 @@ func TestLicensesAddFake(t *testing.T) { stdout := expecter.NewAttachedToInvocation(t, inv) clitest.Start(t, inv) ctx := testutil.Context(t, testutil.WaitMedium) - stdout.ExpectMatchContext(ctx, "License with ID 1 added") + stdout.ExpectMatch(ctx, "License with ID 1 added") }) t.Run("Prompt", func(t *testing.T) { t.Parallel() @@ -53,10 +53,10 @@ func TestLicensesAddFake(t *testing.T) { go func() { errC <- inv.WithContext(ctx).Run() }() - stdout.ExpectMatchContext(ctx, "Paste license:") + stdout.ExpectMatch(ctx, "Paste license:") stdin.WriteLine(fakeLicenseJWT) require.NoError(t, <-errC) - stdout.ExpectMatchContext(ctx, "License with ID 1 added") + stdout.ExpectMatch(ctx, "License with ID 1 added") }) t.Run("File", func(t *testing.T) { t.Parallel() @@ -72,7 +72,7 @@ func TestLicensesAddFake(t *testing.T) { errC <- inv.WithContext(ctx).Run() }() require.NoError(t, <-errC) - stdout.ExpectMatchContext(ctx, "License with ID 1 added") + stdout.ExpectMatch(ctx, "License with ID 1 added") }) t.Run("StdIn", func(t *testing.T) { t.Parallel() @@ -109,7 +109,7 @@ func TestLicensesAddFake(t *testing.T) { errC <- inv.WithContext(ctx).Run() }() require.NoError(t, <-errC) - stdout.ExpectMatchContext(ctx, "\"f2\": 2") + stdout.ExpectMatch(ctx, "\"f2\": 2") }) } @@ -205,7 +205,7 @@ func TestLicensesDeleteFake(t *testing.T) { clitest.Start(t, inv) ctx := testutil.Context(t, testutil.WaitMedium) - stdout.ExpectMatchContext(ctx, "License with ID 55 deleted") + stdout.ExpectMatch(ctx, "License with ID 55 deleted") }) } diff --git a/enterprise/cli/organization_test.go b/enterprise/cli/organization_test.go index 56115db26b..3a7f75350f 100644 --- a/enterprise/cli/organization_test.go +++ b/enterprise/cli/organization_test.go @@ -144,7 +144,7 @@ func TestShowOrganizations(t *testing.T) { errC <- inv.Run() }() require.NoError(t, <-errC) - stdout.ExpectMatchContext(ctx, first.OrganizationID.String()) + stdout.ExpectMatch(ctx, first.OrganizationID.String()) }) t.Run("UsingFlag", func(t *testing.T) { @@ -185,7 +185,7 @@ func TestShowOrganizations(t *testing.T) { errC <- inv.Run() }() require.NoError(t, <-errC) - stdout.ExpectMatchContext(ctx, orgs["bar"].ID.String()) + stdout.ExpectMatch(ctx, orgs["bar"].ID.String()) }) } diff --git a/enterprise/cli/prebuilds_test.go b/enterprise/cli/prebuilds_test.go index 14856c0a02..51881b8155 100644 --- a/enterprise/cli/prebuilds_test.go +++ b/enterprise/cli/prebuilds_test.go @@ -483,7 +483,7 @@ func TestSchedulePrebuilds(t *testing.T) { require.NoError(t, inv.Run()) // Then: the updated schedule should be shown - stdout.ExpectMatchContext(ctx, workspace.OwnerName+"/"+workspace.Name) + stdout.ExpectMatch(ctx, workspace.OwnerName+"/"+workspace.Name) }) } } diff --git a/enterprise/cli/provisionerdaemonstart_test.go b/enterprise/cli/provisionerdaemonstart_test.go index 40cdce82be..5078cd80f9 100644 --- a/enterprise/cli/provisionerdaemonstart_test.go +++ b/enterprise/cli/provisionerdaemonstart_test.go @@ -47,7 +47,7 @@ func TestProvisionerDaemon_PSK(t *testing.T) { defer cancel() clitest.Start(t, inv) stdout.ExpectNoMatchBefore(ctx, "check entitlement", "starting provisioner daemon") - stdout.ExpectMatchContext(ctx, "matt-daemon") + stdout.ExpectMatch(ctx, "matt-daemon") var daemons []codersdk.ProvisionerDaemon require.Eventually(t, func() bool { @@ -82,7 +82,7 @@ func TestProvisionerDaemon_PSK(t *testing.T) { ctx, cancel := context.WithTimeout(inv.Context(), testutil.WaitLong) defer cancel() clitest.Start(t, inv) - stdout.ExpectMatchContext(ctx, "starting provisioner daemon") + stdout.ExpectMatch(ctx, "starting provisioner daemon") }) t.Run("NoUserNoPSK", func(t *testing.T) { @@ -124,7 +124,7 @@ func TestProvisionerDaemon_SessionToken(t *testing.T) { ctx, cancel := context.WithTimeout(inv.Context(), testutil.WaitLong) defer cancel() clitest.Start(t, inv) - stdout.ExpectMatchContext(ctx, "starting provisioner daemon") + stdout.ExpectMatch(ctx, "starting provisioner daemon") var daemons []codersdk.ProvisionerDaemon var err error @@ -159,7 +159,7 @@ func TestProvisionerDaemon_SessionToken(t *testing.T) { ctx, cancel := context.WithTimeout(inv.Context(), testutil.WaitLong) defer cancel() clitest.Start(t, inv) - stdout.ExpectMatchContext(ctx, "starting provisioner daemon") + stdout.ExpectMatch(ctx, "starting provisioner daemon") var daemons []codersdk.ProvisionerDaemon var err error @@ -195,7 +195,7 @@ func TestProvisionerDaemon_SessionToken(t *testing.T) { ctx, cancel := context.WithTimeout(inv.Context(), testutil.WaitLong) defer cancel() clitest.Start(t, inv) - stdout.ExpectMatchContext(ctx, "starting provisioner daemon") + stdout.ExpectMatch(ctx, "starting provisioner daemon") var daemons []codersdk.ProvisionerDaemon var err error @@ -231,7 +231,7 @@ func TestProvisionerDaemon_SessionToken(t *testing.T) { ctx, cancel := context.WithTimeout(inv.Context(), testutil.WaitLong) defer cancel() clitest.Start(t, inv) - stdout.ExpectMatchContext(ctx, "starting provisioner daemon") + stdout.ExpectMatch(ctx, "starting provisioner daemon") var daemons []codersdk.ProvisionerDaemon var err error @@ -278,7 +278,7 @@ func TestProvisionerDaemon_ProvisionerKey(t *testing.T) { stdout := expecter.NewAttachedToInvocation(t, inv) clitest.Start(t, inv) stdout.ExpectNoMatchBefore(ctx, "check entitlement", "starting provisioner daemon") - stdout.ExpectMatchContext(ctx, "matt-daemon") + stdout.ExpectMatch(ctx, "matt-daemon") var daemons []codersdk.ProvisionerDaemon require.Eventually(t, func() bool { @@ -323,7 +323,7 @@ func TestProvisionerDaemon_ProvisionerKey(t *testing.T) { stdout := expecter.NewAttachedToInvocation(t, inv) clitest.Start(t, inv) stdout.ExpectNoMatchBefore(ctx, "check entitlement", "starting provisioner daemon") - stdout.ExpectMatchContext(ctx, `tags={"tag1":"value1","tag2":"value2"}`) + stdout.ExpectMatch(ctx, `tags={"tag1":"value1","tag2":"value2"}`) var daemons []codersdk.ProvisionerDaemon require.Eventually(t, func() bool { @@ -439,7 +439,7 @@ func TestProvisionerDaemon_ProvisionerKey(t *testing.T) { stdout := expecter.NewAttachedToInvocation(t, inv) clitest.Start(t, inv) stdout.ExpectNoMatchBefore(ctx, "check entitlement", "starting provisioner daemon") - stdout.ExpectMatchContext(ctx, "matt-daemon") + stdout.ExpectMatch(ctx, "matt-daemon") var daemons []codersdk.ProvisionerDaemon require.Eventually(t, func() bool { daemons, err = client.OrganizationProvisionerDaemons(ctx, anotherOrg.ID, nil) @@ -479,7 +479,7 @@ func TestProvisionerDaemon_PrometheusEnabled(t *testing.T) { // Start "provisionerd" command clitest.Start(t, inv) - stdout.ExpectMatchContext(ctx, "starting provisioner daemon") + stdout.ExpectMatch(ctx, "starting provisioner daemon") var daemons []codersdk.ProvisionerDaemon var err error diff --git a/enterprise/cli/proxyserver_test.go b/enterprise/cli/proxyserver_test.go index a6987ff65b..3861dcf785 100644 --- a/enterprise/cli/proxyserver_test.go +++ b/enterprise/cli/proxyserver_test.go @@ -107,7 +107,7 @@ func TestWorkspaceProxy_Server_PrometheusEnabled(t *testing.T) { clitest.StartWithAssert(t, inv, func(t *testing.T, err error) { // actually no assertions are needed as the test verifies only Prometheus endpoint }) - stdout.ExpectMatchContext(ctx, "Started HTTP listener at") + stdout.ExpectMatch(ctx, "Started HTTP listener at") // Fetch metrics from Prometheus endpoint var res *http.Response diff --git a/enterprise/cli/workspaceproxy_test.go b/enterprise/cli/workspaceproxy_test.go index ea84ab6224..3b6c0e3c79 100644 --- a/enterprise/cli/workspaceproxy_test.go +++ b/enterprise/cli/workspaceproxy_test.go @@ -64,7 +64,7 @@ func Test_ProxyCRUD(t *testing.T) { err = inv.WithContext(ctx).Run() require.NoError(t, err) - stdout.ExpectMatchContext(ctx, expectedName) + stdout.ExpectMatch(ctx, expectedName) // Also check via the api proxies, err := client.WorkspaceProxies(ctx) //nolint:gocritic // requires owner diff --git a/pty/ptytest/ptytest_test.go b/pty/ptytest/ptytest_test.go index 29011ba9e7..b6959d878c 100644 --- a/pty/ptytest/ptytest_test.go +++ b/pty/ptytest/ptytest_test.go @@ -17,9 +17,10 @@ func TestPtytest(t *testing.T) { t.Parallel() t.Run("Echo", func(t *testing.T) { t.Parallel() + ctx := testutil.Context(t, testutil.WaitMedium) pty := ptytest.New(t) pty.Output().Write([]byte("write")) - pty.ExpectMatch("write") + pty.ExpectMatch(ctx, "write") pty.WriteLine("read") }) @@ -38,7 +39,7 @@ func TestPtytest(t *testing.T) { require.Equal(t, "line 2", pty.ReadLine(ctx)) require.Equal(t, "line 3", pty.ReadLine(ctx)) require.Equal(t, "line 4", pty.ReadLine(ctx)) - require.Equal(t, "line 5", pty.ExpectMatch("5")) + require.Equal(t, "line 5", pty.ExpectMatch(ctx, "5")) }) // See https://github.com/coder/coder/issues/2122 for the motivation diff --git a/pty/start_other_test.go b/pty/start_other_test.go index 77c7dad15c..88438be869 100644 --- a/pty/start_other_test.go +++ b/pty/start_other_test.go @@ -26,9 +26,10 @@ func TestStart(t *testing.T) { t.Parallel() t.Run("Echo", func(t *testing.T) { t.Parallel() + ctx := testutil.Context(t, testutil.WaitMedium) pty, ps := ptytest.Start(t, pty.Command("echo", "test")) - pty.ExpectMatch("test") + pty.ExpectMatch(ctx, "test") err := ps.Wait() require.NoError(t, err) err = pty.Close() @@ -63,6 +64,7 @@ func TestStart(t *testing.T) { t.Run("SSH_TTY", func(t *testing.T) { t.Parallel() + ctx := testutil.Context(t, testutil.WaitMedium) opts := pty.WithPTYOption(pty.WithSSHRequest(ssh.Pty{ Window: ssh.Window{ Width: 80, @@ -70,7 +72,7 @@ func TestStart(t *testing.T) { }, })) pty, ps := ptytest.Start(t, pty.Command(`/bin/sh`, `-c`, `env | grep SSH_TTY`), opts) - pty.ExpectMatch("SSH_TTY=/dev/") + pty.ExpectMatch(ctx, "SSH_TTY=/dev/") err := ps.Wait() require.NoError(t, err) err = pty.Close() diff --git a/pty/start_windows_test.go b/pty/start_windows_test.go index a067a98691..015347434b 100644 --- a/pty/start_windows_test.go +++ b/pty/start_windows_test.go @@ -27,8 +27,9 @@ func TestStart(t *testing.T) { t.Parallel() t.Run("Echo", func(t *testing.T) { t.Parallel() + ctx := testutil.Context(t, testutil.WaitMedium) ptty, ps := ptytest.Start(t, pty.Command("cmd.exe", "/c", "echo", "test")) - ptty.ExpectMatch("test") + ptty.ExpectMatch(ctx, "test") err := ps.Wait() require.NoError(t, err) err = ptty.Close() diff --git a/testutil/expecter/expecter.go b/testutil/expecter/expecter.go index 44b5298fc6..bbcbdb5b21 100644 --- a/testutil/expecter/expecter.go +++ b/testutil/expecter/expecter.go @@ -145,31 +145,11 @@ func (e *Expecter) logClose(name string, c io.Closer) { e.Logf("closed %s: %v", name, err) } -// Deprecated: use ExpectMatchContext instead. -// This uses a background context, so will not respect the test's context. -func (e *Expecter) ExpectMatch(str string) string { - return e.expectMatchContextFunc(str, e.ExpectMatchContext) -} - -func (e *Expecter) ExpectRegexMatch(str string) string { - return e.expectMatchContextFunc(str, e.ExpectRegexMatchContext) -} - -func (e *Expecter) expectMatchContextFunc(str string, fn func(ctx context.Context, str string) string) string { - e.t.Helper() - - timeout, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium) - defer cancel() - - return fn(timeout, str) -} - -// TODO(mafredri): Rename this to ExpectMatch when refactoring. -func (e *Expecter) ExpectMatchContext(ctx context.Context, str string) string { +func (e *Expecter) ExpectMatch(ctx context.Context, str string) string { return e.expectMatcherFunc(ctx, str, strings.Contains) } -func (e *Expecter) ExpectRegexMatchContext(ctx context.Context, str string) string { +func (e *Expecter) ExpectRegexMatch(ctx context.Context, str string) string { return e.expectMatcherFunc(ctx, str, func(src, pattern string) bool { return regexp.MustCompile(pattern).MatchString(src) })