(t *testing.T)
| 171 | } |
| 172 | |
| 173 | func TestOpenVSCode_NoAgentDirectory(t *testing.T) { |
| 174 | t.Parallel() |
| 175 | |
| 176 | agentName := "agent1" |
| 177 | client, workspace, agentToken := setupWorkspaceForAgent(t, func(agents []*proto.Agent) []*proto.Agent { |
| 178 | agents[0].Name = agentName |
| 179 | agents[0].OperatingSystem = runtime.GOOS |
| 180 | return agents |
| 181 | }) |
| 182 | |
| 183 | _ = agenttest.New(t, client.URL, agentToken) |
| 184 | _ = coderdtest.NewWorkspaceAgentWaiter(t, client, workspace.ID).Wait() |
| 185 | |
| 186 | insideWorkspaceEnv := map[string]string{ |
| 187 | "CODER": "true", |
| 188 | "CODER_WORKSPACE_NAME": workspace.Name, |
| 189 | "CODER_WORKSPACE_AGENT_NAME": agentName, |
| 190 | } |
| 191 | |
| 192 | wd, err := os.Getwd() |
| 193 | require.NoError(t, err) |
| 194 | |
| 195 | absPath := "/home/coder" |
| 196 | if runtime.GOOS == "windows" { |
| 197 | absPath = "C:\\home\\coder" |
| 198 | } |
| 199 | |
| 200 | tests := []struct { |
| 201 | name string |
| 202 | args []string |
| 203 | env map[string]string |
| 204 | wantDir string |
| 205 | wantToken bool |
| 206 | wantError bool |
| 207 | }{ |
| 208 | { |
| 209 | name: "ok", |
| 210 | args: []string{"--test.open-error", workspace.Name}, |
| 211 | }, |
| 212 | { |
| 213 | name: "no agent dir error relative path", |
| 214 | args: []string{"--test.open-error", workspace.Name, "my/relative/path"}, |
| 215 | wantDir: filepath.FromSlash("my/relative/path"), |
| 216 | wantError: true, |
| 217 | }, |
| 218 | { |
| 219 | name: "ok with absolute path", |
| 220 | args: []string{"--test.open-error", workspace.Name, absPath}, |
| 221 | wantDir: absPath, |
| 222 | }, |
| 223 | { |
| 224 | name: "ok with token", |
| 225 | args: []string{"--test.open-error", workspace.Name, "--generate-token"}, |
| 226 | wantToken: true, |
| 227 | }, |
| 228 | // Inside workspace, does not require --test.open-error. |
| 229 | { |
| 230 | name: "ok inside workspace", |
nothing calls this directly
no test coverage detected