forked from cli/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiostreams_test.go
More file actions
68 lines (66 loc) · 1.34 KB
/
iostreams_test.go
File metadata and controls
68 lines (66 loc) · 1.34 KB
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
package iostreams
import (
"errors"
"testing"
)
func TestIOStreams_ForceTerminal(t *testing.T) {
tests := []struct {
name string
iostreams *IOStreams
arg string
wantTTY bool
wantWidth int
}{
{
name: "explicit width",
iostreams: &IOStreams{},
arg: "72",
wantTTY: true,
wantWidth: 72,
},
{
name: "measure width",
iostreams: &IOStreams{
ttySize: func() (int, int, error) {
return 72, 0, nil
},
},
arg: "true",
wantTTY: true,
wantWidth: 72,
},
{
name: "measure width fails",
iostreams: &IOStreams{
ttySize: func() (int, int, error) {
return -1, -1, errors.New("ttySize sabotage!")
},
},
arg: "true",
wantTTY: true,
wantWidth: 80,
},
{
name: "apply percentage",
iostreams: &IOStreams{
ttySize: func() (int, int, error) {
return 72, 0, nil
},
},
arg: "50%",
wantTTY: true,
wantWidth: 36,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.iostreams.ForceTerminal(tt.arg)
if isTTY := tt.iostreams.IsStdoutTTY(); isTTY != tt.wantTTY {
t.Errorf("IOStreams.IsStdoutTTY() = %v, want %v", isTTY, tt.wantTTY)
}
if tw := tt.iostreams.TerminalWidth(); tw != tt.wantWidth {
t.Errorf("IOStreams.TerminalWidth() = %v, want %v", tw, tt.wantWidth)
}
})
}
}