Improve D&D validation reliability
This commit is contained in:
@@ -66,6 +66,27 @@ func TestValidatorRegistersStrictOptionsAndPolicy(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidatorReportsEveryDuplicateSubjectWithContext(t *testing.T) {
|
||||
value := events(
|
||||
event("Ashfang", dnd.EnemyEventKindEngaged, 1),
|
||||
event("Ashfang", dnd.EnemyEventKindEngaged, 2),
|
||||
event("Briar", dnd.EnemyEventKindEngaged, 3),
|
||||
event("Briar", dnd.EnemyEventKindEngaged, 4),
|
||||
)
|
||||
result, err := New(Options{}).Validate(context.Background(), contracts.TypedValidationRequest[dnd.EnemyEventList]{Value: value})
|
||||
if err != nil || result.Approved {
|
||||
t.Fatalf("Validate() = %#v, %v; want rejection", result, err)
|
||||
}
|
||||
for _, want := range []string{"Ashfang", "Briar", "source unit 1", "source unit 2", "source unit 3", "source unit 4"} {
|
||||
if !strings.Contains(result.CorrectionGuidance, want) {
|
||||
t.Fatalf("CorrectionGuidance = %q, want %q", result.CorrectionGuidance, want)
|
||||
}
|
||||
}
|
||||
if strings.Contains(result.CorrectionGuidance, "events[") || strings.Contains(result.CorrectionGuidance, ReasonCode) {
|
||||
t.Fatalf("CorrectionGuidance exposed internal diagnostics: %q", result.CorrectionGuidance)
|
||||
}
|
||||
}
|
||||
|
||||
func events(values ...dnd.EnemyEvent) dnd.EnemyEventList { return dnd.EnemyEventList{Events: values} }
|
||||
|
||||
func event(name string, kind dnd.EnemyEventKind, unitID int) dnd.EnemyEvent {
|
||||
|
||||
Reference in New Issue
Block a user