MCPcopy Create free account
hub / github.com/github/gh-aw / TestEnsureDevcontainerConfigWithBuildField

Function TestEnsureDevcontainerConfigWithBuildField

pkg/cli/devcontainer_test.go:593–743  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

591}
592
593func TestEnsureDevcontainerConfigWithBuildField(t *testing.T) {
594 tmpDir := testutil.TempDir(t, "test-*")
595
596 originalDir, err := os.Getwd()
597 if err != nil {
598 t.Fatalf("Failed to get current directory: %v", err)
599 }
600 defer func() {
601 _ = os.Chdir(originalDir)
602 }()
603
604 if err := os.Chdir(tmpDir); err != nil {
605 t.Fatalf("Failed to change to temp directory: %v", err)
606 }
607
608 // Initialize git repo
609 if err := exec.Command("git", "init").Run(); err != nil {
610 t.Skip("Git not available")
611 }
612
613 // Configure git and add remote
614 exec.Command("git", "config", "user.name", "Test User").Run()
615 exec.Command("git", "config", "user.email", "test@example.com").Run()
616 exec.Command("git", "remote", "add", "origin", "https://github.com/testorg/testrepo.git").Run()
617
618 // Create .devcontainer directory
619 devcontainerDir := ".devcontainer"
620 if err := os.MkdirAll(devcontainerDir, 0755); err != nil {
621 t.Fatalf("Failed to create directory: %v", err)
622 }
623
624 // Create an existing devcontainer.json with "build" field instead of "image"
625 existingConfig := DevcontainerConfig{
626 Name: "Custom Build Environment",
627 Build: &DevcontainerBuild{
628 Dockerfile: "Dockerfile",
629 },
630 Customizations: &DevcontainerCustomizations{
631 VSCode: &DevcontainerVSCode{
632 Extensions: []string{
633 "golang.go",
634 },
635 },
636 },
637 Features: DevcontainerFeatures{
638 "ghcr.io/devcontainers/features/docker-in-docker:2": map[string]any{},
639 },
640 PostCreateCommand: "make setup",
641 }
642
643 devcontainerPath := filepath.Join(devcontainerDir, "devcontainer.json")
644 data, err := json.MarshalIndent(existingConfig, "", " ")
645 if err != nil {
646 t.Fatalf("Failed to marshal existing config: %v", err)
647 }
648 data = append(data, '\n')
649
650 if err := os.WriteFile(devcontainerPath, data, 0644); err != nil {

Callers

nothing calls this directly

Calls 5

TempDirFunction · 0.92
ensureDevcontainerConfigFunction · 0.85
RunMethod · 0.45
ErrorfMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected