TestRemoveWorkflowsWithNoOrphansFlag tests that the --keep-orphans flag works correctly
(t *testing.T)
| 830 | |
| 831 | // TestRemoveWorkflowsWithNoOrphansFlag tests that the --keep-orphans flag works correctly |
| 832 | func TestRemoveWorkflowsWithNoOrphansFlag(t *testing.T) { |
| 833 | // Create a temporary directory structure |
| 834 | tmpDir, err := os.MkdirTemp("", "test-keep-orphans-flag") |
| 835 | if err != nil { |
| 836 | t.Fatal(err) |
| 837 | } |
| 838 | defer os.RemoveAll(tmpDir) |
| 839 | |
| 840 | // Create .github/workflows directory |
| 841 | workflowsDir := filepath.Join(tmpDir, constants.GetWorkflowDir()) |
| 842 | if err := os.MkdirAll(workflowsDir, 0755); err != nil { |
| 843 | t.Fatal(err) |
| 844 | } |
| 845 | |
| 846 | // Create shared subdirectory |
| 847 | sharedDir := filepath.Join(workflowsDir, "shared") |
| 848 | if err := os.MkdirAll(sharedDir, 0755); err != nil { |
| 849 | t.Fatal(err) |
| 850 | } |
| 851 | |
| 852 | // Create a workflow that uses an include |
| 853 | workflowContent := `--- |
| 854 | on: |
| 855 | workflow_dispatch: |
| 856 | --- |
| 857 | |
| 858 | # Test Workflow |
| 859 | |
| 860 | @include shared/common.md |
| 861 | |
| 862 | This workflow uses an include. |
| 863 | ` |
| 864 | if err := os.WriteFile(filepath.Join(workflowsDir, "test-workflow.md"), []byte(workflowContent), 0644); err != nil { |
| 865 | t.Fatal(err) |
| 866 | } |
| 867 | |
| 868 | // Create the include file |
| 869 | includeContent := `This is a shared include file.` |
| 870 | if err := os.WriteFile(filepath.Join(sharedDir, "common.md"), []byte(includeContent), 0644); err != nil { |
| 871 | t.Fatal(err) |
| 872 | } |
| 873 | |
| 874 | // Change to the temporary directory |
| 875 | oldDir, err := os.Getwd() |
| 876 | if err != nil { |
| 877 | t.Fatal(err) |
| 878 | } |
| 879 | defer func() { |
| 880 | if err := os.Chdir(oldDir); err != nil { |
| 881 | t.Logf("Warning: Failed to restore working directory: %v", err) |
| 882 | } |
| 883 | }() |
| 884 | |
| 885 | if err := os.Chdir(tmpDir); err != nil { |
| 886 | t.Fatal(err) |
| 887 | } |
| 888 | |
| 889 | // Test 1: Verify include file exists before removal |
nothing calls this directly
no test coverage detected