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

Function TestReadWorkflowFilePathSeparators

pkg/cli/workflows_path_test.go:81–117  ·  view source on GitHub ↗

TestReadWorkflowFilePathSeparators tests that the function works correctly regardless of path separator

(t *testing.T)

Source from the content-addressed store, hash-verified

79
80// TestReadWorkflowFilePathSeparators tests that the function works correctly regardless of path separator
81func TestReadWorkflowFilePathSeparators(t *testing.T) {
82 // Create a temporary directory structure
83 tempDir := testutil.TempDir(t, "test-*")
84 workflowsDir := filepath.Join(tempDir, ".github", "workflows")
85 if err := os.MkdirAll(workflowsDir, 0755); err != nil {
86 t.Fatalf("Failed to create workflows directory: %v", err)
87 }
88
89 // Create a test workflow file in a subdirectory
90 subDir := filepath.Join(workflowsDir, "subfolder")
91 if err := os.MkdirAll(subDir, 0755); err != nil {
92 t.Fatalf("Failed to create subfolder: %v", err)
93 }
94
95 testFile := filepath.Join(subDir, "test-workflow.md")
96 testContent := []byte("---\non: push\n---\n# Test Workflow")
97 if err := os.WriteFile(testFile, testContent, 0644); err != nil {
98 t.Fatalf("Failed to write test file: %v", err)
99 }
100
101 // Test reading with OS-appropriate path separators
102 // filepath.Join will use the correct separator for the current OS
103 relativePath := filepath.Join("subfolder", "test-workflow.md")
104 content, path, err := readWorkflowFile(relativePath, workflowsDir)
105 if err != nil {
106 t.Errorf("readWorkflowFile failed with subdirectory path: %v", err)
107 }
108
109 if string(content) != string(testContent) {
110 t.Errorf("Content mismatch. Expected: %s, Got: %s", testContent, content)
111 }
112
113 // The returned path should be the full path to the file
114 if path != testFile {
115 t.Errorf("Path mismatch. Expected: %s, Got: %s", testFile, path)
116 }
117}
118
119// TestReadWorkflowFileNonExistent tests error handling for non-existent files
120func TestReadWorkflowFileNonExistent(t *testing.T) {

Callers

nothing calls this directly

Calls 3

TempDirFunction · 0.92
readWorkflowFileFunction · 0.85
ErrorfMethod · 0.45

Tested by

no test coverage detected