From 5a9e0cf763fa97e47e059e5375c03953912df1d8 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Fri, 5 Jan 2018 10:59:30 -0500 Subject: [PATCH] create a new InternalProviders test Remove the legacy InternalProviders global. The terraform provider is the only one run internally. --- command/internal_plugin.go | 10 ---------- command/internal_plugin_list.go | 2 -- command/internal_plugin_test.go | 29 ++++++++++++++++++++--------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/command/internal_plugin.go b/command/internal_plugin.go index 01d8c77b9..b26ba1df6 100644 --- a/command/internal_plugin.go +++ b/command/internal_plugin.go @@ -45,16 +45,6 @@ func (c *InternalPluginCommand) Run(args []string) int { log.SetPrefix(fmt.Sprintf("%s-%s (internal) ", pluginName, pluginType)) switch pluginType { - case "provider": - pluginFunc, found := InternalProviders[pluginName] - if !found { - log.Printf("[ERROR] Could not load provider: %s", pluginName) - return 1 - } - log.Printf("[INFO] Starting provider plugin %s", pluginName) - plugin.Serve(&plugin.ServeOpts{ - ProviderFunc: pluginFunc, - }) case "provisioner": pluginFunc, found := InternalProvisioners[pluginName] if !found { diff --git a/command/internal_plugin_list.go b/command/internal_plugin_list.go index 7993e9a54..b7f998ebd 100644 --- a/command/internal_plugin_list.go +++ b/command/internal_plugin_list.go @@ -14,8 +14,6 @@ import ( "github.com/hashicorp/terraform/plugin" ) -var InternalProviders = map[string]plugin.ProviderFunc{} - var InternalProvisioners = map[string]plugin.ProvisionerFunc{ "chef": chefprovisioner.Provisioner, "file": fileprovisioner.Provisioner, diff --git a/command/internal_plugin_test.go b/command/internal_plugin_test.go index 8f9338ddf..f96b5feae 100644 --- a/command/internal_plugin_test.go +++ b/command/internal_plugin_test.go @@ -2,15 +2,26 @@ package command import "testing" -// providers are all external for now -//func TestInternalPlugin_InternalProviders(t *testing.T) { -// // Note this is a randomish sample and does not check for all plugins -// for _, name := range []string{"atlas", "consul", "docker", "template"} { -// if _, ok := InternalProviders[name]; !ok { -// t.Errorf("Expected to find %s in InternalProviders", name) -// } -// } -//} +func TestInternalPlugin_InternalProviders(t *testing.T) { + m := new(Meta) + providers := m.internalProviders() + // terraform is the only provider moved back to internal + for _, name := range []string{"terraform"} { + pf, ok := providers[name] + if !ok { + t.Errorf("Expected to find %s in InternalProviders", name) + } + + provider, err := pf() + if err != nil { + t.Fatal(err) + } + + if provider == nil { + t.Fatal("provider factory returned a nil provider") + } + } +} func TestInternalPlugin_InternalProvisioners(t *testing.T) { for _, name := range []string{"chef", "file", "local-exec", "remote-exec", "salt-masterless"} {