summaryrefslogtreecommitdiff
path: root/common/pretty/duration_test.go
blob: 94ea2c50af9e74455a1bc4109e951f2f9cc3c9a5 (plain)
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
package pretty

import (
	"testing"
	"time"
)

func TestDuration(t *testing.T) {
	type args struct {
		duration time.Duration
	}
	tests := []struct {
		name string
		args args
		want string
	}{
		{
			name: "zero",
			args: args{0},
			want: "00:00:00",
		},
		{
			name: "1s",
			args: args{time.Second},
			want: "00:00:01",
		},
		{
			name: "2s",
			args: args{time.Second * 2},
			want: "00:00:02",
		},
		{
			name: "59s",
			args: args{time.Second * 59},
			want: "00:00:59",
		},
		{
			name: "1m",
			args: args{time.Second * 60},
			want: "00:01:00",
		},
		{
			name: "1m1s",
			args: args{time.Second * 61},
			want: "00:01:01",
		},
		{
			name: "1h",
			args: args{time.Second * 3600},
			want: "01:00:00",
		},
		{
			name: "54h7m13s",
			args: args{time.Hour*54 + time.Minute*7 + time.Second*13},
			want: "54:07:13",
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if got := Duration(tt.args.duration); got != tt.want {
				t.Errorf("Duration() = %v, want %v", got, tt.want)
			}
		})
	}
}