mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
test: Using local time in unit test fails in certain time zones (#1540)
* test: Using local time in unit test fails in certain time zones This test was failing when running in CST (GMT-5) timezone. My local timezone pushed the next to the upcoming monday * fix: schedule: assert expected result of String() separately from input spec Co-authored-by: Cian Johnston <cian@coder.com>
This commit is contained in:
co-authored by
Cian Johnston
parent
ba818b3a10
commit
4e28b2d9c5
@@ -12,31 +12,34 @@ import (
|
||||
func Test_Weekly(t *testing.T) {
|
||||
t.Parallel()
|
||||
testCases := []struct {
|
||||
name string
|
||||
spec string
|
||||
at time.Time
|
||||
expectedNext time.Time
|
||||
expectedError string
|
||||
expectedCron string
|
||||
expectedTz string
|
||||
name string
|
||||
spec string
|
||||
at time.Time
|
||||
expectedNext time.Time
|
||||
expectedError string
|
||||
expectedCron string
|
||||
expectedTz string
|
||||
expectedString string
|
||||
}{
|
||||
{
|
||||
name: "with timezone",
|
||||
spec: "CRON_TZ=US/Central 30 9 * * 1-5",
|
||||
at: time.Date(2022, 4, 1, 14, 29, 0, 0, time.UTC),
|
||||
expectedNext: time.Date(2022, 4, 1, 14, 30, 0, 0, time.UTC),
|
||||
expectedError: "",
|
||||
expectedCron: "30 9 * * 1-5",
|
||||
expectedTz: "US/Central",
|
||||
name: "with timezone",
|
||||
spec: "CRON_TZ=US/Central 30 9 * * 1-5",
|
||||
at: time.Date(2022, 4, 1, 14, 29, 0, 0, time.UTC),
|
||||
expectedNext: time.Date(2022, 4, 1, 14, 30, 0, 0, time.UTC),
|
||||
expectedError: "",
|
||||
expectedCron: "30 9 * * 1-5",
|
||||
expectedTz: "US/Central",
|
||||
expectedString: "CRON_TZ=US/Central 30 9 * * 1-5",
|
||||
},
|
||||
{
|
||||
name: "without timezone",
|
||||
spec: "CRON_TZ=UTC 30 9 * * 1-5",
|
||||
at: time.Date(2022, 4, 1, 9, 29, 0, 0, time.Local),
|
||||
expectedNext: time.Date(2022, 4, 1, 9, 30, 0, 0, time.Local),
|
||||
expectedError: "",
|
||||
expectedCron: "30 9 * * 1-5",
|
||||
expectedTz: "UTC",
|
||||
name: "without timezone",
|
||||
spec: "30 9 * * 1-5",
|
||||
at: time.Date(2022, 4, 1, 9, 29, 0, 0, time.UTC),
|
||||
expectedNext: time.Date(2022, 4, 1, 9, 30, 0, 0, time.UTC),
|
||||
expectedError: "",
|
||||
expectedCron: "30 9 * * 1-5",
|
||||
expectedTz: "UTC",
|
||||
expectedString: "CRON_TZ=UTC 30 9 * * 1-5",
|
||||
},
|
||||
{
|
||||
name: "invalid schedule",
|
||||
@@ -91,9 +94,9 @@ func Test_Weekly(t *testing.T) {
|
||||
nextTime := actual.Next(testCase.at)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, testCase.expectedNext, nextTime)
|
||||
require.Equal(t, testCase.spec, actual.String())
|
||||
require.Equal(t, testCase.expectedCron, actual.Cron())
|
||||
require.Equal(t, testCase.expectedTz, actual.Timezone())
|
||||
require.Equal(t, testCase.expectedString, actual.String())
|
||||
} else {
|
||||
require.EqualError(t, err, testCase.expectedError)
|
||||
require.Nil(t, actual)
|
||||
|
||||
Reference in New Issue
Block a user