(t *testing.T)
| 34 | ) |
| 35 | |
| 36 | func 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 | }, |
nothing calls this directly
no test coverage detected