-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathutils_test.go
61 lines (58 loc) · 1.13 KB
/
utils_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
package qb
import (
"testing"
"time"
)
func TestFormatDuration(t *testing.T) {
tests := []struct {
name string
input time.Duration
expected string
}{
{
name: "Zero duration",
input: 0,
expected: "",
},
{
input: 500 * time.Millisecond,
expected: "500ms",
},
{
input: 10 * time.Second,
expected: "10s",
},
{
input: 3 * time.Minute,
expected: "3m",
},
{
input: (2 * time.Minute) + (30 * time.Second),
expected: "2m30s",
},
{
input: (15 * time.Second) + (250 * time.Millisecond),
expected: "15s250ms",
},
{
input: (1 * time.Minute) + (45 * time.Second) + (123 * time.Millisecond),
expected: "1m45s123ms",
},
{
input: (5 * time.Minute) + (1 * time.Second) + (999 * time.Millisecond),
expected: "5m1s999ms",
},
{
input: (2 * time.Second) + (1500 * time.Millisecond), // 3 seconds, 500ms
expected: "3s500ms",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actual := formatDuration(tt.input)
if actual != tt.expected {
t.Errorf("got %q, want %q", actual, tt.expected)
}
})
}
}