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

Function TestSSH

cli/ssh_test.go:80–1812  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

78}
79
80func TestSSH(t *testing.T) {
81 t.Parallel()
82 t.Run("ImmediateExit", func(t *testing.T) {
83 t.Parallel()
84
85 client, workspace, agentToken := setupWorkspaceForAgent(t)
86 inv, root := clitest.New(t, "ssh", workspace.Name)
87 clitest.SetupConfig(t, client, root)
88 pty := ptytest.New(t).Attach(inv)
89
90 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
91 defer cancel()
92
93 cmdDone := tGo(t, func() {
94 err := inv.WithContext(ctx).Run()
95 assert.NoError(t, err)
96 })
97 pty.ExpectMatch("Waiting")
98
99 _ = agenttest.New(t, client.URL, agentToken)
100 coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
101
102 // Shells on Mac, Windows, and Linux all exit shells with the "exit" command.
103 pty.WriteLine("exit")
104 <-cmdDone
105 })
106 t.Run("WorkspaceNameInput", func(t *testing.T) {
107 t.Parallel()
108
109 cases := []string{
110 "myworkspace",
111 "myworkspace.dev",
112 "myuser/myworkspace",
113 "myuser--myworkspace",
114 "myuser/myworkspace--dev",
115 "myuser/myworkspace.dev",
116 "myuser--myworkspace--dev",
117 "myuser--myworkspace.dev",
118 "dev.myworkspace.myuser",
119 }
120
121 for _, tc := range cases {
122 t.Run(tc, func(t *testing.T) {
123 t.Parallel()
124 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
125 defer cancel()
126
127 client, workspace, agentToken := setupWorkspaceForAgent(t)
128
129 inv, root := clitest.New(t, "ssh", tc)
130 clitest.SetupConfig(t, client, root)
131 pty := ptytest.New(t).Attach(inv)
132
133 cmdDone := tGo(t, func() {
134 err := inv.WithContext(ctx).Run()
135 assert.NoError(t, err)
136 })
137 pty.ExpectMatch("Waiting")

Callers

nothing calls this directly

Calls 15

WorkspaceMethod · 0.95
SetLoggerMethod · 0.95
CloseMethod · 0.95
UserMethod · 0.95
NotifyMethod · 0.95
AssertStoppedMethod · 0.95
CloseMethod · 0.95
NewFunction · 0.92
SetupConfigFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
AwaitWorkspaceAgentsFunction · 0.92

Tested by

no test coverage detected