template: ParseFile

pull/2134/head
Mitchell Hashimoto 11 years ago
parent d74dacc4c0
commit 97a48e35bb

@ -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)
}

@ -1,7 +1,6 @@
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)
}

Loading…
Cancel
Save