-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
76 lines (71 loc) · 1.46 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package finding
import (
"testing"
"time"
)
func TestToEbayDateTime(t *testing.T) {
tests := []struct {
input string
want string
}{
{
input: "2021/11/27T00/28/30.123",
want: "2021-11-27T00:28:30.123Z",
},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
dt, _ := time.Parse("2006/01/02T15/04/05.000", tt.input)
if got := ToEbayDateTime(dt); got != tt.want {
t.Errorf("ToEbayDateTime() = %v, want %v", got, tt.want)
}
})
}
}
func TestFromEbayDateTime(t *testing.T) {
tests := []struct {
input string
want string
}{
{
input: "2021-11-27T00:28:30.123Z",
want: "2021/11/27T00/28/30.123",
},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
dt, _ := FromEbayDateTime(tt.input)
datetime := dt.Format("2006/01/02T15/04/05.000")
if got := datetime; got != tt.want {
t.Errorf("FromEbayDateTime() = %v, want %v", got, tt.want)
}
})
}
}
func TestFromEbayDuration(t *testing.T) {
tests := []struct {
d string
wantD time.Duration
}{
{
d: "P2DT23H32M51S",
wantD: time.Hour*24*2 + time.Hour*23 + time.Minute*32 + time.Second*51,
},
{
d: "P0DT0H0M1S",
wantD: time.Second,
},
{
d: "P0DT0H0M0S",
wantD: time.Second * 0,
},
}
for _, tt := range tests {
t.Run(tt.d, func(t *testing.T) {
curDuration := FromEbayDuration(tt.d)
if tt.wantD != curDuration {
t.Errorf("wanted: %d , but got %d", tt.wantD, curDuration)
}
})
}
}