make getProvider pluggable

This commit is contained in:
James Bardin 2017-05-04 13:01:05 -04:00 committed by Martin Atkins
parent 66ebff90cd
commit 4c32cd432a
1 changed files with 12 additions and 1 deletions

View File

@ -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