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