forked from mercari/tfnotify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tee_test.go
39 lines (36 loc) · 802 Bytes
/
tee_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
package main
import (
"bytes"
"io"
"testing"
)
func TestTee(t *testing.T) {
testCases := []struct {
stdin io.Reader
stdout string
body string
}{
{
// Regular
stdin: bytes.NewBufferString("Plan: 1 to add\n"),
stdout: "Plan: 1 to add\n",
body: "Plan: 1 to add\n",
},
{
// ANSI color codes are included
stdin: bytes.NewBufferString("\033[mPlan: 1 to add\033[m\n"),
stdout: "\033[mPlan: 1 to add\033[m\n",
body: "Plan: 1 to add\n",
},
}
for _, testCase := range testCases {
stdout := new(bytes.Buffer)
body := tee(testCase.stdin, stdout)
if body != testCase.body {
t.Errorf("got %q but want %q", body, testCase.body)
}
if stdout.String() != testCase.stdout {
t.Errorf("got %q but want %q", stdout.String(), testCase.stdout)
}
}
}