]>
Commit | Line | Data |
---|---|---|
bae9f6d2 JC |
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 | } |