File: read_test.go

package info (click to toggle)
golang-github-tcnksm-go-input 0.0~git20180404.548a7d7-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 136 kB
  • sloc: makefile: 20
file content (52 lines) | stat: -rw-r--r-- 844 bytes parent folder | download
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)
		}
	}
}