forked from garetht/amanar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate_flow_test.go
69 lines (64 loc) · 1.77 KB
/
template_flow_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package amanar
import (
"bytes"
"os"
"testing"
)
func TestTemplateFlow_PersistChanges(t *testing.T) {
type fields struct {
credentials *Credentials
source *TemplateSource
}
strBuf := bytes.NewBuffer([]byte{})
s := "Hello from {{.Username}} and {{.Password}}"
templSource, _ := NewTemplateSourceFromString(&s, strBuf)
fileBuf := bytes.NewBuffer([]byte{})
wd, _ := os.Getwd()
path := wd + "/example/example_template_file.go.md"
fileSource, err := NewTemplateSourceFromFile(&path, fileBuf)
if err != nil {
print("hello")
}
tests := []struct {
name string
buffer *bytes.Buffer
fields fields
wantErr error
wantOutput string
}{
{name: "Can write a string template to a writer",
buffer: strBuf,
fields: struct {
credentials *Credentials
source *TemplateSource
}{credentials: &Credentials{Username: "uname", Password: "password"}, source: templSource},
wantErr: nil,
wantOutput: "Hello from uname and password"},
{name: "Can write a file template to stdout",
buffer: fileBuf,
fields: struct {
credentials *Credentials
source *TemplateSource
}{credentials: &Credentials{Username: "firstname", Password: "secondname"}, source: fileSource},
wantErr: nil,
wantOutput: `Template
===
The credentials are firstname and secondname
`},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tf := &TemplateFlow{
credentials: tt.fields.credentials,
source: tt.fields.source,
}
if err := tf.PersistChanges(); err != tt.wantErr {
t.Errorf("PersistChanges() error = %v, wantErr %v", err, tt.wantErr)
}
output := tt.buffer.String()
if output != tt.wantOutput {
t.Errorf("output error, received output = %v, want output = %v", output, tt.wantOutput)
}
})
}
}