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