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

Function TestReadWorkflowFileWithRelativePath

pkg/cli/workflows_path_test.go:14–45  ·  view source on GitHub ↗

TestReadWorkflowFileWithRelativePath tests that readWorkflowFile correctly handles relative paths on all platforms

(t *testing.T)

Source from the content-addressed store, hash-verified

12
13// TestReadWorkflowFileWithRelativePath tests that readWorkflowFile correctly handles relative paths on all platforms
14func 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
48func TestReadWorkflowFileWithAbsolutePath(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