Skip to content

Commit

Permalink
Cover pipe templates too
Browse files Browse the repository at this point in the history
  • Loading branch information
lucapette committed Jun 22, 2017
1 parent 37b4202 commit 1e05268
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
44 changes: 44 additions & 0 deletions integration/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ func (tf *testFile) write(content string) {
}
}

func (tf *testFile) asFile() *os.File {
file, err := os.Open(tf.path())
if err != nil {
tf.t.Fatalf("could not open %s: %v", tf.name, err)
}
return file
}

func (tf *testFile) load() string {
content, err := ioutil.ReadFile(tf.path())
if err != nil {
Expand Down Expand Up @@ -235,6 +243,42 @@ func TestTemplatesWithCLIArgs(t *testing.T) {
}
}

func TestTemplatesWithPipe(t *testing.T) {
tests := []struct {
tmpl string
golden string
wantErr bool
}{
{"simple.tmpl", "simple-template-pipe.golden", false},
{"broken.tmpl", "broken-template-pipe.golden", true},
{"unknown-function.tmpl", "unknown-function-pipe.golden", true},
}

for _, tt := range tests {
t.Run(tt.tmpl, func(t *testing.T) {
fixture := 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 := newGoldenFile(t, tt.golden)
actual := string(output)
if *update {
golden.write(actual)
}

expected := golden.load()

if !reflect.DeepEqual(actual, expected) {
t.Fatalf("diff: %v", diff(expected, actual))
}
})
}
}

func TestMain(m *testing.M) {
err := os.Chdir("..")
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions integration/golden/broken-template-pipe.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
template: stdin:1: unexpected "}" in operand
1 change: 1 addition & 0 deletions integration/golden/simple-template-pipe.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
42--foo42--foo42--foo42--foo42--foo42--foo42--foo42--foo42--foo42--foo
1 change: 1 addition & 0 deletions integration/golden/unknown-function-pipe.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
template: stdin:1: function "Madeup" not defined

0 comments on commit 1e05268

Please sign in to comment.