(t *testing.T)
| 81 | } |
| 82 | |
| 83 | func TestFrontmatterOffsetCalculation(t *testing.T) { |
| 84 | // Test frontmatter at the beginning of the file |
| 85 | tempFile := "/tmp/gh-aw/gh-aw/test_frontmatter_offset.md" |
| 86 | |
| 87 | // Ensure the directory exists |
| 88 | err := os.MkdirAll(filepath.Dir(tempFile), 0755) |
| 89 | if err != nil { |
| 90 | t.Fatalf("Failed to create temp directory: %v", err) |
| 91 | } |
| 92 | |
| 93 | content := `--- |
| 94 | name: Test Workflow |
| 95 | invalid_prop: bad |
| 96 | --- |
| 97 | |
| 98 | # This is content after frontmatter |
| 99 | <!-- HTML comment --> |
| 100 | |
| 101 | Content here. |
| 102 | ` |
| 103 | |
| 104 | err = os.WriteFile(tempFile, []byte(content), 0644) |
| 105 | if err != nil { |
| 106 | t.Fatalf("Failed to create temp file: %v", err) |
| 107 | } |
| 108 | defer os.Remove(tempFile) |
| 109 | |
| 110 | schemaJSON := `{ |
| 111 | "type": "object", |
| 112 | "properties": { |
| 113 | "name": {"type": "string"} |
| 114 | }, |
| 115 | "additionalProperties": false |
| 116 | }` |
| 117 | |
| 118 | frontmatterResult, err := ExtractFrontmatterFromContent(content) |
| 119 | if err != nil { |
| 120 | t.Fatalf("Failed to extract frontmatter: %v", err) |
| 121 | } |
| 122 | |
| 123 | err = validateWithSchemaAndLocation(frontmatterResult.Frontmatter, schemaJSON, "test workflow", tempFile) |
| 124 | |
| 125 | if err == nil { |
| 126 | t.Fatal("Expected validation error for additional properties, got nil") |
| 127 | } |
| 128 | |
| 129 | errorMessage := err.Error() |
| 130 | t.Logf("Error message with offset: %s", errorMessage) |
| 131 | |
| 132 | // The invalid_prop should be on line 3 (1-based: ---, name, invalid_prop) |
| 133 | expectedPatterns := []string{ |
| 134 | tempFile + ":", |
| 135 | "3:", // Line 3 where invalid_prop appears |
| 136 | "invalid_prop", |
| 137 | } |
| 138 | |
| 139 | for _, pattern := range expectedPatterns { |
| 140 | if !strings.Contains(errorMessage, pattern) { |
nothing calls this directly
no test coverage detected