setupDevcontainerWorkspace prepares a test environment with a minimal devcontainer.json configuration and returns the path to the config file.
(t *testing.T, workspaceFolder string)
| 602 | // setupDevcontainerWorkspace prepares a test environment with a minimal |
| 603 | // devcontainer.json configuration and returns the path to the config file. |
| 604 | func setupDevcontainerWorkspace(t *testing.T, workspaceFolder string) string { |
| 605 | t.Helper() |
| 606 | |
| 607 | // Create the devcontainer directory structure. |
| 608 | devcontainerDir := filepath.Join(workspaceFolder, ".devcontainer") |
| 609 | err := os.MkdirAll(devcontainerDir, 0o755) |
| 610 | require.NoError(t, err, "create .devcontainer directory") |
| 611 | |
| 612 | // Write a minimal configuration with test labels for identification. |
| 613 | configPath := filepath.Join(devcontainerDir, "devcontainer.json") |
| 614 | content := `{ |
| 615 | "image": "alpine:latest", |
| 616 | "containerEnv": { |
| 617 | "TEST_CONTAINER": "true" |
| 618 | }, |
| 619 | "runArgs": ["--label=com.coder.test=devcontainercli", "--label=` + agentcontainers.DevcontainerIsTestRunLabel + `=true"] |
| 620 | }` |
| 621 | err = os.WriteFile(configPath, []byte(content), 0o600) |
| 622 | require.NoError(t, err, "create devcontainer.json file") |
| 623 | |
| 624 | return configPath |
| 625 | } |
| 626 | |
| 627 | // findDevcontainerByID locates a container by its ID and verifies it has our |
| 628 | // test label. Returns the container and whether it was found. |
no test coverage detected