-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_between_test.go
145 lines (131 loc) · 4.23 KB
/
client_between_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package jhol_test
import (
"context"
"testing"
"time"
"github.com/kanmu/jhol"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestClientBetween(_t *testing.T) {
assert := assert.New(_t)
require := require.New(_t)
client := jhol.NewClient(TestGCalAPIKey)
type expectedHoliday struct {
expectedDate string
expectedName string
}
tests := []struct {
from string
to string
holidays []expectedHoliday
}{
{"2024-01-01 00:00:00", "2024-12-31 23:59:59", []expectedHoliday{
{"2024-01-01", "元日"},
{"2024-01-08", "成人の日"},
{"2024-02-11", "建国記念の日"},
{"2024-02-12", "休日"},
{"2024-02-23", "天皇誕生日"},
{"2024-03-20", "春分の日"},
{"2024-04-29", "昭和の日"},
{"2024-05-03", "憲法記念日"},
{"2024-05-04", "みどりの日"},
{"2024-05-05", "こどもの日"},
{"2024-05-06", "休日"},
{"2024-07-15", "海の日"},
{"2024-08-11", "山の日"},
{"2024-08-12", "休日"},
{"2024-09-16", "敬老の日"},
{"2024-09-22", "秋分の日"},
{"2024-09-23", "休日"},
{"2024-10-14", "スポーツの日"},
{"2024-11-03", "文化の日"},
{"2024-11-04", "休日"},
{"2024-11-23", "勤労感謝の日"},
}},
{"2024-01-08 00:00:00", "2024-11-04 23:59:59", []expectedHoliday{
{"2024-01-08", "成人の日"},
{"2024-02-11", "建国記念の日"},
{"2024-02-12", "休日"},
{"2024-02-23", "天皇誕生日"},
{"2024-03-20", "春分の日"},
{"2024-04-29", "昭和の日"},
{"2024-05-03", "憲法記念日"},
{"2024-05-04", "みどりの日"},
{"2024-05-05", "こどもの日"},
{"2024-05-06", "休日"},
{"2024-07-15", "海の日"},
{"2024-08-11", "山の日"},
{"2024-08-12", "休日"},
{"2024-09-16", "敬老の日"},
{"2024-09-22", "秋分の日"},
{"2024-09-23", "休日"},
{"2024-10-14", "スポーツの日"},
{"2024-11-03", "文化の日"},
{"2024-11-04", "休日"},
}},
}
for _, t := range tests {
from, _ := time.ParseInLocation("2006-01-02 15:04:05", t.from, JST)
to, _ := time.ParseInLocation("2006-01-02 15:04:05", t.to, JST)
holidays, err := client.Between(context.Background(), from, to)
require.NoErrorf(err, "%s - %s", t.from, t.to)
expected := []*jhol.Holiday{}
for _, h := range t.holidays {
expectedDate, _ := time.ParseInLocation("2006-01-02", h.expectedDate, JST)
expected = append(expected, &jhol.Holiday{Date: expectedDate, Name: h.expectedName})
}
assert.Equalf(expected, holidays, "%v\n!= %v\n", expected, holidays)
}
}
func TestClientBetween_UTC(_t *testing.T) {
assert := assert.New(_t)
require := require.New(_t)
client := jhol.NewClient(TestGCalAPIKey)
type expectedHoliday struct {
expectedDate string
expectedName string
}
tests := []struct {
from string
to string
holidays []expectedHoliday
}{
{"2024-01-01 00:00:00", "2024-12-31 23:59:59", []expectedHoliday{
{"2024-01-01", "元日"},
{"2024-01-08", "成人の日"},
{"2024-02-11", "建国記念の日"},
{"2024-02-12", "休日"},
{"2024-02-23", "天皇誕生日"},
{"2024-03-20", "春分の日"},
{"2024-04-29", "昭和の日"},
{"2024-05-03", "憲法記念日"},
{"2024-05-04", "みどりの日"},
{"2024-05-05", "こどもの日"},
{"2024-05-06", "休日"},
{"2024-07-15", "海の日"},
{"2024-08-11", "山の日"},
{"2024-08-12", "休日"},
{"2024-09-16", "敬老の日"},
{"2024-09-22", "秋分の日"},
{"2024-09-23", "休日"},
{"2024-10-14", "スポーツの日"},
{"2024-11-03", "文化の日"},
{"2024-11-04", "休日"},
{"2024-11-23", "勤労感謝の日"},
{"2025-01-01", "元日"},
}},
}
for _, t := range tests {
from, _ := time.ParseInLocation("2006-01-02 15:04:05", t.from, time.UTC)
to, _ := time.ParseInLocation("2006-01-02 15:04:05", t.to, time.UTC)
holidays, err := client.Between(context.Background(), from, to)
require.NoErrorf(err, "%s - %s", t.from, t.to)
expected := []*jhol.Holiday{}
for _, h := range t.holidays {
expectedDate, _ := time.ParseInLocation("2006-01-02", h.expectedDate, JST)
expected = append(expected, &jhol.Holiday{Date: expectedDate, Name: h.expectedName})
}
assert.Equalf(expected, holidays, "%v\n!= %v\n", expected, holidays)
}
}