Summary
Extract the repeated schema compilation and validation boilerplate into a reusable test helper function.
Related: #118, #140, #141, #142
Problem
The schema compilation and validation pattern is repeated 7 times across internal/report/report_test.go (lines 215-241, 354-378, 416-441, 448-460, 465-527, 533-597, 604-667). Each instance has the same boilerplate:
sch, err := jsonschema.UnmarshalJSON(strings.NewReader(schemaJSON))
// error check
compiler := jsonschema.NewCompiler()
err = compiler.AddResource("schema.json", sch)
// error check
compiled, err := compiler.Compile("schema.json")
// error check
err = compiled.Validate(document)
// error check
With #140 (QualitySchema exposure), #141 (CRAPSchema), and #142 (round-trip tests), this count will grow to 12-15+ instances.
Proposed Change
Extract a test helper:
func compileSchema(t *testing.T, schemaJSON string) *jsonschema.Schema {
t.Helper()
sch, err := jsonschema.UnmarshalJSON(strings.NewReader(schemaJSON))
if err != nil {
t.Fatalf("failed to parse schema JSON: %v", err)
}
compiler := jsonschema.NewCompiler()
if err := compiler.AddResource("schema.json", sch); err != nil {
t.Fatalf("failed to add schema resource: %v", err)
}
compiled, err := compiler.Compile("schema.json")
if err != nil {
t.Fatalf("failed to compile schema: %v", err)
}
return compiled
}
Uses standard library testing package only — no third-party assertion libraries.
Scope
Summary
Extract the repeated schema compilation and validation boilerplate into a reusable test helper function.
Related: #118, #140, #141, #142
Problem
The schema compilation and validation pattern is repeated 7 times across
internal/report/report_test.go(lines 215-241, 354-378, 416-441, 448-460, 465-527, 533-597, 604-667). Each instance has the same boilerplate:With #140 (QualitySchema exposure), #141 (CRAPSchema), and #142 (round-trip tests), this count will grow to 12-15+ instances.
Proposed Change
Extract a test helper:
Uses standard library
testingpackage only — no third-party assertion libraries.Scope
gaze schema crap#141, test: Add round-trip schema validation tests for QualitySchema #142) should use the helper from the start