TestFindWorkflowsWithSource_CustomDirectory tests that findWorkflowsWithSource works with custom directories
(t *testing.T)
| 433 | |
| 434 | // TestFindWorkflowsWithSource_CustomDirectory tests that findWorkflowsWithSource works with custom directories |
| 435 | func TestFindWorkflowsWithSource_CustomDirectory(t *testing.T) { |
| 436 | // Create a temporary directory structure |
| 437 | tmpDir := testutil.TempDir(t, "test-*") |
| 438 | customWorkflowDir := filepath.Join(tmpDir, "custom", "workflows") |
| 439 | if err := os.MkdirAll(customWorkflowDir, 0755); err != nil { |
| 440 | t.Fatalf("Failed to create custom workflow directory: %v", err) |
| 441 | } |
| 442 | |
| 443 | // Create a workflow file with source field |
| 444 | workflowContent := `--- |
| 445 | on: push |
| 446 | engine: claude |
| 447 | source: test/repo/workflow.md@v1.0.0 |
| 448 | --- |
| 449 | |
| 450 | # Test Workflow |
| 451 | |
| 452 | Test content.` |
| 453 | |
| 454 | workflowPath := filepath.Join(customWorkflowDir, "test-workflow.md") |
| 455 | if err := os.WriteFile(workflowPath, []byte(workflowContent), 0644); err != nil { |
| 456 | t.Fatalf("Failed to write workflow file: %v", err) |
| 457 | } |
| 458 | |
| 459 | // Create a workflow file without source field |
| 460 | workflowWithoutSource := `--- |
| 461 | on: push |
| 462 | engine: claude |
| 463 | --- |
| 464 | |
| 465 | # Another Workflow |
| 466 | |
| 467 | No source field.` |
| 468 | |
| 469 | workflowPath2 := filepath.Join(customWorkflowDir, "no-source.md") |
| 470 | if err := os.WriteFile(workflowPath2, []byte(workflowWithoutSource), 0644); err != nil { |
| 471 | t.Fatalf("Failed to write workflow file: %v", err) |
| 472 | } |
| 473 | |
| 474 | // Test findWorkflowsWithSource with custom directory |
| 475 | workflows, err := findWorkflowsWithSource(customWorkflowDir, nil, false) |
| 476 | if err != nil { |
| 477 | t.Fatalf("Expected no error, got: %v", err) |
| 478 | } |
| 479 | |
| 480 | // Should find only one workflow (the one with source field) |
| 481 | if len(workflows) != 1 { |
| 482 | t.Errorf("Expected to find 1 workflow with source field, got %d", len(workflows)) |
| 483 | } |
| 484 | |
| 485 | if len(workflows) > 0 { |
| 486 | if workflows[0].Name != "test-workflow" { |
| 487 | t.Errorf("Expected workflow name 'test-workflow', got '%s'", workflows[0].Name) |
| 488 | } |
| 489 | if workflows[0].SourceSpec != "test/repo/workflow.md@v1.0.0" { |
| 490 | t.Errorf("Expected source spec 'test/repo/workflow.md@v1.0.0', got '%s'", workflows[0].SourceSpec) |
| 491 | } |
| 492 | } |
nothing calls this directly
no test coverage detected