packer: add mock implementations and more template tests

This commit is contained in:
Mitchell Hashimoto
2013-08-22 11:32:59 -07:00
parent cfb53005ff
commit cc0f91b41b
3 changed files with 106 additions and 0 deletions
+37
View File
@@ -1,9 +1,46 @@
package command
import (
"github.com/mitchellh/packer/packer"
"testing"
)
func testTemplate() (*packer.Template, *packer.ComponentFinder) {
tplData := `{
"builders": [
{
"type": "foo"
},
{
"type": "bar"
}
]
}`
tpl, err := packer.ParseTemplate([]byte(tplData))
if err != nil {
panic(err)
}
cf := &packer.ComponentFinder{
Builder: func(string) (packer.Builder, error) { return new(packer.MockBuilder), nil },
}
return tpl, cf
}
func TestBuildOptionsBuilds(t *testing.T) {
opts := new(BuildOptions)
bs, err := opts.Builds(testTemplate())
if err != nil {
t.Fatalf("err: %s", err)
}
if len(bs) != 2 {
t.Fatalf("bad: %d", len(bs))
}
}
func TestBuildOptionsValidate(t *testing.T) {
bf := new(BuildOptions)