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

Function TestEnsureDevcontainerConfigMergesWithExisting

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

Source from the content-addressed store, hash-verified

444}
445
446func TestEnsureDevcontainerConfigMergesWithExisting(t *testing.T) {
447 tmpDir := testutil.TempDir(t, "test-*")
448
449 originalDir, err := os.Getwd()
450 if err != nil {
451 t.Fatalf("Failed to get current directory: %v", err)
452 }
453 defer func() {
454 _ = os.Chdir(originalDir)
455 }()
456
457 if err := os.Chdir(tmpDir); err != nil {
458 t.Fatalf("Failed to change to temp directory: %v", err)
459 }
460
461 // Initialize git repo
462 if err := exec.Command("git", "init").Run(); err != nil {
463 t.Skip("Git not available")
464 }
465
466 // Configure git and add remote
467 exec.Command("git", "config", "user.name", "Test User").Run()
468 exec.Command("git", "config", "user.email", "test@example.com").Run()
469 exec.Command("git", "remote", "add", "origin", "https://github.com/testorg/testrepo.git").Run()
470
471 // Create .devcontainer directory
472 devcontainerDir := ".devcontainer"
473 if err := os.MkdirAll(devcontainerDir, 0755); err != nil {
474 t.Fatalf("Failed to create directory: %v", err)
475 }
476
477 // Create an existing devcontainer.json with custom configuration
478 existingConfig := DevcontainerConfig{
479 Name: "My Custom Dev Environment",
480 Image: "mcr.microsoft.com/devcontainers/python:3.11",
481 Customizations: &DevcontainerCustomizations{
482 VSCode: &DevcontainerVSCode{
483 Extensions: []string{
484 "ms-python.python",
485 "ms-python.vscode-pylance",
486 },
487 },
488 },
489 Features: DevcontainerFeatures{
490 "ghcr.io/devcontainers/features/docker-in-docker:2": map[string]any{},
491 },
492 PostCreateCommand: "pip install -r requirements.txt",
493 }
494
495 devcontainerPath := filepath.Join(devcontainerDir, "devcontainer.json")
496 data, err := json.MarshalIndent(existingConfig, "", " ")
497 if err != nil {
498 t.Fatalf("Failed to marshal existing config: %v", err)
499 }
500 data = append(data, '\n')
501
502 if err := os.WriteFile(devcontainerPath, data, 0644); err != nil {
503 t.Fatalf("Failed to write existing config: %v", err)

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