-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtemplates_test.go
72 lines (61 loc) · 1.79 KB
/
templates_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
70
71
72
package integration
import (
"fmt"
"os/exec"
"reflect"
"testing"
"github.com/lucapette/fakedata/testutil"
)
var templateTests = []struct {
tmpl string
golden string
wantErr bool
}{
{"simple.tmpl", "simple-template.golden", false},
{"loop.tmpl", "loop.golden", false},
{"loop-with-index.tmpl", "loop-with-index.golden", false},
{"broken.tmpl", "broken-template.golden", true},
{"unknown-function.tmpl", "unknown-function.golden", true},
}
func TestTemplatesWithCLIArgs(t *testing.T) {
for _, tt := range templateTests {
t.Run(tt.tmpl, func(t *testing.T) {
cmd := exec.Command(binaryPath, "--template", fmt.Sprintf("testutil/fixtures/%s", tt.tmpl))
output, err := cmd.CombinedOutput()
if (err != nil) != tt.wantErr {
t.Fatalf("%s\nexpected (err != nil) to be %v, but got %v. err: %v", output, tt.wantErr, err != nil, err)
}
golden := testutil.NewGoldenFile(t, tt.golden)
actual := string(output)
if *update {
golden.Write(actual)
}
expected := golden.Load()
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("diff: %v", testutil.Diff(expected, actual))
}
})
}
}
func TestTemplatesWithPipe(t *testing.T) {
for _, tt := range templateTests {
t.Run(tt.tmpl, func(t *testing.T) {
fixture := testutil.NewFixture(t, tt.tmpl)
cmd := exec.Command(binaryPath)
cmd.Stdin = fixture.AsFile()
output, err := cmd.CombinedOutput()
if (err != nil) != tt.wantErr {
t.Fatalf("%s\nexpected (err != nil) to be %v, but got %v. err: %v", output, tt.wantErr, err != nil, err)
}
golden := testutil.NewGoldenFile(t, tt.golden)
actual := string(output)
if *update {
golden.Write(actual)
}
expected := golden.Load()
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("diff: %v", testutil.Diff(expected, actual))
}
})
}
}