Commit 97a48e35 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

template: ParseFile

parent d74dacc4
......@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"io"
"os"
"sort"
"github.com/hashicorp/go-multierror"
......@@ -290,3 +291,15 @@ func Parse(r io.Reader) (*Template, error) {
// Return the template parsed from the raw structure
return rawTpl.Template()
}
// ParseFile is the same as Parse but is a helper to automatically open
// a file for parsing.
func ParseFile(path string) (*Template, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
return Parse(f)
}
package template
import (
"os"
"reflect"
"testing"
"time"
......@@ -272,13 +271,7 @@ func TestParse(t *testing.T) {
}
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()
tpl, err := ParseFile(fixtureDir(tc.File))
if (err != nil) != tc.Err {
t.Fatalf("err: %s", err)
}
......
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