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

Function setupDevcontainerWorkspace

agent/agentcontainers/devcontainercli_test.go:604–625  ·  view source on GitHub ↗

setupDevcontainerWorkspace prepares a test environment with a minimal devcontainer.json configuration and returns the path to the config file.

(t *testing.T, workspaceFolder string)

Source from the content-addressed store, hash-verified

602// setupDevcontainerWorkspace prepares a test environment with a minimal
603// devcontainer.json configuration and returns the path to the config file.
604func 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.

Callers 1

Calls 3

MkdirAllMethod · 0.80
HelperMethod · 0.65
WriteFileMethod · 0.65

Tested by

no test coverage detected