From e4bf0e129eb033f6a959922a2eb7f5c864c1688a Mon Sep 17 00:00:00 2001 From: winebarrel Date: Tue, 9 Jan 2024 13:11:35 +0900 Subject: [PATCH] fix TestClientBetween* --- client_between_test.go | 134 ++++++++++++++++++++++------------------- 1 file changed, 72 insertions(+), 62 deletions(-) diff --git a/client_between_test.go b/client_between_test.go index be1e024..9ae23b2 100644 --- a/client_between_test.go +++ b/client_between_test.go @@ -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 { @@ -23,39 +25,49 @@ 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", "文化の日 振替休日"}, }}, } @@ -63,11 +75,7 @@ func TestClientBetween(_t *testing.T) { 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 { @@ -75,12 +83,13 @@ func TestClientBetween(_t *testing.T) { 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 { @@ -93,24 +102,29 @@ 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", "元日"}, }}, } @@ -118,11 +132,7 @@ func TestClientBetween_UTC(_t *testing.T) { 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 { @@ -130,6 +140,6 @@ func TestClientBetween_UTC(_t *testing.T) { expected = append(expected, &jhol.Holiday{Date: expectedDate, Name: h.expectedName}) } - assert.Equal(expected, holidays) + assert.Equalf(expected, holidays, "%v\n!= %v\n", expected, holidays) } }