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

Function TestEnsureDevcontainerConfig

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

Source from the content-addressed store, hash-verified

14)
15
16func TestEnsureDevcontainerConfig(t *testing.T) {
17 tmpDir := testutil.TempDir(t, "test-*")
18
19 originalDir, err := os.Getwd()
20 if err != nil {
21 t.Fatalf("Failed to get current directory: %v", err)
22 }
23 defer func() {
24 _ = os.Chdir(originalDir)
25 }()
26
27 if err := os.Chdir(tmpDir); err != nil {
28 t.Fatalf("Failed to change to temp directory: %v", err)
29 }
30
31 // Initialize git repo (required for getCurrentRepoName)
32 if err := exec.Command("git", "init").Run(); err != nil {
33 t.Skip("Git not available")
34 }
35
36 // Configure git
37 exec.Command("git", "config", "user.name", "Test User").Run()
38 exec.Command("git", "config", "user.email", "test@example.com").Run()
39
40 // Test creating devcontainer.json
41 err = ensureDevcontainerConfig(false, []string{})
42 if err != nil {
43 t.Fatalf("ensureDevcontainerConfig() failed: %v", err)
44 }
45
46 // Verify .devcontainer/devcontainer.json was created at default location
47 devcontainerPath := filepath.Join(".devcontainer", "devcontainer.json")
48 if _, err := os.Stat(devcontainerPath); os.IsNotExist(err) {
49 t.Fatal("Expected .devcontainer/devcontainer.json to be created")
50 }
51
52 // Read and parse the created file
53 data, err := os.ReadFile(devcontainerPath)
54 if err != nil {
55 t.Fatalf("Failed to read devcontainer.json: %v", err)
56 }
57
58 var config DevcontainerConfig
59 if err := json.Unmarshal(data, &config); err != nil {
60 t.Fatalf("Failed to parse devcontainer.json: %v", err)
61 }
62
63 // Verify basic structure
64 if config.Name == "" {
65 t.Error("Expected name to be set")
66 }
67
68 if config.Image != "mcr.microsoft.com/devcontainers/universal:latest" {
69 t.Errorf("Expected universal image, got %q", config.Image)
70 }
71
72 // Verify Codespaces configuration
73 if config.Customizations == nil || config.Customizations.Codespaces == nil {

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected