From 4c32cd432a3af47e53b2bbdb76e7dd0fce4ae471 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 4 May 2017 13:01:05 -0400 Subject: [PATCH] make getProvider pluggable --- command/init.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/command/init.go b/command/init.go index 7008bb6e0c..b3d816c31d 100644 --- a/command/init.go +++ b/command/init.go @@ -19,6 +19,12 @@ import ( // module and clones it to the working directory. type InitCommand struct { Meta + + // getProvider fetches providers that aren't found locally, and unpacks + // them into the dst directory. + // This uses discovery.GetProvider by default, but it provided here as a + // way to mock fetching providers for tests. + getProvider func(dst, provider string, req discovery.Constraints) error } func (c *InitCommand) Run(args []string) int { @@ -41,6 +47,11 @@ func (c *InitCommand) Run(args []string) int { return 1 } + // set getProvider if we don't have a test version already + if c.getProvider == nil { + c.getProvider = discovery.GetProvider + } + // Validate the arg count args = cmdFlags.Args() if len(args) > 2 { @@ -210,7 +221,7 @@ func (c *InitCommand) getProviders(path string, state *terraform.State) error { dst := c.pluginDir() for provider, reqd := range missing { - err := discovery.GetProvider(dst, provider, reqd) + err := c.getProvider(dst, provider, reqd) // TODO: return all errors if err != nil { return err