Complete shared domain contract verification
This commit is contained in:
@@ -51,6 +51,9 @@ func New(_ Options, references ...contracts.ReferenceSet) (*Normalizer, error) {
|
||||
if len(references) == 1 {
|
||||
referenceSet = references[0]
|
||||
}
|
||||
if err := shared.ValidateReferenceSelections(referenceSet); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
npcResolver, err := npcregistry.NewResolver(referenceSet)
|
||||
if err != nil {
|
||||
return nil, normalizerErrorf("prepare NPC registry: %w", err)
|
||||
@@ -298,9 +301,6 @@ func Register(registry *pipeline.NormalizerRegistry) error {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := shared.ValidateReferenceSelections(request.References); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return New(options, request.References)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -49,6 +49,9 @@ func New(_ Options, references ...contracts.ReferenceSet) (*Normalizer, error) {
|
||||
if len(references) == 1 {
|
||||
referenceSet = references[0]
|
||||
}
|
||||
if err := shared.ValidateReferenceSelections(referenceSet); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resolver, err := npcregistry.NewResolver(referenceSet)
|
||||
if err != nil {
|
||||
return nil, normalizerErrorf("prepare NPC registry: %w", err)
|
||||
@@ -262,9 +265,6 @@ func Register(registry *pipeline.NormalizerRegistry) error {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := shared.ValidateReferenceSelections(request.References); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return New(options, request.References)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -48,6 +48,9 @@ func New(_ Options, references ...contracts.ReferenceSet) (*Normalizer, error) {
|
||||
if len(references) == 1 {
|
||||
referenceSet = references[0]
|
||||
}
|
||||
if err := shared.ValidateReferenceSelections(referenceSet); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resolver, err := itemregistry.NewResolver(referenceSet)
|
||||
if err != nil {
|
||||
return nil, normalizerErrorf("prepare item registry: %w", err)
|
||||
@@ -269,9 +272,6 @@ func Register(registry *pipeline.NormalizerRegistry) error {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := shared.ValidateReferenceSelections(request.References); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return New(options, request.References)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package itemoccurrences
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
|
||||
@@ -13,6 +14,14 @@ import (
|
||||
itemidentity "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/items/identity"
|
||||
)
|
||||
|
||||
func TestConstructionRejectsCollectionSelectionOnRegistry(t *testing.T) {
|
||||
refs := registryReferences(t)
|
||||
refs.Slots[ItemRegistryReferenceSlot].Items[0].Collections = []string{}
|
||||
if _, err := New(Options{}, refs); err == nil || !strings.Contains(err.Error(), ItemRegistryReferenceSlot) {
|
||||
t.Fatalf("expected registry selection error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func registryReferences(t *testing.T) contracts.ReferenceSet {
|
||||
t.Helper()
|
||||
content, err := itemcodec.New().Encode(dnd.ItemRegistry{Items: []dnd.Item{{ID: itemidentity.DeriveID("Torch"), Name: "Torch", SourceRefs: []source.SourceRef{{SourceID: "session", StartUnitID: 1, EndUnitID: 1}}}}})
|
||||
|
||||
@@ -51,6 +51,9 @@ func New(_ Options, references ...contracts.ReferenceSet) (*Normalizer, error) {
|
||||
if len(references) == 1 {
|
||||
referenceSet = references[0]
|
||||
}
|
||||
if err := shared.ValidateReferenceSelections(referenceSet); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resolver, err := locationregistry.NewResolver(referenceSet)
|
||||
if err != nil {
|
||||
return nil, normalizerErrorf("prepare location registry: %w", err)
|
||||
@@ -320,9 +323,6 @@ func Register(registry *pipeline.NormalizerRegistry) error {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := shared.ValidateReferenceSelections(request.References); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return New(options, request.References)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -48,6 +48,9 @@ func New(_ Options, references ...contracts.ReferenceSet) (*Normalizer, error) {
|
||||
if len(references) == 1 {
|
||||
referenceSet = references[0]
|
||||
}
|
||||
if err := shared.ValidateReferenceSelections(referenceSet); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resolver, err := npcregistry.NewResolver(referenceSet)
|
||||
if err != nil {
|
||||
return nil, normalizerErrorf("prepare NPC registry: %w", err)
|
||||
@@ -239,9 +242,6 @@ func Register(registry *pipeline.NormalizerRegistry) error {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := shared.ValidateReferenceSelections(request.References); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return New(options, request.References)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -46,6 +46,9 @@ func New(_ Options, references ...contracts.ReferenceSet) (*Normalizer, error) {
|
||||
if len(references) == 1 {
|
||||
referenceSet = references[0]
|
||||
}
|
||||
if err := shared.ValidateReferenceSelections(referenceSet); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
effectiveCatalog, err := spellcatalog.ResolveEffectiveCatalog(referenceSet)
|
||||
if err != nil {
|
||||
return nil, normalizerErrorf("resolve effective spell catalog: %w", err)
|
||||
@@ -256,9 +259,6 @@ func Register(registry *pipeline.NormalizerRegistry) error {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := shared.ValidateReferenceSelections(request.References); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return New(options, request.References)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ func TestModuleContractAndStrictOptions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewBuildsEmbeddedAndOverlayCatalogs(t *testing.T) {
|
||||
func TestNewBuildsEmbeddedAndSharedGlossaryCatalogs(t *testing.T) {
|
||||
base, err := New(Options{})
|
||||
if err != nil {
|
||||
t.Fatalf("New() error = %v, want nil", err)
|
||||
@@ -69,15 +69,15 @@ func TestNewBuildsEmbeddedAndOverlayCatalogs(t *testing.T) {
|
||||
t.Fatalf("apostrophe lookup = %q, %t, want canonical curly apostrophe spelling", canonical, ok)
|
||||
}
|
||||
|
||||
overlay, err := New(Options{}, overlayReference())
|
||||
sharedGlossary, err := New(Options{}, sharedGlossaryReference())
|
||||
if err != nil {
|
||||
t.Fatalf("New(overlay) error = %v, want nil", err)
|
||||
t.Fatalf("New(shared glossary) error = %v, want nil", err)
|
||||
}
|
||||
if got := overlay.effectiveCatalog.CollectionNames(); !reflect.DeepEqual(got, []string{"spells"}) {
|
||||
if got := sharedGlossary.effectiveCatalog.CollectionNames(); !reflect.DeepEqual(got, []string{"spells"}) {
|
||||
t.Fatalf("collection names = %#v, want spells", got)
|
||||
}
|
||||
if canonical, ok := overlay.effectiveCatalog.Lookup(" emberfall aegis "); !ok || canonical != "Aegis of Emberfall" {
|
||||
t.Fatalf("overlay alias lookup = %q, %t, want Aegis of Emberfall", canonical, ok)
|
||||
if canonical, ok := sharedGlossary.effectiveCatalog.Lookup(" emberfall aegis "); !ok || canonical != "Aegis of Emberfall" {
|
||||
t.Fatalf("shared glossary alias lookup = %q, %t, want Aegis of Emberfall", canonical, ok)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ func TestNewRejectsInvalidCatalogReferencesDuringConstruction(t *testing.T) {
|
||||
t.Fatalf("New(invalid reference) error = %v, want media type failure", err)
|
||||
}
|
||||
|
||||
tooMany := overlayReference()
|
||||
tooMany := sharedGlossaryReference()
|
||||
slot := tooMany.Slots[spellcatalog.SpellCatalogReferenceSlot]
|
||||
slot.Items = append(slot.Items, slot.Items[0])
|
||||
tooMany.Slots[spellcatalog.SpellCatalogReferenceSlot] = slot
|
||||
@@ -452,7 +452,7 @@ func TestNormalizeDuplicateOutputDoesNotShareInputSlices(t *testing.T) {
|
||||
|
||||
func newNormalizer(t *testing.T) *Normalizer {
|
||||
t.Helper()
|
||||
normalizer, err := New(Options{}, overlayReference())
|
||||
normalizer, err := New(Options{}, sharedGlossaryReference())
|
||||
if err != nil {
|
||||
t.Fatalf("New() error = %v, want nil", err)
|
||||
}
|
||||
@@ -502,7 +502,7 @@ func diagnosticByReason(diagnostics []contracts.ProducerDiagnostic, reason strin
|
||||
return nil
|
||||
}
|
||||
|
||||
func overlayReference() contracts.ReferenceSet {
|
||||
func sharedGlossaryReference() contracts.ReferenceSet {
|
||||
return spellCatalogReference(`{"schema_version":"maximumdirect.glossary.v1","collections":{"spells":{"entries":[{"id":"aegis","name":"Aegis of Emberfall","category":"spell","aliases":["Emberfall Aegis"]}]}}}`)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user