(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestValidateWithSchema(t *testing.T) { |
| 13 | tests := []struct { |
| 14 | name string |
| 15 | frontmatter map[string]any |
| 16 | schema string |
| 17 | context string |
| 18 | wantErr bool |
| 19 | errContains string |
| 20 | }{ |
| 21 | { |
| 22 | name: "valid data with simple schema", |
| 23 | frontmatter: map[string]any{ |
| 24 | "name": "test", |
| 25 | }, |
| 26 | schema: `{ |
| 27 | "type": "object", |
| 28 | "properties": { |
| 29 | "name": {"type": "string"} |
| 30 | }, |
| 31 | "additionalProperties": false |
| 32 | }`, |
| 33 | context: "test context", |
| 34 | wantErr: false, |
| 35 | }, |
| 36 | { |
| 37 | name: "invalid data with additional property", |
| 38 | frontmatter: map[string]any{ |
| 39 | "name": "test", |
| 40 | "invalid": "value", |
| 41 | }, |
| 42 | schema: `{ |
| 43 | "type": "object", |
| 44 | "properties": { |
| 45 | "name": {"type": "string"} |
| 46 | }, |
| 47 | "additionalProperties": false |
| 48 | }`, |
| 49 | context: "test context", |
| 50 | wantErr: true, |
| 51 | errContains: "additional properties 'invalid' not allowed", |
| 52 | }, |
| 53 | { |
| 54 | name: "invalid schema JSON", |
| 55 | frontmatter: map[string]any{ |
| 56 | "name": "test", |
| 57 | }, |
| 58 | schema: `invalid json`, |
| 59 | context: "test context", |
| 60 | wantErr: true, |
| 61 | errContains: "schema validation error for test context", |
| 62 | }, |
| 63 | } |
| 64 | |
| 65 | for _, tt := range tests { |
| 66 | t.Run(tt.name, func(t *testing.T) { |
| 67 | err := validateWithSchema(tt.frontmatter, tt.schema, tt.context) |
| 68 | |
| 69 | if tt.wantErr && err == nil { |
nothing calls this directly
no test coverage detected