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

Function TestRemoveWorkflowsWithNoOrphansFlag

pkg/cli/commands_test.go:832–908  ·  view source on GitHub ↗

TestRemoveWorkflowsWithNoOrphansFlag tests that the --keep-orphans flag works correctly

(t *testing.T)

Source from the content-addressed store, hash-verified

830
831// TestRemoveWorkflowsWithNoOrphansFlag tests that the --keep-orphans flag works correctly
832func 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 := `---
854on:
855 workflow_dispatch:
856---
857
858# Test Workflow
859
860@include shared/common.md
861
862This 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

Callers

nothing calls this directly

Calls 3

GetWorkflowDirFunction · 0.92
previewOrphanedIncludesFunction · 0.85
ErrorfMethod · 0.45

Tested by

no test coverage detected