diff options
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/config/module/testing.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/config/module/testing.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/terraform/config/module/testing.go b/vendor/github.com/hashicorp/terraform/config/module/testing.go new file mode 100644 index 0000000..fc9e733 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/config/module/testing.go | |||
@@ -0,0 +1,38 @@ | |||
1 | package module | ||
2 | |||
3 | import ( | ||
4 | "io/ioutil" | ||
5 | "os" | ||
6 | "testing" | ||
7 | |||
8 | "github.com/hashicorp/go-getter" | ||
9 | ) | ||
10 | |||
11 | // TestTree loads a module at the given path and returns the tree as well | ||
12 | // as a function that should be deferred to clean up resources. | ||
13 | func TestTree(t *testing.T, path string) (*Tree, func()) { | ||
14 | // Create a temporary directory for module storage | ||
15 | dir, err := ioutil.TempDir("", "tf") | ||
16 | if err != nil { | ||
17 | t.Fatalf("err: %s", err) | ||
18 | return nil, nil | ||
19 | } | ||
20 | |||
21 | // Load the module | ||
22 | mod, err := NewTreeModule("", path) | ||
23 | if err != nil { | ||
24 | t.Fatalf("err: %s", err) | ||
25 | return nil, nil | ||
26 | } | ||
27 | |||
28 | // Get the child modules | ||
29 | s := &getter.FolderStorage{StorageDir: dir} | ||
30 | if err := mod.Load(s, GetModeGet); err != nil { | ||
31 | t.Fatalf("err: %s", err) | ||
32 | return nil, nil | ||
33 | } | ||
34 | |||
35 | return mod, func() { | ||
36 | os.RemoveAll(dir) | ||
37 | } | ||
38 | } | ||