From 9ba39d93b7ad9f544a737e27fb0a11d44dfeeddc Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 24 Sep 2014 14:23:29 -0700 Subject: [PATCH] helper/resource: compile --- helper/resource/testing.go | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/helper/resource/testing.go b/helper/resource/testing.go index 2b0a2231f..89b73e200 100644 --- a/helper/resource/testing.go +++ b/helper/resource/testing.go @@ -6,10 +6,11 @@ import ( "io/ioutil" "log" "os" + "path/filepath" "strings" "testing" - "github.com/hashicorp/terraform/config" + "github.com/hashicorp/terraform/config/module" "github.com/hashicorp/terraform/terraform" ) @@ -149,22 +150,19 @@ func testStep( opts terraform.ContextOpts, state *terraform.State, step TestStep) (*terraform.State, error) { - // Write the configuration - cfgF, err := ioutil.TempFile("", "tf-test") + cfgPath, err := ioutil.TempDir("", "tf-test") if err != nil { return state, fmt.Errorf( - "Error creating temporary file for config: %s", err) + "Error creating temporary directory for config: %s", err) } - cfgPath := cfgF.Name() + ".tf" - cfgF.Close() - os.Remove(cfgF.Name()) + defer os.RemoveAll(cfgPath) - cfgF, err = os.Create(cfgPath) + // Write the configuration + cfgF, err := os.Create(filepath.Join(cfgPath, "main.tf")) if err != nil { return state, fmt.Errorf( "Error creating temporary file for config: %s", err) } - defer os.Remove(cfgPath) _, err = io.Copy(cfgF, strings.NewReader(step.Config)) cfgF.Close() @@ -174,14 +172,23 @@ func testStep( } // Parse the configuration - config, err := config.Load(cfgPath) + mod, err := module.NewTreeModule("", cfgPath) if err != nil { return state, fmt.Errorf( - "Error parsing configuration: %s", err) + "Error loading configuration: %s", err) + } + + // Load the modules + modStorage := &module.FolderStorage{ + StorageDir: filepath.Join(cfgPath, ".tfmodules"), + } + err = mod.Load(modStorage, module.GetModeGet) + if err != nil { + return state, fmt.Errorf("Error downloading modules: %s", err) } // Build the context - opts.Config = config + opts.Module = mod opts.State = state ctx := terraform.NewContext(&opts) if ws, es := ctx.Validate(); len(ws) > 0 || len(es) > 0 {