Preserve selected collections in materialized references
This commit is contained in:
@@ -1,6 +1,31 @@
|
||||
package shared
|
||||
|
||||
import "gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
)
|
||||
|
||||
// ValidateReferenceSelections rejects collection metadata on non-glossary inputs.
|
||||
func ValidateReferenceSelections(references contracts.ReferenceSet) error {
|
||||
names := make([]string, 0, len(references.Slots))
|
||||
for name := range references.Slots {
|
||||
names = append(names, name)
|
||||
}
|
||||
sort.Strings(names)
|
||||
for _, name := range names {
|
||||
if name == "glossary" || name == "spell_catalog" {
|
||||
continue
|
||||
}
|
||||
for _, item := range references.Slots[name].Items {
|
||||
if item.Collections != nil {
|
||||
return fmt.Errorf("reference slot %q does not support collection selection", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type ReferenceSlotDescriptions struct {
|
||||
Glossary string
|
||||
|
||||
@@ -2,11 +2,27 @@ package shared
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
)
|
||||
|
||||
func TestValidateReferenceSelections(t *testing.T) {
|
||||
for _, slot := range []string{"party", "roster", "players", "npc_registry"} {
|
||||
references := contracts.ReferenceSet{Slots: map[string]contracts.ResolvedReferenceSlot{slot: {Items: []contracts.ReferenceItem{{Collections: []string{}}}}}}
|
||||
if err := ValidateReferenceSelections(references); err == nil || !strings.Contains(err.Error(), slot) {
|
||||
t.Fatalf("slot %s: error = %v", slot, err)
|
||||
}
|
||||
}
|
||||
for _, slot := range []string{"glossary", "spell_catalog"} {
|
||||
references := contracts.ReferenceSet{Slots: map[string]contracts.ResolvedReferenceSlot{slot: {Items: []contracts.ReferenceItem{{Collections: []string{"chosen"}}}}}}
|
||||
if err := ValidateReferenceSelections(references); err != nil {
|
||||
t.Fatalf("slot %s: %v", slot, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestReferenceMediaTypesReturnsDefensiveCopy(t *testing.T) {
|
||||
want := []string{
|
||||
"application/json",
|
||||
|
||||
Reference in New Issue
Block a user