Skip to content

Commit

Permalink
Merge pull request #54 from kanmu/update_test
Browse files Browse the repository at this point in the history
Update test
  • Loading branch information
winebarrel authored Jan 9, 2024
2 parents d47b87a + e4bf0e1 commit f710cb1
Show file tree
Hide file tree
Showing 7 changed files with 422 additions and 424 deletions.
134 changes: 72 additions & 62 deletions client_between_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import (

"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 {
Expand All @@ -23,64 +25,71 @@ func TestClientBetween(_t *testing.T) {
to string
holidays []expectedHoliday
}{
{"2022-01-01 00:00:00", "2022-12-31 23:59:59", []expectedHoliday{
{"2022-01-01", "元日"},
{"2022-01-10", "成人の日"},
{"2022-02-11", "建国記念の日"},
{"2022-02-23", "天皇誕生日"},
{"2022-03-21", "春分の日"},
{"2022-04-29", "昭和の日"},
{"2022-05-03", "憲法記念日"},
{"2022-05-04", "みどりの日"},
{"2022-05-05", "こどもの日"},
{"2022-07-18", "海の日"},
{"2022-08-11", "山の日"},
{"2022-09-19", "敬老の日"},
{"2022-09-23", "秋分の日"},
{"2022-10-10", "スポーツの日"},
{"2022-11-03", "文化の日"},
{"2022-11-23", "勤労感謝の日"},
{"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", "勤労感謝の日"},
}},
{"2022-01-10 00:00:00", "2022-11-03 23:59:59", []expectedHoliday{
{"2022-01-10", "成人の日"},
{"2022-02-11", "建国記念の日"},
{"2022-02-23", "天皇誕生日"},
{"2022-03-21", "春分の日"},
{"2022-04-29", "昭和の日"},
{"2022-05-03", "憲法記念日"},
{"2022-05-04", "みどりの日"},
{"2022-05-05", "こどもの日"},
{"2022-07-18", "海の日"},
{"2022-08-11", "山の日"},
{"2022-09-19", "敬老の日"},
{"2022-09-23", "秋分の日"},
{"2022-10-10", "スポーツの日"},
{"2022-11-03", "文化の日"},
{"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)

if !assert.NoErrorf(err, "%+v", t) {
continue
}

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.Equal(expected, holidays)
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 {
Expand All @@ -93,43 +102,44 @@ func TestClientBetween_UTC(_t *testing.T) {
to string
holidays []expectedHoliday
}{
{"2022-01-01 00:00:00", "2022-12-31 23:59:59", []expectedHoliday{
{"2022-01-01", "元日"},
{"2022-01-10", "成人の日"},
{"2022-02-11", "建国記念の日"},
{"2022-02-23", "天皇誕生日"},
{"2022-03-21", "春分の日"},
{"2022-04-29", "昭和の日"},
{"2022-05-03", "憲法記念日"},
{"2022-05-04", "みどりの日"},
{"2022-05-05", "こどもの日"},
{"2022-07-18", "海の日"},
{"2022-08-11", "山の日"},
{"2022-09-19", "敬老の日"},
{"2022-09-23", "秋分の日"},
{"2022-10-10", "スポーツの日"},
{"2022-11-03", "文化の日"},
{"2022-11-23", "勤労感謝の日"},
{"2023-01-01", "元日"},
{"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)

if !assert.NoErrorf(err, "%+v", t) {
continue
}

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.Equal(expected, holidays)
assert.Equalf(expected, holidays, "%v\n!= %v\n", expected, holidays)
}
}
Loading

0 comments on commit f710cb1

Please sign in to comment.