Tighten NPC interaction validation and consistency
This commit is contained in:
@@ -2,9 +2,12 @@ package diagnostics
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"unicode/utf8"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
)
|
||||
|
||||
func TestAggregateEnforcesByteBudgetAndReportsOmissions(t *testing.T) {
|
||||
@@ -26,3 +29,25 @@ func TestAggregateEnforcesByteBudgetAndReportsOmissions(t *testing.T) {
|
||||
t.Fatalf("Aggregate() = %q, want %q", message, wantOmitted)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLimitWarningsBoundsOutputAndReportsOmissions(t *testing.T) {
|
||||
warnings := make([]contracts.Warning, MaxWarnings+3)
|
||||
for index := range warnings {
|
||||
warnings[index] = contracts.Warning{ReasonCode: fmt.Sprintf("warning-%d", index)}
|
||||
}
|
||||
before := append([]contracts.Warning(nil), warnings...)
|
||||
|
||||
got := LimitWarnings(warnings, "records", "warnings_omitted")
|
||||
if len(got) != MaxWarnings {
|
||||
t.Fatalf("LimitWarnings() count = %d, want %d", len(got), MaxWarnings)
|
||||
}
|
||||
summary := got[len(got)-1]
|
||||
wantOmitted := len(warnings) - (MaxWarnings - 1)
|
||||
if summary.Scope != "records" || summary.ReasonCode != "warnings_omitted" ||
|
||||
summary.Message != fmt.Sprintf("%d additional warning(s) omitted", wantOmitted) {
|
||||
t.Fatalf("summary = %#v", summary)
|
||||
}
|
||||
if !reflect.DeepEqual(warnings, before) {
|
||||
t.Fatal("LimitWarnings() mutated its input")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user