(t *testing.T)
| 13 | ) |
| 14 | |
| 15 | func TestImportFileNotFoundError(t *testing.T) { |
| 16 | tempDir := testutil.TempDir(t, "import-error-*") |
| 17 | |
| 18 | // Create a workflow with a missing import |
| 19 | workflowPath := filepath.Join(tempDir, "workflow.md") |
| 20 | workflowContent := `--- |
| 21 | on: push |
| 22 | imports: |
| 23 | - nonexistent.md |
| 24 | --- |
| 25 | |
| 26 | # Test Workflow |
| 27 | ` |
| 28 | if err := os.WriteFile(workflowPath, []byte(workflowContent), 0644); err != nil { |
| 29 | t.Fatalf("Failed to write workflow file: %v", err) |
| 30 | } |
| 31 | |
| 32 | // Extract frontmatter |
| 33 | result, err := parser.ExtractFrontmatterFromContent(workflowContent) |
| 34 | if err != nil { |
| 35 | t.Fatalf("Failed to extract frontmatter: %v", err) |
| 36 | } |
| 37 | |
| 38 | // Try to process imports with source information |
| 39 | _, err = parser.ProcessImportsFromFrontmatterWithSource( |
| 40 | result.Frontmatter, |
| 41 | tempDir, |
| 42 | nil, |
| 43 | workflowPath, |
| 44 | workflowContent, |
| 45 | ) |
| 46 | |
| 47 | // Should get a formatted error |
| 48 | if err == nil { |
| 49 | t.Fatal("Expected error for missing import file, got nil") |
| 50 | } |
| 51 | |
| 52 | errStr := err.Error() |
| 53 | |
| 54 | // Check that error contains source location |
| 55 | wantContains := []string{ |
| 56 | "workflow.md:4:", // Line number |
| 57 | "error:", // Error type |
| 58 | "import file not found", // Error message |
| 59 | "nonexistent.md", // Import path |
| 60 | } |
| 61 | |
| 62 | for _, want := range wantContains { |
| 63 | if !strings.Contains(errStr, want) { |
| 64 | t.Errorf("Error missing expected string %q\nGot:\n%s", want, errStr) |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | func TestMultipleImportsWithError(t *testing.T) { |
| 70 | tempDir := testutil.TempDir(t, "import-error-*") |
nothing calls this directly
no test coverage detected