TestReadWorkflowFileWithRelativePath tests that readWorkflowFile correctly handles relative paths on all platforms
(t *testing.T)
| 12 | |
| 13 | // TestReadWorkflowFileWithRelativePath tests that readWorkflowFile correctly handles relative paths on all platforms |
| 14 | func TestReadWorkflowFileWithRelativePath(t *testing.T) { |
| 15 | // Create a temporary directory structure |
| 16 | tempDir := testutil.TempDir(t, "test-*") |
| 17 | workflowsDir := filepath.Join(tempDir, ".github", "workflows") |
| 18 | if err := os.MkdirAll(workflowsDir, 0755); err != nil { |
| 19 | t.Fatalf("Failed to create workflows directory: %v", err) |
| 20 | } |
| 21 | |
| 22 | // Create a test workflow file |
| 23 | testFile := filepath.Join(workflowsDir, "test-workflow.md") |
| 24 | testContent := []byte("---\non: push\n---\n# Test Workflow") |
| 25 | if err := os.WriteFile(testFile, testContent, 0644); err != nil { |
| 26 | t.Fatalf("Failed to write test file: %v", err) |
| 27 | } |
| 28 | |
| 29 | // Test reading the workflow file with a relative path |
| 30 | // This simulates what happens when getWorkflowsDir() returns a string and it's used with filepath.Join |
| 31 | content, path, err := readWorkflowFile("test-workflow.md", workflowsDir) |
| 32 | if err != nil { |
| 33 | t.Errorf("readWorkflowFile failed: %v", err) |
| 34 | } |
| 35 | |
| 36 | if string(content) != string(testContent) { |
| 37 | t.Errorf("Content mismatch. Expected: %s, Got: %s", testContent, content) |
| 38 | } |
| 39 | |
| 40 | // The returned path should be the full path to the file |
| 41 | expectedPath := testFile |
| 42 | if path != expectedPath { |
| 43 | t.Errorf("Path mismatch. Expected: %s, Got: %s", expectedPath, path) |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | // TestReadWorkflowFileWithAbsolutePath tests that readWorkflowFile correctly handles absolute paths |
| 48 | func TestReadWorkflowFileWithAbsolutePath(t *testing.T) { |
nothing calls this directly
no test coverage detected