Strengthen Notarius determinism tests
This commit is contained in:
@@ -297,37 +297,87 @@ func TestNotariusValidationFailureDoesNotMutateConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNotariusNormalizationIsIndependentOfMapInsertionOrder(t *testing.T) {
|
func TestNotariusNormalizationProducesCanonicalValues(t *testing.T) {
|
||||||
first := validNotariusConfig()
|
cfg := validNotariusConfig()
|
||||||
first.References = make(map[string]string)
|
cfg.References = map[string]string{
|
||||||
first.References[" party "] = " narratio.input.party "
|
" party ": " narratio.input.party ",
|
||||||
first.References["chunk . players"] = " narratio.input.players "
|
"chunk . players": " narratio.input.players ",
|
||||||
first.Outputs = make(map[string]NotariusOutputConfig)
|
|
||||||
first.Outputs[" npc_registry "] = NotariusOutputConfig{
|
|
||||||
LaneID: " npc-registry ", MediaType: " application/json ",
|
|
||||||
SchemaID: " notarius.dnd.npc_registry ", SchemaVersion: " v1 ",
|
|
||||||
}
|
}
|
||||||
first.Outputs["spells"] = NotariusOutputConfig{
|
cfg.Outputs = map[string]NotariusOutputConfig{
|
||||||
LaneID: " spells ", MediaType: " application/json ",
|
" npc_registry ": {
|
||||||
SchemaID: " notarius.dnd.spells ", SchemaVersion: " v1 ",
|
LaneID: " npc-registry ", MediaType: " application/json ",
|
||||||
|
SchemaID: " notarius.dnd.npc_registry ", SchemaVersion: " v1 ",
|
||||||
|
},
|
||||||
|
"spells": {
|
||||||
|
LaneID: " spells ", MediaType: " application/json ",
|
||||||
|
SchemaID: " notarius.dnd.spells ", SchemaVersion: " v1 ",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
second := validNotariusConfig()
|
if err := validateNotarius(cfg, nil); err != nil {
|
||||||
second.References = make(map[string]string)
|
t.Fatalf("validateNotarius() error = %v", err)
|
||||||
second.References["chunk . players"] = " narratio.input.players "
|
}
|
||||||
second.References[" party "] = " narratio.input.party "
|
wantReferences := map[string]string{
|
||||||
second.Outputs = make(map[string]NotariusOutputConfig)
|
"party": "narratio.input.party",
|
||||||
second.Outputs["spells"] = first.Outputs["spells"]
|
"chunk.players": "narratio.input.players",
|
||||||
second.Outputs[" npc_registry "] = first.Outputs[" npc_registry "]
|
}
|
||||||
|
if !reflect.DeepEqual(cfg.References, wantReferences) {
|
||||||
|
t.Fatalf("references = %#v, want %#v", cfg.References, wantReferences)
|
||||||
|
}
|
||||||
|
if _, ok := cfg.Outputs[" npc_registry "]; ok {
|
||||||
|
t.Fatal("outputs retain unnormalized key")
|
||||||
|
}
|
||||||
|
if got := cfg.Outputs["npc_registry"]; got.LaneID != "npc-registry" || got.MediaType != "application/json" || got.SchemaID != "notarius.dnd.npc_registry" || got.SchemaVersion != "v1" {
|
||||||
|
t.Fatalf("normalized npc_registry output = %#v", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := validateNotarius(first, nil); err != nil {
|
func TestNotariusDiagnosticsUseSortedMapKeys(t *testing.T) {
|
||||||
t.Fatalf("validateNotarius(first) error = %v", err)
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
configure func(*NotariusConfig, []string)
|
||||||
|
wantField string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "references",
|
||||||
|
configure: func(cfg *NotariusConfig, keys []string) {
|
||||||
|
cfg.References = make(map[string]string, len(keys))
|
||||||
|
for _, key := range keys {
|
||||||
|
cfg.References[key] = "narratio.input.unsupported"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
wantField: "pipeline.notarius.references.alpha",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "outputs",
|
||||||
|
configure: func(cfg *NotariusConfig, keys []string) {
|
||||||
|
cfg.References = nil
|
||||||
|
cfg.Outputs = make(map[string]NotariusOutputConfig, len(keys))
|
||||||
|
for _, key := range keys {
|
||||||
|
cfg.Outputs[key] = NotariusOutputConfig{LaneID: key}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
wantField: "pipeline.notarius.outputs.alpha.media_type",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
if err := validateNotarius(second, nil); err != nil {
|
|
||||||
t.Fatalf("validateNotarius(second) error = %v", err)
|
for _, test := range tests {
|
||||||
}
|
t.Run(test.name, func(t *testing.T) {
|
||||||
if !reflect.DeepEqual(first, second) {
|
orders := [][]string{{"zeta", "alpha"}, {"alpha", "zeta"}}
|
||||||
t.Fatalf("normalized configs differ:\nfirst: %#v\nsecond: %#v", first, second)
|
diagnostics := make([]string, 0, len(orders))
|
||||||
|
for _, keys := range orders {
|
||||||
|
cfg := validNotariusConfig()
|
||||||
|
test.configure(cfg, keys)
|
||||||
|
err := validateNotarius(cfg, nil)
|
||||||
|
if err == nil || !strings.Contains(err.Error(), test.wantField) {
|
||||||
|
t.Fatalf("validateNotarius() error = %v, want field %q", err, test.wantField)
|
||||||
|
}
|
||||||
|
diagnostics = append(diagnostics, err.Error())
|
||||||
|
}
|
||||||
|
if diagnostics[0] != diagnostics[1] {
|
||||||
|
t.Fatalf("equivalent maps produced different diagnostics:\nfirst: %s\nsecond: %s", diagnostics[0], diagnostics[1])
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user