Files
archie/internal/plugin/pluginextract/pluginextract_test.go
T
sam 1b0133d7b7 refactor(plugin): delete the unused Registry type
Registry carried no plugin identity, discovery, compatibility or
lifecycle, so it was never the seed for the approved internal/domain/plugin
package. Host, Manifest and Module are, and they stay.

Regenerating pluginextract strips the interface-wrapper nil guards, so
those are restored by hand; the only intended change to the generated
table is dropping the Registry symbol.
2026-09-20 11:38:15 +10:00

59 lines
1.7 KiB
Go

package pluginextract
import (
"reflect"
"testing"
)
func TestSymbolsContainsExpectedPluginEntries(t *testing.T) {
pkgKey := "github.com/samcharles93/archie-core/internal/plugin/plugin"
pkg, ok := Symbols[pkgKey]
if !ok {
t.Fatalf("Symbols missing key %q", pkgKey)
}
// LoadDir must be a function.
if v, ok := pkg["LoadDir"]; !ok {
t.Error("LoadDir missing from Symbols")
} else if v.Kind() != reflect.Func {
t.Errorf("LoadDir kind = %v, want Func", v.Kind())
}
// Plugin must be a pointer type.
if v, ok := pkg["Plugin"]; !ok {
t.Error("Plugin missing from Symbols")
} else if v.Kind() != reflect.Pointer {
t.Errorf("Plugin kind = %v, want Ptr", v.Kind())
}
}
func TestGeneratedWrapperHasNilGuards(t *testing.T) {
// Regression: go generate strips nil-guards from _Plugin wrapper.
// Verify that Plugin is present in the Symbols table and is an
// interface type (as expected for yaegi interface extraction).
pkgKey := "github.com/samcharles93/archie-core/internal/plugin/plugin"
pkg := Symbols[pkgKey]
pluginType, ok := pkg["Plugin"]
if !ok {
t.Fatal("Plugin missing from Symbols")
}
// Plugin is an interface type — yaegi represents interfaces
// differently from struct pointers.
kind := pluginType.Kind()
if kind != reflect.Interface && kind != reflect.Pointer {
t.Errorf("Plugin type kind = %v, want Interface or Ptr", kind)
}
// Verify WName and WVersion exist on the Plugin interface type.
// For interface types, we check the method set.
if kind == reflect.Interface {
methodCount := pluginType.Type().NumMethod()
if methodCount < 2 {
t.Errorf("Plugin interface has %d methods, expected at least 2 (Name, Version)", methodCount)
}
}
}