-
Notifications
You must be signed in to change notification settings - Fork 2k
/
testing.go
75 lines (62 loc) · 1.87 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package catalog
import (
testing "github.com/mitchellh/go-testing-interface"
"github.com/hashicorp/nomad/helper/pluginutils/loader"
"github.com/hashicorp/nomad/helper/testlog"
"github.com/hashicorp/nomad/nomad/structs/config"
)
// TestPluginLoader returns a plugin loader populated only with internal plugins
func TestPluginLoader(t testing.T) loader.PluginCatalog {
driverConfigs := []*config.PluginConfig{
{
Name: "raw_exec",
Config: map[string]interface{}{
"enabled": true,
},
},
}
return TestPluginLoaderWithOptions(t, "", nil, driverConfigs)
}
// TestPluginLoaderWithOptions allows configuring the plugin loader fully.
func TestPluginLoaderWithOptions(t testing.T,
pluginDir string,
options map[string]string,
configs []*config.PluginConfig) loader.PluginCatalog {
// Get a logger
logger := testlog.HCLogger(t)
// Get the registered plugins
catalog := Catalog()
// Create our map of plugins
internal := make(map[loader.PluginID]*loader.InternalPluginConfig, len(catalog))
for id, reg := range catalog {
if reg.Config == nil {
logger.Warn("skipping loading internal plugin because it is missing its configuration", "plugin", id)
continue
}
pluginConfig := reg.Config.Config
if reg.ConfigLoader != nil {
pc, err := reg.ConfigLoader(options)
if err != nil {
t.Fatalf("failed to retrieve config for internal plugin %v: %v", id, err)
}
pluginConfig = pc
}
internal[id] = &loader.InternalPluginConfig{
Factory: reg.Config.Factory,
Config: pluginConfig,
}
}
// Build the plugin loader
config := &loader.PluginLoaderConfig{
Logger: logger,
PluginDir: "",
Configs: configs,
InternalPlugins: internal,
SupportedVersions: loader.AgentSupportedApiVersions,
}
l, err := loader.NewPluginLoader(config)
if err != nil {
t.Fatalf("failed to create plugin loader: %v", err)
}
return l
}