(t *testing.T)
| 4363 | } |
| 4364 | |
| 4365 | func TestDevcontainerDiscovery(t *testing.T) { |
| 4366 | t.Parallel() |
| 4367 | |
| 4368 | if runtime.GOOS == "windows" { |
| 4369 | t.Skip("Dev Container tests are not supported on Windows") |
| 4370 | } |
| 4371 | |
| 4372 | // We discover dev container projects by searching |
| 4373 | // for git repositories at the agent's directory, |
| 4374 | // and then recursively walking through these git |
| 4375 | // repositories to find any `.devcontainer/devcontainer.json` |
| 4376 | // files. These tests are to validate that behavior. |
| 4377 | |
| 4378 | homeDir, err := os.UserHomeDir() |
| 4379 | require.NoError(t, err) |
| 4380 | |
| 4381 | tests := []struct { |
| 4382 | name string |
| 4383 | agentDir string |
| 4384 | fs map[string]string |
| 4385 | expected []codersdk.WorkspaceAgentDevcontainer |
| 4386 | }{ |
| 4387 | { |
| 4388 | name: "GitProjectInRootDir/SingleProject", |
| 4389 | agentDir: "/home/coder", |
| 4390 | fs: map[string]string{ |
| 4391 | "/home/coder/.git/HEAD": "", |
| 4392 | "/home/coder/.devcontainer/devcontainer.json": "", |
| 4393 | }, |
| 4394 | expected: []codersdk.WorkspaceAgentDevcontainer{ |
| 4395 | { |
| 4396 | WorkspaceFolder: "/home/coder", |
| 4397 | ConfigPath: "/home/coder/.devcontainer/devcontainer.json", |
| 4398 | Status: codersdk.WorkspaceAgentDevcontainerStatusStopped, |
| 4399 | }, |
| 4400 | }, |
| 4401 | }, |
| 4402 | { |
| 4403 | name: "GitProjectInRootDir/MultipleProjects", |
| 4404 | agentDir: "/home/coder", |
| 4405 | fs: map[string]string{ |
| 4406 | "/home/coder/.git/HEAD": "", |
| 4407 | "/home/coder/.devcontainer/devcontainer.json": "", |
| 4408 | "/home/coder/site/.devcontainer/devcontainer.json": "", |
| 4409 | }, |
| 4410 | expected: []codersdk.WorkspaceAgentDevcontainer{ |
| 4411 | { |
| 4412 | WorkspaceFolder: "/home/coder", |
| 4413 | ConfigPath: "/home/coder/.devcontainer/devcontainer.json", |
| 4414 | Status: codersdk.WorkspaceAgentDevcontainerStatusStopped, |
| 4415 | }, |
| 4416 | { |
| 4417 | WorkspaceFolder: "/home/coder/site", |
| 4418 | ConfigPath: "/home/coder/site/.devcontainer/devcontainer.json", |
| 4419 | Status: codersdk.WorkspaceAgentDevcontainerStatusStopped, |
| 4420 | }, |
| 4421 | }, |
| 4422 | }, |
nothing calls this directly
no test coverage detected