forked from pterm/pterm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
progressbar_printer_test.go
167 lines (130 loc) · 3.58 KB
/
progressbar_printer_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package pterm
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestProgressbarPrinter_Add(t *testing.T) {
proxyToDevNull()
p := DefaultProgressbar.WithTotal(2000)
p.Add(1337)
assert.Equal(t, 1337, p.Current)
p.Stop()
}
func TestProgressbarPrinter_AddTotalEqualsCurrent(t *testing.T) {
proxyToDevNull()
p := DefaultProgressbar.WithTotal(1)
p.Start()
p.Add(1)
assert.Equal(t, 1, p.Current)
assert.False(t, p.IsActive)
p.Stop()
}
func TestProgressbarPrinter_RemoveWhenDone(t *testing.T) {
proxyToDevNull()
p, err := DefaultProgressbar.WithTotal(2).WithRemoveWhenDone().Start()
assert.NoError(t, err)
p.Stop()
p.Add(1)
assert.Equal(t, 1, p.Current)
assert.False(t, p.IsActive)
}
func TestProgressbarPrinter_GenericStart(t *testing.T) {
p := DefaultProgressbar
p.GenericStart()
}
func TestProgressbarPrinter_GenericStartRawOutput(t *testing.T) {
DisableStyling()
p := DefaultProgressbar
p.GenericStart()
EnableStyling()
}
func TestProgressbarPrinter_GenericStop(t *testing.T) {
p, err := DefaultProgressbar.Start()
assert.NoError(t, err)
p.GenericStop()
}
func TestProgressbarPrinter_GetElapsedTime(t *testing.T) {
p := DefaultProgressbar
p.Start()
p.Stop()
assert.NotEmpty(t, p.GetElapsedTime())
}
func TestProgressbarPrinter_Increment(t *testing.T) {
p := DefaultProgressbar.WithTotal(2000)
p.Increment()
assert.Equal(t, 1, p.Current)
}
func TestProgressbarPrinter_WithBarStyle(t *testing.T) {
s := NewStyle(FgRed, BgBlue, Bold)
p := ProgressbarPrinter{}
p2 := p.WithBarStyle(s)
assert.Equal(t, s, p2.BarStyle)
}
func TestProgressbarPrinter_WithCurrent(t *testing.T) {
p := ProgressbarPrinter{}
p2 := p.WithCurrent(10)
assert.Equal(t, 10, p2.Current)
}
func TestProgressbarPrinter_WithElapsedTimeRoundingFactor(t *testing.T) {
p := ProgressbarPrinter{}
p2 := p.WithElapsedTimeRoundingFactor(time.Hour)
assert.Equal(t, time.Hour, p2.ElapsedTimeRoundingFactor)
}
func TestProgressbarPrinter_WithLastCharacter(t *testing.T) {
p := ProgressbarPrinter{}
p2 := p.WithLastCharacter(">")
assert.Equal(t, ">", p2.LastCharacter)
}
func TestProgressbarPrinter_WithBarCharacter(t *testing.T) {
p := ProgressbarPrinter{}
p2 := p.WithBarCharacter("-")
assert.Equal(t, "-", p2.BarCharacter)
}
func TestProgressbarPrinter_WithRemoveWhenDone(t *testing.T) {
p := ProgressbarPrinter{}
p2 := p.WithRemoveWhenDone()
assert.True(t, p2.RemoveWhenDone)
}
func TestProgressbarPrinter_WithShowCount(t *testing.T) {
p := ProgressbarPrinter{}
p2 := p.WithShowCount()
assert.True(t, p2.ShowCount)
}
func TestProgressbarPrinter_WithShowElapsedTime(t *testing.T) {
p := ProgressbarPrinter{}
p2 := p.WithShowElapsedTime()
assert.True(t, p2.ShowElapsedTime)
}
func TestProgressbarPrinter_WithShowPercentage(t *testing.T) {
p := ProgressbarPrinter{}
p2 := p.WithShowPercentage()
assert.True(t, p2.ShowPercentage)
}
func TestProgressbarPrinter_WithShowTitle(t *testing.T) {
p := ProgressbarPrinter{}
p2 := p.WithShowTitle()
assert.True(t, p2.ShowTitle)
}
func TestProgressbarPrinter_WithTitle(t *testing.T) {
p := ProgressbarPrinter{}
p2 := p.WithTitle("test")
assert.Equal(t, "test", p2.Title)
}
func TestProgressbarPrinter_WithTitleStyle(t *testing.T) {
s := NewStyle(FgRed, BgBlue, Bold)
p := ProgressbarPrinter{}
p2 := p.WithTitleStyle(s)
assert.Equal(t, s, p2.TitleStyle)
}
func TestProgressbarPrinter_WithTotal(t *testing.T) {
p := ProgressbarPrinter{}
p2 := p.WithTotal(1337)
assert.Equal(t, 1337, p2.Total)
}
func TestProgressbarPrinter_parseElapsedTime(t *testing.T) {
p := ProgressbarPrinter{}
p.Start()
p.Stop()
assert.NotEmpty(t, p.parseElapsedTime())
}