forked from google/gops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
80 lines (75 loc) · 1.5 KB
/
main_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
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"testing"
"time"
)
func Test_shortenVersion(t *testing.T) {
tests := []struct {
version string
want string
}{
{
version: "go1.8.1.typealias",
want: "go1.8.1.typealias",
},
{
version: "go1.9",
want: "go1.9",
},
{
version: "go1.9rc",
want: "go1.9rc",
},
{
version: "devel +990dac2723 Fri Jun 30 18:24:58 2017 +0000",
want: "devel +990dac2723",
},
}
for _, tt := range tests {
t.Run(tt.version, func(t *testing.T) {
if got := shortenVersion(tt.version); got != tt.want {
t.Errorf("shortenVersion() = %v, want %v", got, tt.want)
}
})
}
}
func Test_fmtEtimeDuration(t *testing.T) {
tests := []struct {
d time.Duration
want string
}{
{
want: "00:00",
},
{
d: 2*time.Minute + 5*time.Second + 400*time.Millisecond,
want: "02:05",
},
{
d: 1*time.Second + 500*time.Millisecond,
want: "00:02",
},
{
d: 2*time.Hour + 42*time.Minute + 12*time.Second,
want: "02:42:12",
},
{
d: 24 * time.Hour,
want: "01-00:00:00",
},
{
d: 24*time.Hour + 59*time.Minute + 59*time.Second,
want: "01-00:59:59",
},
}
for _, tt := range tests {
t.Run(tt.d.String(), func(t *testing.T) {
if got := fmtEtimeDuration(tt.d); got != tt.want {
t.Errorf("fmtEtimeDuration() = %v, want %v", got, tt.want)
}
})
}
}