TestReadWorkflowFilePathSeparators tests that the function works correctly regardless of path separator
(t *testing.T)
| 79 | |
| 80 | // TestReadWorkflowFilePathSeparators tests that the function works correctly regardless of path separator |
| 81 | func 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 |
| 120 | func TestReadWorkflowFileNonExistent(t *testing.T) { |
nothing calls this directly
no test coverage detected