forked from tcnksm/go-input
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathread_test.go
52 lines (45 loc) · 844 Bytes
/
read_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
package input
import (
"bytes"
"io"
"io/ioutil"
"testing"
)
func TestRead(t *testing.T) {
cases := []struct {
opts *readOptions
userInput io.Reader
expect string
}{
{
opts: &readOptions{
mask: false,
maskVal: "",
},
userInput: bytes.NewBufferString("passw0rd"),
expect: "passw0rd",
},
{
opts: &readOptions{
mask: false,
maskVal: "",
},
userInput: bytes.NewBufferString("taichi nakashima"),
expect: "taichi nakashima",
},
// No good way to test masking...
}
for i, tc := range cases {
ui := &UI{
Writer: ioutil.Discard,
Reader: tc.userInput,
}
out, err := ui.read(tc.opts)
if err != nil {
t.Fatalf("#%d expect not to be error: %s", i, err)
}
if out != tc.expect {
t.Fatalf("#%d expect %q to be eq %q", i, out, tc.expect)
}
}
}