github.com/yandex/pandora@v0.5.32/core/plugin/plugin_test.go (about) 1 package plugin 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestDefaultRegistry(t *testing.T) { 10 beforeEach := func() { Register(ptestType(), ptestPluginName, ptestNewImpl) } 11 afterEach := func() { defaultRegistry = NewRegistry() } 12 13 t.Run("lookup", func(t *testing.T) { 14 defer afterEach() 15 beforeEach() 16 assert.True(t, Lookup(ptestType())) 17 }) 18 t.Run("lookup factory", func(t *testing.T) { 19 defer afterEach() 20 beforeEach() 21 assert.True(t, LookupFactory(ptestNewErrType())) 22 }) 23 t.Run("new", func(t *testing.T) { 24 defer afterEach() 25 beforeEach() 26 plugin, err := New(ptestType(), ptestPluginName) 27 assert.NoError(t, err) 28 assert.NotNil(t, plugin) 29 }) 30 t.Run("new factory", func(t *testing.T) { 31 defer afterEach() 32 beforeEach() 33 pluginFactory, err := NewFactory(ptestNewErrType(), ptestPluginName) 34 assert.NoError(t, err) 35 assert.NotNil(t, pluginFactory) 36 }) 37 } 38 39 func TestTypeHelpers(t *testing.T) { 40 t.Run("ptr type", func(t *testing.T) { 41 var plugin ptestPlugin 42 assert.Equal(t, ptestType(), PtrType(&plugin)) 43 }) 44 t.Run("factory plugin type ok", func(t *testing.T) { 45 factoryPlugin, ok := FactoryPluginType(ptestNewErrType()) 46 assert.True(t, ok) 47 assert.Equal(t, ptestType(), factoryPlugin) 48 }) 49 }