packer-cn/template/template_test.go

75 lines
1.0 KiB
Go
Raw Normal View History

2015-05-19 17:25:56 -04:00
package template
import (
2015-05-21 17:29:45 -04:00
"os"
2015-05-19 17:25:56 -04:00
"path/filepath"
2015-05-21 17:29:45 -04:00
"testing"
2015-05-19 17:25:56 -04:00
)
const FixturesDir = "./test-fixtures"
// fixtureDir returns the path to a test fixtures directory
func fixtureDir(n string) string {
return filepath.Join(FixturesDir, n)
}
2015-05-21 17:29:45 -04:00
func TestTemplateValidate(t *testing.T) {
cases := []struct {
File string
Err bool
}{
{
"validate-no-builders.json",
true,
},
{
"validate-bad-override.json",
true,
},
{
"validate-good-override.json",
false,
},
2015-05-21 17:39:32 -04:00
{
"validate-bad-prov-only.json",
true,
},
{
"validate-good-prov-only.json",
false,
},
{
"validate-bad-prov-except.json",
true,
},
{
"validate-good-prov-except.json",
false,
},
2015-05-21 17:29:45 -04:00
}
for _, tc := range cases {
f, err := os.Open(fixtureDir(tc.File))
if err != nil {
t.Fatalf("err: %s", err)
}
tpl, err := Parse(f)
f.Close()
if err != nil {
t.Fatalf("err: %s\n\n%s", tc.File, err)
}
err = tpl.Validate()
if (err != nil) != tc.Err {
t.Fatalf("err: %s\n\n%s", tc.File, err)
}
}
}