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

Function TestEnsureDevcontainerConfigUpdatesOldVersion

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

Source from the content-addressed store, hash-verified

329}
330
331func TestEnsureDevcontainerConfigUpdatesOldVersion(t *testing.T) {
332 tmpDir := testutil.TempDir(t, "test-*")
333
334 originalDir, err := os.Getwd()
335 if err != nil {
336 t.Fatalf("Failed to get current directory: %v", err)
337 }
338 defer func() {
339 _ = os.Chdir(originalDir)
340 }()
341
342 if err := os.Chdir(tmpDir); err != nil {
343 t.Fatalf("Failed to change to temp directory: %v", err)
344 }
345
346 // Initialize git repo
347 if err := exec.Command("git", "init").Run(); err != nil {
348 t.Skip("Git not available")
349 }
350
351 // Configure git
352 exec.Command("git", "config", "user.name", "Test User").Run()
353 exec.Command("git", "config", "user.email", "test@example.com").Run()
354
355 // Create .devcontainer directory
356 devcontainerDir := ".devcontainer"
357 if err := os.MkdirAll(devcontainerDir, 0755); err != nil {
358 t.Fatalf("Failed to create directory: %v", err)
359 }
360
361 // Create a devcontainer.json with old copilot-cli version at default location
362 oldConfig := DevcontainerConfig{
363 Name: "Existing Dev Environment",
364 Image: "mcr.microsoft.com/devcontainers/go:latest",
365 Features: DevcontainerFeatures{
366 "ghcr.io/devcontainers/features/github-cli:1": map[string]any{},
367 "ghcr.io/devcontainers/features/copilot-cli:1": map[string]any{}, // Old version
368 },
369 PostCreateCommand: "echo 'existing setup'",
370 }
371
372 devcontainerPath := filepath.Join(devcontainerDir, "devcontainer.json")
373 data, err := json.MarshalIndent(oldConfig, "", " ")
374 if err != nil {
375 t.Fatalf("Failed to marshal old config: %v", err)
376 }
377 data = append(data, '\n')
378
379 if err := os.WriteFile(devcontainerPath, data, 0644); err != nil {
380 t.Fatalf("Failed to write old config: %v", err)
381 }
382
383 // Run ensureDevcontainerConfig - should update the version
384 err = ensureDevcontainerConfig(false, []string{})
385 if err != nil {
386 t.Fatalf("ensureDevcontainerConfig() failed: %v", err)
387 }
388

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