(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func TestPing(t *testing.T) { |
| 17 | t.Parallel() |
| 18 | |
| 19 | t.Run("OK", func(t *testing.T) { |
| 20 | t.Parallel() |
| 21 | |
| 22 | client, workspace, agentToken := setupWorkspaceForAgent(t) |
| 23 | inv, root := clitest.New(t, "ping", workspace.Name) |
| 24 | clitest.SetupConfig(t, client, root) |
| 25 | pty := ptytest.New(t) |
| 26 | inv.Stdin = pty.Input() |
| 27 | inv.Stderr = pty.Output() |
| 28 | inv.Stdout = pty.Output() |
| 29 | |
| 30 | _ = agenttest.New(t, client.URL, agentToken) |
| 31 | _ = coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID) |
| 32 | |
| 33 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) |
| 34 | defer cancel() |
| 35 | |
| 36 | cmdDone := tGo(t, func() { |
| 37 | err := inv.WithContext(ctx).Run() |
| 38 | assert.NoError(t, err) |
| 39 | }) |
| 40 | |
| 41 | pty.ExpectMatch("pong from " + workspace.Name) |
| 42 | cancel() |
| 43 | <-cmdDone |
| 44 | }) |
| 45 | |
| 46 | t.Run("1Ping", func(t *testing.T) { |
| 47 | t.Parallel() |
| 48 | |
| 49 | client, workspace, agentToken := setupWorkspaceForAgent(t) |
| 50 | inv, root := clitest.New(t, "ping", "-n", "1", workspace.Name) |
| 51 | clitest.SetupConfig(t, client, root) |
| 52 | pty := ptytest.New(t) |
| 53 | inv.Stdin = pty.Input() |
| 54 | inv.Stderr = pty.Output() |
| 55 | inv.Stdout = pty.Output() |
| 56 | |
| 57 | _ = agenttest.New(t, client.URL, agentToken) |
| 58 | _ = coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID) |
| 59 | |
| 60 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) |
| 61 | defer cancel() |
| 62 | |
| 63 | cmdDone := tGo(t, func() { |
| 64 | err := inv.WithContext(ctx).Run() |
| 65 | assert.NoError(t, err) |
| 66 | }) |
| 67 | |
| 68 | pty.ExpectMatch("pong from " + workspace.Name) |
| 69 | cancel() |
| 70 | <-cmdDone |
| 71 | }) |
| 72 | |
| 73 | t.Run("1PingWithTime", func(t *testing.T) { |
nothing calls this directly
no test coverage detected