TestAddWorkflowForce tests the --force flag to overwrite existing workflows
(t *testing.T)
| 503 | |
| 504 | // TestAddWorkflowForce tests the --force flag to overwrite existing workflows |
| 505 | func 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 := `--- |
| 516 | name: Old Workflow |
| 517 | on: push |
| 518 | permissions: |
| 519 | contents: read |
| 520 | engine: copilot |
| 521 | --- |
| 522 | |
| 523 | # Old Workflow |
| 524 | |
| 525 | This 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 := `--- |
| 537 | name: New Workflow |
| 538 | on: workflow_dispatch |
| 539 | permissions: |
| 540 | contents: read |
| 541 | engine: copilot |
| 542 | --- |
| 543 | |
| 544 | # New Workflow |
| 545 | |
| 546 | This 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 |
nothing calls this directly
no test coverage detected