MCPcopy Index your code
hub / github.com/coder/coder / TestPing

Function TestPing

cli/ping_test.go:16–128  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func 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) {

Callers

nothing calls this directly

Calls 13

NewFunction · 0.92
SetupConfigFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
AwaitWorkspaceAgentsFunction · 0.92
tGoFunction · 0.85
WithContextMethod · 0.80
setupWorkspaceForAgentFunction · 0.70
RunMethod · 0.65
InputMethod · 0.65
OutputMethod · 0.65
ExpectMatchMethod · 0.45

Tested by

no test coverage detected