-
Notifications
You must be signed in to change notification settings - Fork 1
/
fromto_test.go
53 lines (47 loc) · 1.06 KB
/
fromto_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
package comatome
import (
"testing"
"time"
)
func loadLocation(name string) *time.Location {
loc, err := time.LoadLocation(name)
if err != nil {
panic(err)
}
return loc
}
func timeParse(layout, target string) time.Time {
t, err := time.Parse(layout, target)
if err != nil {
panic(err)
}
return t
}
func TestQueryStr(t *testing.T) {
tcs := []struct {
inFrom time.Time
inTo time.Time
inLoc *time.Location
wantFrom string
wantTo string
}{
// only yyyy-mm is acceptable
{
inFrom: timeParse("2006-01", "2019-01"),
inTo: timeParse("2006-01", "2019-02"),
inLoc: loadLocation("Asia/Tokyo"),
wantFrom: "2019-01-01T09:00:00+09:00",
wantTo: "2019-02-01T09:00:00+09:00",
},
}
for i, tc := range tcs {
ft := NewFromTo(tc.inFrom, tc.inTo, tc.inLoc)
gotFrom, gotTo := ft.QueryStr()
if gotFrom != tc.wantFrom {
t.Fatalf("[No.%d] unexpected result. [got] %v [want] %v", i, gotFrom, tc.wantFrom)
}
if gotTo != tc.wantTo {
t.Fatalf("[No.%d] unexpected result. [got] %v [want] %v", i, gotTo, tc.wantTo)
}
}
}