-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
34 lines (29 loc) · 853 Bytes
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main
import (
"bytes"
"io/ioutil"
"log"
"os"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestParsetemplate(t *testing.T) {
Convey("Check that parsetemplate returns a bytes.buffer of rendered template", t, func() {
os.Setenv("FOO", "bar")
tmpDir, _ := ioutil.TempDir("/tmp/", "envtoconf")
tmpfile, _ := ioutil.TempFile(tmpDir, "template")
defer os.RemoveAll(tmpDir)
file := tmpfile.Name()
testdata := `home path is: {{env "HOME"}} and foo: {{env "FOO"}}`
if err := ioutil.WriteFile(file, []byte(testdata), 0644); err != nil {
t.Fatalf("WriteFile %s: %v", file, err)
}
log.Printf("File is: %s\n", file)
data, err := parsetemplate(file)
if err != nil {
log.Fatalf("%s\n", err)
}
So(data, ShouldHaveSameTypeAs, new(bytes.Buffer))
So(data.String(), ShouldContainSubstring, `bar`)
})
}