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

Function TestEnsureDevcontainerConfigWithCurrentRepo

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

Source from the content-addressed store, hash-verified

194}
195
196func TestEnsureDevcontainerConfigWithCurrentRepo(t *testing.T) {
197 tmpDir := testutil.TempDir(t, "test-*")
198
199 originalDir, err := os.Getwd()
200 if err != nil {
201 t.Fatalf("Failed to get current directory: %v", err)
202 }
203 defer func() {
204 _ = os.Chdir(originalDir)
205 }()
206
207 if err := os.Chdir(tmpDir); err != nil {
208 t.Fatalf("Failed to change to temp directory: %v", err)
209 }
210
211 // Initialize git repo
212 if err := exec.Command("git", "init").Run(); err != nil {
213 t.Skip("Git not available")
214 }
215
216 // Configure git
217 exec.Command("git", "config", "user.name", "Test User").Run()
218 exec.Command("git", "config", "user.email", "test@example.com").Run()
219
220 // Test creating devcontainer.json
221 err = ensureDevcontainerConfig(false, []string{})
222 if err != nil {
223 t.Fatalf("ensureDevcontainerConfig() failed: %v", err)
224 }
225
226 // Read and parse the created file at default location
227 devcontainerPath := filepath.Join(".devcontainer", "devcontainer.json")
228 data, err := os.ReadFile(devcontainerPath)
229 if err != nil {
230 t.Fatalf("Failed to read devcontainer.json: %v", err)
231 }
232
233 var config DevcontainerConfig
234 if err := json.Unmarshal(data, &config); err != nil {
235 t.Fatalf("Failed to parse devcontainer.json: %v", err)
236 }
237
238 // Verify that current repo has workflows: write permission
239 if config.Customizations == nil || config.Customizations.Codespaces == nil {
240 t.Fatal("Expected Codespaces customizations to be set")
241 }
242
243 // Check if any repository has workflows: write (should be current repo)
244 hasWorkflowsWrite := false
245 for _, repo := range config.Customizations.Codespaces.Repositories {
246 if repo.Permissions["workflows"] == "write" {
247 hasWorkflowsWrite = true
248 break
249 }
250 }
251
252 if !hasWorkflowsWrite {
253 t.Error("Expected at least one repository to have workflows: write permission")

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected