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

Function TestAddWorkflowForce

pkg/cli/add_integration_test.go:505–582  ·  view source on GitHub ↗

TestAddWorkflowForce tests the --force flag to overwrite existing workflows

(t *testing.T)

Source from the content-addressed store, hash-verified

503
504// TestAddWorkflowForce tests the --force flag to overwrite existing workflows
505func TestAddWorkflowForce(t *testing.T) {
506 setup := setupAddIntegrationTest(t)
507 defer setup.cleanup()
508
509 // Create .github/workflows directory with an existing workflow
510 workflowsDir := filepath.Join(setup.tempDir, ".github", "workflows")
511 err := os.MkdirAll(workflowsDir, 0755)
512 require.NoError(t, err, "should create workflows directory")
513
514 existingWorkflowPath := filepath.Join(workflowsDir, "existing-workflow.md")
515 existingContent := `---
516name: Old Workflow
517on: push
518permissions:
519 contents: read
520engine: copilot
521---
522
523# Old Workflow
524
525This is the OLD content that should be replaced.
526`
527 err = os.WriteFile(existingWorkflowPath, []byte(existingContent), 0644)
528 require.NoError(t, err, "should write existing workflow file")
529
530 // Create a new workflow file with same name in source directory
531 sourceDir := filepath.Join(setup.tempDir, "source-workflows")
532 err = os.MkdirAll(sourceDir, 0755)
533 require.NoError(t, err, "should create source directory")
534
535 newWorkflowPath := filepath.Join(sourceDir, "existing-workflow.md")
536 newContent := `---
537name: New Workflow
538on: workflow_dispatch
539permissions:
540 contents: read
541engine: copilot
542---
543
544# New Workflow
545
546This is the NEW content that should replace the old.
547`
548 err = os.WriteFile(newWorkflowPath, []byte(newContent), 0644)
549 require.NoError(t, err, "should write new workflow file")
550
551 // First try without --force (should fail)
552 cmdNoForce := exec.Command(setup.binaryPath, "add", newWorkflowPath)
553 cmdNoForce.Dir = setup.tempDir
554 outputNoForce, errNoForce := cmdNoForce.CombinedOutput()
555 outputNoForceStr := string(outputNoForce)
556
557 t.Logf("Command output (without --force):\n%s", outputNoForceStr)
558
559 assert.Error(t, errNoForce, "add without --force should fail when file exists")
560 assert.Contains(t, outputNoForceStr, "already exists", "error should mention file exists")
561
562 // Verify original content is still there

Callers

nothing calls this directly

Calls 2

setupAddIntegrationTestFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected