Finalize structured diagnostic aggregation
This commit is contained in:
@@ -12,24 +12,24 @@ import (
|
||||
|
||||
func TestExecuteValidationChainSettlesEveryValidatorInOrder(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
chain preparedValidatorChain
|
||||
invoke validationInvoker
|
||||
want []validationOutcome
|
||||
wantCalls []string
|
||||
wantGuidance []string
|
||||
wantWarnings []string
|
||||
name string
|
||||
chain preparedValidatorChain
|
||||
invoke validationInvoker
|
||||
want []validationOutcome
|
||||
wantCalls []string
|
||||
wantGuidance []string
|
||||
wantDiagnostics []string
|
||||
}{
|
||||
{
|
||||
name: "all approved",
|
||||
chain: validationChain(validationSpec("shape", contracts.ExecutionClassDeterministic, 0), validationSpec("refs", contracts.ExecutionClassDeterministic, 0)),
|
||||
invoke: validationSequence(map[string][]validationStep{
|
||||
"shape": {{result: contracts.ValidationResult{Approved: true, Warnings: []contracts.Warning{{ReasonCode: "shape"}}}}},
|
||||
"refs": {{result: contracts.ValidationResult{Approved: true, Warnings: []contracts.Warning{{ReasonCode: "refs"}}}}},
|
||||
"shape": {{result: contracts.ValidationResult{Approved: true, Diagnostics: []contracts.ProducerDiagnostic{validationDiagnostic("shape")}}}},
|
||||
"refs": {{result: contracts.ValidationResult{Approved: true, Diagnostics: []contracts.ProducerDiagnostic{validationDiagnostic("refs")}}}},
|
||||
}),
|
||||
want: []validationOutcome{validationApproved, validationApproved},
|
||||
wantCalls: []string{"shape:1", "refs:1"},
|
||||
wantWarnings: []string{"shape", "refs"},
|
||||
want: []validationOutcome{validationApproved, validationApproved},
|
||||
wantCalls: []string{"shape:1", "refs:1"},
|
||||
wantDiagnostics: []string{"shape", "refs"},
|
||||
},
|
||||
{
|
||||
name: "multiple rejections deduplicate guidance",
|
||||
@@ -117,13 +117,13 @@ func TestExecuteValidationChainSettlesEveryValidatorInOrder(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
warnings := report.Warnings()
|
||||
var warningCodes []string
|
||||
for _, warning := range warnings {
|
||||
warningCodes = append(warningCodes, warning.ReasonCode)
|
||||
diagnostics := report.Diagnostics()
|
||||
var diagnosticCodes []string
|
||||
for _, record := range diagnostics {
|
||||
diagnosticCodes = append(diagnosticCodes, record.diagnostic.ReasonCode)
|
||||
}
|
||||
if !reflect.DeepEqual(warningCodes, test.wantWarnings) {
|
||||
t.Fatalf("Warnings() = %#v, want codes %#v", warnings, test.wantWarnings)
|
||||
if !reflect.DeepEqual(diagnosticCodes, test.wantDiagnostics) {
|
||||
t.Fatalf("Diagnostics() = %#v, want codes %#v", diagnostics, test.wantDiagnostics)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -158,14 +158,24 @@ func TestValidationReportRejectsOversizedGuidanceAndOwnsRecords(t *testing.T) {
|
||||
unique[0] = byte('a' + index)
|
||||
report.records[index] = validationRecord{validatorName: "validator", outcome: validationRejected, correctionGuidance: string(unique)}
|
||||
}
|
||||
report.records[0].warnings = []contracts.Warning{{ReasonCode: "warning"}}
|
||||
report.records[0].diagnostics = []contracts.ProducerDiagnostic{validationDiagnostic("diagnostic")}
|
||||
if _, err := report.CorrectionRequest(); err == nil {
|
||||
t.Fatal("CorrectionRequest() error = nil, want aggregate overflow error")
|
||||
}
|
||||
records := report.Records()
|
||||
records[0].warnings[0].ReasonCode = "changed"
|
||||
if report.Records()[0].warnings[0].ReasonCode != "warning" {
|
||||
t.Fatal("Records() exposed mutable warning storage")
|
||||
records[0].diagnostics[0].ReasonCode = "changed"
|
||||
if report.Records()[0].diagnostics[0].ReasonCode != "diagnostic" {
|
||||
t.Fatal("Records() exposed mutable diagnostic storage")
|
||||
}
|
||||
}
|
||||
|
||||
func validationDiagnostic(reasonCode string) contracts.ProducerDiagnostic {
|
||||
return contracts.ProducerDiagnostic{
|
||||
Disposition: contracts.DiagnosticDispositionObservation,
|
||||
Category: contracts.DiagnosticCategoryNormalization,
|
||||
ReasonCode: reasonCode,
|
||||
OccurrenceCount: 1,
|
||||
Samples: []contracts.DiagnosticSample{{Scope: "validator", Message: reasonCode}},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user