github.com/bigcommerce/nomad@v0.9.3-bc/client/pluginmanager/drivermanager/testing.go (about) 1 // +build !release 2 3 package drivermanager 4 5 import ( 6 "fmt" 7 "testing" 8 9 log "github.com/hashicorp/go-hclog" 10 "github.com/hashicorp/nomad/helper/pluginutils/catalog" 11 "github.com/hashicorp/nomad/helper/pluginutils/loader" 12 "github.com/hashicorp/nomad/helper/pluginutils/singleton" 13 "github.com/hashicorp/nomad/helper/testlog" 14 "github.com/hashicorp/nomad/plugins/base" 15 "github.com/hashicorp/nomad/plugins/drivers" 16 ) 17 18 type testManager struct { 19 logger log.Logger 20 loader loader.PluginCatalog 21 } 22 23 func TestDriverManager(t *testing.T) Manager { 24 logger := testlog.HCLogger(t).Named("driver_mgr") 25 pluginLoader := catalog.TestPluginLoader(t) 26 return &testManager{ 27 logger: logger, 28 loader: singleton.NewSingletonLoader(logger, pluginLoader), 29 } 30 } 31 32 func (m *testManager) Run() {} 33 func (m *testManager) Shutdown() {} 34 func (m *testManager) PluginType() string { return base.PluginTypeDriver } 35 36 func (m *testManager) Dispense(driver string) (drivers.DriverPlugin, error) { 37 instance, err := m.loader.Dispense(driver, base.PluginTypeDriver, nil, m.logger) 38 if err != nil { 39 return nil, err 40 } 41 42 d, ok := instance.Plugin().(drivers.DriverPlugin) 43 if !ok { 44 return nil, fmt.Errorf("plugin does not implement DriverPlugin interface") 45 } 46 47 return d, nil 48 } 49 50 func (m *testManager) RegisterEventHandler(driver, taskID string, handler EventHandler) {} 51 func (m *testManager) DeregisterEventHandler(driver, taskID string) {}