forked from derailed/k9s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers_test.go
89 lines (78 loc) · 1.74 KB
/
helpers_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
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of K9s
package model1
import (
"math"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSortLabels(t *testing.T) {
uu := map[string]struct {
labels string
e [][]string
}{
"simple": {
labels: "a=b,c=d",
e: [][]string{
{"a", "c"},
{"b", "d"},
},
},
}
for k := range uu {
u := uu[k]
t.Run(k, func(t *testing.T) {
hh, vv := sortLabels(labelize(u.labels))
assert.Equal(t, u.e[0], hh)
assert.Equal(t, u.e[1], vv)
})
}
}
func TestLabelize(t *testing.T) {
uu := map[string]struct {
labels string
e map[string]string
}{
"simple": {
labels: "a=b,c=d",
e: map[string]string{"a": "b", "c": "d"},
},
}
for k := range uu {
u := uu[k]
t.Run(k, func(t *testing.T) {
assert.Equal(t, u.e, labelize(u.labels))
})
}
}
func TestDurationToSecond(t *testing.T) {
uu := map[string]struct {
s string
e int64
}{
"seconds": {s: "22s", e: 22},
"minutes": {s: "22m", e: 1320},
"hours": {s: "12h", e: 43200},
"days": {s: "3d", e: 259200},
"day_hour": {s: "3d9h", e: 291600},
"day_hour_minute": {s: "2d22h3m", e: 252180},
"day_hour_minute_seconds": {s: "2d22h3m50s", e: 252230},
"year": {s: "3y", e: 94608000},
"year_day": {s: "1y2d", e: 31708800},
"n/a": {s: NAValue, e: math.MaxInt64},
}
for k := range uu {
u := uu[k]
t.Run(k, func(t *testing.T) {
assert.Equal(t, u.e, durationToSeconds(u.s))
})
}
}
func BenchmarkDurationToSecond(b *testing.B) {
t := "2d22h3m50s"
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
durationToSeconds(t)
}
}