(t *testing.T)
| 591 | } |
| 592 | |
| 593 | func 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 { |
nothing calls this directly
no test coverage detected