forked from grafana/k6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui_test.go
96 lines (88 loc) · 2.59 KB
/
ui_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
/*
*
* k6 - a next-generation load testing tool
* Copyright (C) 2019 Load Impact
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package cmd
import (
"fmt"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"go.k6.io/k6/ui/pb"
)
// Return progressbars with different content lengths, to test for
// padding.
func createTestProgressBars(num, padding, colIdx int) []*pb.ProgressBar {
pbs := make([]*pb.ProgressBar, num)
for i := 0; i < num; i++ {
left := fmt.Sprintf("left %d", i)
rightCol1 := fmt.Sprintf("right %d", i)
progress := 0.0
status := pb.Running
if i == colIdx {
pad := strings.Repeat("+", padding)
left += pad
rightCol1 += pad
progress = 1.0
status = pb.Done
}
pbs[i] = pb.New(
pb.WithLeft(func() string { return left }),
pb.WithStatus(status),
pb.WithProgress(func() (float64, []string) {
return progress, []string{rightCol1, "000"}
}),
)
}
return pbs
}
func TestRenderMultipleBars(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
padding int
widthDelta int
expOut string
expLongLine int
}{
{"pad0", 0, 0, `
left 0 [--------------------------------------] right 0 000
left 1 ✓ [======================================] right 1 000
left 2 [--------------------------------------] right 2 000
`, 62},
{"pad2", 2, 0, `
left 0 [--------------------------------------] right 0 000
left 1++ ✓ [======================================] right 1++ 000
left 2 [--------------------------------------] right 2 000
`, 66},
{"pad0compact", 0, -50, `
left 0 [ 0% ] right 0 000
left 1 ✓ [ 100% ] right 1 000
left 2 [ 0% ] right 2 000
`, 30},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
pbs := createTestProgressBars(3, tc.padding, 1)
out, longestLine := renderMultipleBars(false, false, 6+tc.padding, 80, tc.widthDelta, pbs)
assert.Equal(t, tc.expOut, out)
assert.Equal(t, tc.expLongLine, longestLine)
})
}
}