Introduce typed D&D spell artifacts
This commit is contained in:
@@ -353,10 +353,48 @@ func TestExtractorRegistryBuildRejectsEmptyKey(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractorRegistryTypedRegistrationCanProvideRawAdapter(t *testing.T) {
|
||||
registry := NewExtractorRegistry()
|
||||
spec := ModuleSpec{Key: "typed-extractor", Stage: StageExtract, ArtifactKind: "test/value"}
|
||||
if err := RegisterExtractorBuilderWithRawAdapter(registry, spec, func(map[string]any) error { return nil },
|
||||
func(BuildRequest) (contracts.Extractor[registryTypedValue], error) {
|
||||
return registryTypedExtractor{key: spec.Key}, nil
|
||||
},
|
||||
func(BuildRequest) (contracts.LegacyRawExtractor, error) {
|
||||
return registryFakeExtractor{key: spec.Key}, nil
|
||||
},
|
||||
); err != nil {
|
||||
t.Fatalf("RegisterExtractorBuilderWithRawAdapter() error = %v", err)
|
||||
}
|
||||
if !registry.usesRawAdapter(spec.Key) {
|
||||
t.Fatal("usesRawAdapter() = false, want true")
|
||||
}
|
||||
if _, ok := registry.typedEntry(spec.Key); !ok {
|
||||
t.Fatal("typedEntry() ok = false, want true")
|
||||
}
|
||||
adapter, err := registry.BuildLegacyRaw(spec.Key)
|
||||
if err != nil || adapter.Key() != spec.Key {
|
||||
t.Fatalf("BuildLegacyRaw() = %#v, %v", adapter, err)
|
||||
}
|
||||
if err := RegisterExtractorBuilderWithRawAdapter[registryTypedValue](NewExtractorRegistry(), spec, func(map[string]any) error { return nil }, nil, nil); err == nil || !strings.Contains(err.Error(), "raw adapter") {
|
||||
t.Fatalf("nil raw builder error = %v, want raw adapter context", err)
|
||||
}
|
||||
}
|
||||
|
||||
type registryFakeExtractor struct {
|
||||
key string
|
||||
}
|
||||
|
||||
type registryTypedValue struct{ Value string }
|
||||
|
||||
type registryTypedExtractor struct{ key string }
|
||||
|
||||
func (extractor registryTypedExtractor) Key() string { return extractor.key }
|
||||
func (registryTypedExtractor) ReferenceSlots() []contracts.ReferenceSlot { return nil }
|
||||
func (registryTypedExtractor) Extract(context.Context, contracts.TypedExtractionRequest) (contracts.TypedExtractionResult[registryTypedValue], error) {
|
||||
return contracts.TypedExtractionResult[registryTypedValue]{}, nil
|
||||
}
|
||||
|
||||
func fakeExtractorConstructor(key string) LegacyRawExtractorConstructor {
|
||||
return func() (contracts.LegacyRawExtractor, error) {
|
||||
return registryFakeExtractor{key: key}, nil
|
||||
|
||||
Reference in New Issue
Block a user