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

Function TestOpenVSCode

cli/open_test.go:36–171  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

34)
35
36func TestOpenVSCode(t *testing.T) {
37 t.Parallel()
38
39 agentName := "agent1"
40 agentDir, err := filepath.Abs(filepath.FromSlash("/tmp"))
41 require.NoError(t, err)
42 client, workspace, agentToken := setupWorkspaceForAgent(t, func(agents []*proto.Agent) []*proto.Agent {
43 agents[0].Directory = agentDir
44 agents[0].Name = agentName
45 agents[0].OperatingSystem = runtime.GOOS
46 return agents
47 })
48
49 _ = agenttest.New(t, client.URL, agentToken)
50 _ = coderdtest.NewWorkspaceAgentWaiter(t, client, workspace.ID).Wait()
51
52 insideWorkspaceEnv := map[string]string{
53 "CODER": "true",
54 "CODER_WORKSPACE_NAME": workspace.Name,
55 "CODER_WORKSPACE_AGENT_NAME": agentName,
56 }
57
58 wd, err := os.Getwd()
59 require.NoError(t, err)
60
61 tests := []struct {
62 name string
63 args []string
64 env map[string]string
65 wantDir string
66 wantToken bool
67 wantError bool
68 }{
69 {
70 name: "no args",
71 wantError: true,
72 },
73 {
74 name: "nonexistent workspace",
75 args: []string{"--test.open-error", workspace.Name + "bad"},
76 wantError: true,
77 },
78 {
79 name: "ok",
80 args: []string{"--test.open-error", workspace.Name},
81 wantDir: agentDir,
82 },
83 {
84 name: "ok relative path",
85 args: []string{"--test.open-error", workspace.Name, "my/relative/path"},
86 wantDir: filepath.Join(agentDir, filepath.FromSlash("my/relative/path")),
87 wantError: false,
88 },
89 {
90 name: "ok with absolute path",
91 args: []string{"--test.open-error", workspace.Name, agentDir},
92 wantDir: agentDir,
93 },

Callers

nothing calls this directly

Calls 15

NewFunction · 0.92
NewWorkspaceAgentWaiterFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
NewFunction · 0.92
ContextFunction · 0.92
StartWithWaiterFunction · 0.92
WithContextMethod · 0.80
RequireErrorMethod · 0.80
NotEmptyMethod · 0.80
RequireSuccessMethod · 0.80
setupWorkspaceForAgentFunction · 0.70

Tested by

no test coverage detected