-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate_test.go
48 lines (38 loc) · 1.07 KB
/
template_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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package duat
import (
"bytes"
"os/user"
"strings"
"testing"
"github.com/jjeffery/kv"
"github.com/go-stack/stack"
)
// This file contains a number of test functions for the templating features of duat
// TestUserTemplate exercises the user information functions in the templating
//
func TestUserTemplate(t *testing.T) {
md, err := NewMetaData(".", "README.md")
if err != nil {
t.Fatal(err)
}
reader := strings.NewReader("{{.duat.userID}}{{.duat.userName}}{{.duat.userGroupID}}")
writer := new(bytes.Buffer)
opts := TemplateOptions{
IOFiles: []TemplateIOFiles{{
In: reader,
Out: writer,
}},
OverrideValues: map[string]string{},
}
if err, _ = md.Template(opts); err != nil {
t.Fatal(err)
}
usr, errGo := user.Current()
if errGo != nil {
t.Fatal(kv.Wrap(errGo).With("stack", stack.Trace().TrimRuntime()))
}
expected := usr.Uid + usr.Username + usr.Gid
if expected != writer.String() {
t.Fatal(kv.NewError("templated user details incorrect").With("expected", expected, "actual", writer.String()).With("stack", stack.Trace().TrimRuntime()))
}
}