github.com/bigcommerce/nomad@v0.9.3-bc/helper/pluginutils/catalog/testing.go (about) 1 package catalog 2 3 import ( 4 testing "github.com/mitchellh/go-testing-interface" 5 6 "github.com/hashicorp/nomad/helper/pluginutils/loader" 7 "github.com/hashicorp/nomad/helper/testlog" 8 "github.com/hashicorp/nomad/nomad/structs/config" 9 ) 10 11 // TestPluginLoader returns a plugin loader populated only with internal plugins 12 func TestPluginLoader(t testing.T) loader.PluginCatalog { 13 return TestPluginLoaderWithOptions(t, "", nil, nil) 14 } 15 16 // TestPluginLoaderWithOptions allows configuring the plugin loader fully. 17 func TestPluginLoaderWithOptions(t testing.T, 18 pluginDir string, 19 options map[string]string, 20 configs []*config.PluginConfig) loader.PluginCatalog { 21 22 // Get a logger 23 logger := testlog.HCLogger(t) 24 25 // Get the registered plugins 26 catalog := Catalog() 27 28 // Create our map of plugins 29 internal := make(map[loader.PluginID]*loader.InternalPluginConfig, len(catalog)) 30 31 for id, reg := range catalog { 32 if reg.Config == nil { 33 logger.Warn("skipping loading internal plugin because it is missing its configuration", "plugin", id) 34 continue 35 } 36 37 pluginConfig := reg.Config.Config 38 if reg.ConfigLoader != nil { 39 pc, err := reg.ConfigLoader(options) 40 if err != nil { 41 t.Fatalf("failed to retrieve config for internal plugin %v: %v", id, err) 42 } 43 44 pluginConfig = pc 45 } 46 47 internal[id] = &loader.InternalPluginConfig{ 48 Factory: reg.Config.Factory, 49 Config: pluginConfig, 50 } 51 } 52 53 // Build the plugin loader 54 config := &loader.PluginLoaderConfig{ 55 Logger: logger, 56 PluginDir: "", 57 Configs: configs, 58 InternalPlugins: internal, 59 SupportedVersions: loader.AgentSupportedApiVersions, 60 } 61 l, err := loader.NewPluginLoader(config) 62 if err != nil { 63 t.Fatalf("failed to create plugin loader: %v", err) 64 } 65 66 return l 67 }