forked from hashicorp/otto
/
testing_appfile.go
65 lines (56 loc) · 1.41 KB
/
testing_appfile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package otto
import (
"io/ioutil"
"path/filepath"
"github.com/hashicorp/otto/appfile"
"github.com/hashicorp/otto/appfile/detect"
)
// TestAppfile returns a compiled appfile for the given path. This uses
// defaults for detectors and such so it is up to you to use a fairly
// complete Appfile.
func TestAppfile(t TestT, path string) *appfile.Compiled {
def, err := appfile.Default(filepath.Dir(path), &detect.Config{
Detectors: []*detect.Detector{
&detect.Detector{
Type: "test",
File: []string{"Appfile"},
},
},
})
if err != nil {
t.Fatal("err: ", err)
}
// Default type should be "test"
def.Infrastructure[0].Type = "test"
def.Infrastructure[0].Flavor = "test"
def.Infrastructure[0].Foundations = nil
// Parse the raw file
f, err := appfile.ParseFile(path)
if err != nil {
t.Fatal("err: ", err)
}
// Merge
if err := def.Merge(f); err != nil {
t.Fatal("err: ", err)
}
f = def
// Create a temporary directory for the compilation data. We don't
// delete this now in case we're using any of that data, but the
// temp dir should get cleaned up by the system at some point.
td, err := ioutil.TempDir("", "otto")
if err != nil {
t.Fatal("err: ", err)
}
// Compile it!
compiler, err := appfile.NewCompiler(&appfile.CompileOpts{
Dir: td,
})
if err != nil {
t.Fatal("err: ", err)
}
result, err := compiler.Compile(f)
if err != nil {
t.Fatal("err: ", err)
}
return result
}