(t *testing.T)
| 22 | const schemaFile = "../../agent-schema.json" |
| 23 | |
| 24 | func TestJsonSchemaWorksForExamples(t *testing.T) { |
| 25 | t.Parallel() |
| 26 | |
| 27 | schemaFile, err := os.ReadFile(schemaFile) |
| 28 | require.NoError(t, err) |
| 29 | |
| 30 | schema, err := gojsonschema.NewSchema(gojsonschema.NewBytesLoader(schemaFile)) |
| 31 | require.NoError(t, err) |
| 32 | |
| 33 | for _, file := range collectExamples(t) { |
| 34 | t.Run(file, func(t *testing.T) { |
| 35 | t.Parallel() |
| 36 | |
| 37 | buf, err := os.ReadFile(file) |
| 38 | require.NoError(t, err) |
| 39 | |
| 40 | // HCL examples are converted to their YAML equivalent before |
| 41 | // being validated against the JSON schema, since the schema |
| 42 | // describes the YAML/JSON representation only. |
| 43 | if filepath.Ext(file) == ".hcl" { |
| 44 | buf, err = hclconv.ToYAML(buf, file) |
| 45 | require.NoError(t, err) |
| 46 | } |
| 47 | |
| 48 | var rawJSON any |
| 49 | err = yaml.Unmarshal(buf, &rawJSON) |
| 50 | require.NoError(t, err) |
| 51 | |
| 52 | result, err := schema.Validate(gojsonschema.NewRawLoader(rawJSON)) |
| 53 | require.NoError(t, err) |
| 54 | assert.True(t, result.Valid(), "Example %s does not match schema: %v", file, result.Errors()) |
| 55 | }) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | // TestSchemaMatchesGoTypes verifies that every JSON-tagged field in the Go |
| 60 | // config structs has a corresponding property in agent-schema.json (and |
nothing calls this directly
no test coverage detected