Commit 643d9033 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: add ParseTemplateFile since that is useful

parent 88d27453
......@@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"github.com/mitchellh/mapstructure"
"io/ioutil"
"sort"
)
......@@ -255,6 +256,17 @@ func ParseTemplate(data []byte) (t *Template, err error) {
return
}
// ParseTemplateFile takes the given template file and parses it into
// a single template.
func ParseTemplateFile(path string) (*Template, error) {
data, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
return ParseTemplate(data)
}
func parsePostProvisioner(i int, rawV interface{}) (result []map[string]interface{}, errors []error) {
switch v := rawV.(type) {
case string:
......
......@@ -2,6 +2,7 @@ package packer
import (
"cgl.tideland.biz/asserts"
"io/ioutil"
"reflect"
"sort"
"testing"
......@@ -18,6 +19,30 @@ func testComponentFinder() *ComponentFinder {
}
}
func TestParseTemplateFile_basic(t *testing.T) {
data := `
{
"builders": [{"type": "something"}]
}
`
tf, err := ioutil.TempFile("", "packer")
if err != nil {
t.Fatalf("err: %s", err)
}
tf.Write([]byte(data))
tf.Close()
result, err := ParseTemplateFile(tf.Name())
if err != nil {
t.Fatalf("err: %s", err)
}
if len(result.Builders) != 1 {
t.Fatalf("bad: %#v", result.Builders)
}
}
func TestParseTemplate_Basic(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment