]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blame - vendor/github.com/hashicorp/terraform/config/module/testing.go
Merge branch 'fix_read_test' of github.com:alexandreFre/terraform-provider-statuscake
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / terraform / config / module / testing.go
CommitLineData
bae9f6d2
JC
1package module
2
3import (
4 "io/ioutil"
5 "os"
6 "testing"
bae9f6d2
JC
7)
8
9// TestTree loads a module at the given path and returns the tree as well
10// as a function that should be deferred to clean up resources.
11func TestTree(t *testing.T, path string) (*Tree, func()) {
12 // Create a temporary directory for module storage
13 dir, err := ioutil.TempDir("", "tf")
14 if err != nil {
15 t.Fatalf("err: %s", err)
16 return nil, nil
17 }
18
19 // Load the module
20 mod, err := NewTreeModule("", path)
21 if err != nil {
22 t.Fatalf("err: %s", err)
23 return nil, nil
24 }
25
26 // Get the child modules
15c0b25d
AP
27 s := &Storage{StorageDir: dir, Mode: GetModeGet}
28 if err := mod.Load(s); err != nil {
bae9f6d2
JC
29 t.Fatalf("err: %s", err)
30 return nil, nil
31 }
32
33 return mod, func() {
34 os.RemoveAll(dir)
35 }
36}