Skip to content

Commit 32a1759

Browse files
committed
330 problems left...
* RunContext -> WithContext * Stdin/Stdout wiring
1 parent c9820fb commit 32a1759

34 files changed

+201
-201
lines changed

cli/cliui/agent_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func TestAgent_TimeoutWithTroubleshootingURL(t *testing.T) {
9696
cmd.SetIn(ptty.Input())
9797
done := make(chan error, 1)
9898
go func() {
99-
done <- cmd.RunContext(ctx)
99+
done <- cmd.WithContext(ctx).Run()
100100
}()
101101
ptty.ExpectMatchContext(ctx, "Don't panic, your workspace is booting")
102102
timeout.Store(true)
@@ -149,7 +149,7 @@ func TestAgent_StartupTimeout(t *testing.T) {
149149
cmd.SetIn(ptty.Input())
150150
done := make(chan error, 1)
151151
go func() {
152-
done <- cmd.RunContext(ctx)
152+
done <- cmd.WithContext(ctx).Run()
153153
}()
154154
setStatus(codersdk.WorkspaceAgentConnecting)
155155
ptty.ExpectMatchContext(ctx, "Don't panic, your workspace is booting")
@@ -207,7 +207,7 @@ func TestAgent_StartErrorExit(t *testing.T) {
207207
cmd.SetIn(ptty.Input())
208208
done := make(chan error, 1)
209209
go func() {
210-
done <- cmd.RunContext(ctx)
210+
done <- cmd.WithContext(ctx).Run()
211211
}()
212212
setStatus(codersdk.WorkspaceAgentConnected)
213213
setState(codersdk.WorkspaceAgentLifecycleStarting)
@@ -262,7 +262,7 @@ func TestAgent_NoWait(t *testing.T) {
262262
cmd.SetIn(ptty.Input())
263263
done := make(chan error, 1)
264264
go func() {
265-
done <- cmd.RunContext(ctx)
265+
done <- cmd.WithContext(ctx).Run()
266266
}()
267267
setStatus(codersdk.WorkspaceAgentConnecting)
268268
ptty.ExpectMatchContext(ctx, "Don't panic, your workspace is booting")
@@ -271,19 +271,19 @@ func TestAgent_NoWait(t *testing.T) {
271271
require.NoError(t, <-done, "created - should exit early")
272272

273273
setState(codersdk.WorkspaceAgentLifecycleStarting)
274-
go func() { done <- cmd.RunContext(ctx) }()
274+
go func() { done <- cmd.WithContext(ctx).Run() }()
275275
require.NoError(t, <-done, "starting - should exit early")
276276

277277
setState(codersdk.WorkspaceAgentLifecycleStartTimeout)
278-
go func() { done <- cmd.RunContext(ctx) }()
278+
go func() { done <- cmd.WithContext(ctx).Run() }()
279279
require.NoError(t, <-done, "start timeout - should exit early")
280280

281281
setState(codersdk.WorkspaceAgentLifecycleStartError)
282-
go func() { done <- cmd.RunContext(ctx) }()
282+
go func() { done <- cmd.WithContext(ctx).Run() }()
283283
require.NoError(t, <-done, "start error - should exit early")
284284

285285
setState(codersdk.WorkspaceAgentLifecycleReady)
286-
go func() { done <- cmd.RunContext(ctx) }()
286+
go func() { done <- cmd.WithContext(ctx).Run() }()
287287
require.NoError(t, <-done, "ready - should exit early")
288288
}
289289

@@ -331,7 +331,7 @@ func TestAgent_LoginBeforeReadyEnabled(t *testing.T) {
331331
cmd.SetIn(ptty.Input())
332332
done := make(chan error, 1)
333333
go func() {
334-
done <- cmd.RunContext(ctx)
334+
done <- cmd.WithContext(ctx).Run()
335335
}()
336336
setStatus(codersdk.WorkspaceAgentConnecting)
337337
ptty.ExpectMatchContext(ctx, "Don't panic, your workspace is booting")
@@ -340,18 +340,18 @@ func TestAgent_LoginBeforeReadyEnabled(t *testing.T) {
340340
require.NoError(t, <-done, "created - should exit early")
341341

342342
setState(codersdk.WorkspaceAgentLifecycleStarting)
343-
go func() { done <- cmd.RunContext(ctx) }()
343+
go func() { done <- cmd.WithContext(ctx).Run() }()
344344
require.NoError(t, <-done, "starting - should exit early")
345345

346346
setState(codersdk.WorkspaceAgentLifecycleStartTimeout)
347-
go func() { done <- cmd.RunContext(ctx) }()
347+
go func() { done <- cmd.WithContext(ctx).Run() }()
348348
require.NoError(t, <-done, "start timeout - should exit early")
349349

350350
setState(codersdk.WorkspaceAgentLifecycleStartError)
351-
go func() { done <- cmd.RunContext(ctx) }()
351+
go func() { done <- cmd.WithContext(ctx).Run() }()
352352
require.NoError(t, <-done, "start error - should exit early")
353353

354354
setState(codersdk.WorkspaceAgentLifecycleReady)
355-
go func() { done <- cmd.RunContext(ctx) }()
355+
go func() { done <- cmd.WithContext(ctx).Run() }()
356356
require.NoError(t, <-done, "ready - should exit early")
357357
}

cli/create_test.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ func TestCreate(t *testing.T) {
4949
clitest.SetupConfig(t, client, root)
5050
doneChan := make(chan struct{})
5151
pty := ptytest.New(t)
52-
cmd.SetIn(pty.Input())
53-
cmd.SetOut(pty.Output())
52+
cmd.Stdin = pty.Input()
53+
cmd.Stdout = pty.Output()
5454
go func() {
5555
defer close(doneChan)
5656
err := cmd.Run()
@@ -98,7 +98,7 @@ func TestCreate(t *testing.T) {
9898
cmdCtx, done := context.WithTimeout(context.Background(), testutil.WaitLong)
9999
go func() {
100100
defer done()
101-
err := cmd.RunContext(cmdCtx)
101+
err := cmd.WithContext(cmdCtx).Run()
102102
assert.NoError(t, err)
103103
}()
104104
// No pty interaction needed since we use the -y skip prompt flag
@@ -117,8 +117,8 @@ func TestCreate(t *testing.T) {
117117
clitest.SetupConfig(t, client, root)
118118
doneChan := make(chan struct{})
119119
pty := ptytest.New(t)
120-
cmd.SetIn(pty.Input())
121-
cmd.SetOut(pty.Output())
120+
cmd.Stdin = pty.Input()
121+
cmd.Stdout = pty.Output()
122122
go func() {
123123
defer close(doneChan)
124124
err := cmd.Run()
@@ -161,8 +161,8 @@ func TestCreate(t *testing.T) {
161161
clitest.SetupConfig(t, client, root)
162162
doneChan := make(chan struct{})
163163
pty := ptytest.New(t)
164-
cmd.SetIn(pty.Input())
165-
cmd.SetOut(pty.Output())
164+
cmd.Stdin = pty.Input()
165+
cmd.Stdout = pty.Output()
166166
go func() {
167167
defer close(doneChan)
168168
err := cmd.Run()
@@ -206,8 +206,8 @@ func TestCreate(t *testing.T) {
206206
clitest.SetupConfig(t, client, root)
207207
doneChan := make(chan struct{})
208208
pty := ptytest.New(t)
209-
cmd.SetIn(pty.Input())
210-
cmd.SetOut(pty.Output())
209+
cmd.Stdin = pty.Input()
210+
cmd.Stdout = pty.Output()
211211
go func() {
212212
defer close(doneChan)
213213
err := cmd.Run()
@@ -251,8 +251,8 @@ func TestCreate(t *testing.T) {
251251
clitest.SetupConfig(t, client, root)
252252
doneChan := make(chan struct{})
253253
pty := ptytest.New(t)
254-
cmd.SetIn(pty.Input())
255-
cmd.SetOut(pty.Output())
254+
cmd.Stdin = pty.Input()
255+
cmd.Stdout = pty.Output()
256256
go func() {
257257
defer close(doneChan)
258258
err := cmd.Run()
@@ -318,8 +318,8 @@ func TestCreate(t *testing.T) {
318318
cmd, root := clitest.New(t, "create", "test", "--parameter-file", parameterFile.Name())
319319
clitest.SetupConfig(t, client, root)
320320
pty := ptytest.New(t)
321-
cmd.SetIn(pty.Input())
322-
cmd.SetOut(pty.Output())
321+
cmd.Stdin = pty.Input()
322+
cmd.Stdout = pty.Output()
323323

324324
err = cmd.Run()
325325
require.Error(t, err)
@@ -380,8 +380,8 @@ func TestCreateWithRichParameters(t *testing.T) {
380380
clitest.SetupConfig(t, client, root)
381381
doneChan := make(chan struct{})
382382
pty := ptytest.New(t)
383-
cmd.SetIn(pty.Input())
384-
cmd.SetOut(pty.Output())
383+
cmd.Stdin = pty.Input()
384+
cmd.Stdout = pty.Output()
385385
go func() {
386386
defer close(doneChan)
387387
err := cmd.Run()
@@ -425,8 +425,8 @@ func TestCreateWithRichParameters(t *testing.T) {
425425

426426
doneChan := make(chan struct{})
427427
pty := ptytest.New(t)
428-
cmd.SetIn(pty.Input())
429-
cmd.SetOut(pty.Output())
428+
cmd.Stdin = pty.Input()
429+
cmd.Stdout = pty.Output()
430430
go func() {
431431
defer close(doneChan)
432432
err := cmd.Run()
@@ -508,8 +508,8 @@ func TestCreateValidateRichParameters(t *testing.T) {
508508
clitest.SetupConfig(t, client, root)
509509
doneChan := make(chan struct{})
510510
pty := ptytest.New(t)
511-
cmd.SetIn(pty.Input())
512-
cmd.SetOut(pty.Output())
511+
cmd.Stdin = pty.Input()
512+
cmd.Stdout = pty.Output()
513513
go func() {
514514
defer close(doneChan)
515515
err := cmd.Run()
@@ -545,8 +545,8 @@ func TestCreateValidateRichParameters(t *testing.T) {
545545
clitest.SetupConfig(t, client, root)
546546
doneChan := make(chan struct{})
547547
pty := ptytest.New(t)
548-
cmd.SetIn(pty.Input())
549-
cmd.SetOut(pty.Output())
548+
cmd.Stdin = pty.Input()
549+
cmd.Stdout = pty.Output()
550550
go func() {
551551
defer close(doneChan)
552552
err := cmd.Run()
@@ -585,8 +585,8 @@ func TestCreateValidateRichParameters(t *testing.T) {
585585
clitest.SetupConfig(t, client, root)
586586
doneChan := make(chan struct{})
587587
pty := ptytest.New(t)
588-
cmd.SetIn(pty.Input())
589-
cmd.SetOut(pty.Output())
588+
cmd.Stdin = pty.Input()
589+
cmd.Stdout = pty.Output()
590590
go func() {
591591
defer close(doneChan)
592592
err := cmd.Run()
@@ -647,8 +647,8 @@ func TestCreateWithGitAuth(t *testing.T) {
647647
clitest.SetupConfig(t, client, root)
648648
doneChan := make(chan struct{})
649649
pty := ptytest.New(t)
650-
cmd.SetIn(pty.Input())
651-
cmd.SetOut(pty.Output())
650+
cmd.Stdin = pty.Input()
651+
cmd.Stdout = pty.Output()
652652
go func() {
653653
defer close(doneChan)
654654
err := cmd.Run()

cli/delete_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ func TestDelete(t *testing.T) {
2929
clitest.SetupConfig(t, client, root)
3030
doneChan := make(chan struct{})
3131
pty := ptytest.New(t)
32-
cmd.SetIn(pty.Input())
33-
cmd.SetOut(pty.Output())
32+
cmd.Stdin = pty.Input()
33+
cmd.Stdout = pty.Output()
3434
go func() {
3535
defer close(doneChan)
3636
err := cmd.Run()
@@ -57,8 +57,8 @@ func TestDelete(t *testing.T) {
5757
clitest.SetupConfig(t, client, root)
5858
doneChan := make(chan struct{})
5959
pty := ptytest.New(t)
60-
cmd.SetIn(pty.Input())
61-
cmd.SetOut(pty.Output())
60+
cmd.Stdin = pty.Input()
61+
cmd.Stdout = pty.Output()
6262
cmd.SetErr(pty.Output())
6363
go func() {
6464
defer close(doneChan)
@@ -91,8 +91,8 @@ func TestDelete(t *testing.T) {
9191
clitest.SetupConfig(t, adminClient, root)
9292
doneChan := make(chan struct{})
9393
pty := ptytest.New(t)
94-
cmd.SetIn(pty.Input())
95-
cmd.SetOut(pty.Output())
94+
cmd.Stdin = pty.Input()
95+
cmd.Stdout = pty.Output()
9696
go func() {
9797
defer close(doneChan)
9898
err := cmd.Run()

cli/gitssh_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func prepareTestGitSSH(ctx context.Context, t *testing.T) (*codersdk.Client, str
7878

7979
errC := make(chan error, 1)
8080
go func() {
81-
errC <- cmd.RunContext(ctx)
81+
errC <- cmd.WithContext(ctx).Run()
8282
}()
8383
t.Cleanup(func() { require.NoError(t, <-errC) })
8484
coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
@@ -166,7 +166,7 @@ func TestGitSSH(t *testing.T) {
166166
"-o", "IdentitiesOnly=yes",
167167
"127.0.0.1",
168168
)
169-
err := cmd.RunContext(ctx)
169+
err := cmd.WithContext(ctx).Run()
170170
require.NoError(t, err)
171171
require.EqualValues(t, 1, inc)
172172

@@ -229,9 +229,9 @@ func TestGitSSH(t *testing.T) {
229229
}
230230
// Test authentication via local private key.
231231
cmd, _ := clitest.New(t, cmdArgs...)
232-
cmd.SetOut(pty.Output())
232+
cmd.Stdout = pty.Output()
233233
cmd.SetErr(pty.Output())
234-
err = cmd.RunContext(ctx)
234+
err = cmd.WithContext(ctx).Run()
235235
require.NoError(t, err)
236236
select {
237237
case key := <-authkey:
@@ -246,9 +246,9 @@ func TestGitSSH(t *testing.T) {
246246

247247
// With the local file deleted, the coder key should be used.
248248
cmd, _ = clitest.New(t, cmdArgs...)
249-
cmd.SetOut(pty.Output())
249+
cmd.Stdout = pty.Output()
250250
cmd.SetErr(pty.Output())
251-
err = cmd.RunContext(ctx)
251+
err = cmd.WithContext(ctx).Run()
252252
require.NoError(t, err)
253253
select {
254254
case key := <-authkey:

cli/list_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ func TestList(t *testing.T) {
3030
cmd, root := clitest.New(t, "ls")
3131
clitest.SetupConfig(t, client, root)
3232
pty := ptytest.New(t)
33-
cmd.SetIn(pty.Input())
34-
cmd.SetOut(pty.Output())
33+
cmd.Stdin = pty.Input()
34+
cmd.Stdout = pty.Output()
3535

3636
ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitLong)
3737
defer cancelFunc()
3838
done := make(chan any)
3939
go func() {
40-
errC := cmd.RunContext(ctx)
40+
errC := cmd.WithContext(ctx).Run()
4141
assert.NoError(t, errC)
4242
close(done)
4343
}()
@@ -65,7 +65,7 @@ func TestList(t *testing.T) {
6565

6666
out := bytes.NewBuffer(nil)
6767
cmd.SetOut(out)
68-
err := cmd.RunContext(ctx)
68+
err := cmd.WithContext(ctx).Run()
6969
require.NoError(t, err)
7070

7171
var templates []codersdk.Workspace

cli/ping_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ func TestPing(t *testing.T) {
2525
cmd, root := clitest.New(t, "ping", workspace.Name)
2626
clitest.SetupConfig(t, client, root)
2727
pty := ptytest.New(t)
28-
cmd.SetIn(pty.Input())
28+
cmd.Stdin = pty.Input()
2929
cmd.SetErr(pty.Output())
30-
cmd.SetOut(pty.Output())
30+
cmd.Stdout = pty.Output()
3131

3232
agentClient := agentsdk.New(client.URL)
3333
agentClient.SetSessionToken(agentToken)
@@ -43,7 +43,7 @@ func TestPing(t *testing.T) {
4343
defer cancel()
4444

4545
cmdDone := tGo(t, func() {
46-
err := cmd.RunContext(ctx)
46+
err := cmd.WithContext(ctx).Run()
4747
assert.NoError(t, err)
4848
})
4949

0 commit comments

Comments
 (0)