mirror of
https://github.com/coder/coder.git
synced 2025-07-13 21:36:50 +00:00
feat(coderd/database/dbtestutil): set default database timezone to non-UTC in unit tests (#9672)
- Adds dbtestutil.WithTimezone(tz) to allow setting the timezone for a test database. - Modifies our test database setup code to pick a consistently weird timezone for the database. - Adds the facility randtz.Name() to pick a random timezone which is consistent across subtests (via sync.Once). - Adds a linter rule to warn against setting the test database timezone to UTC.
This commit is contained in:
@ -395,3 +395,16 @@ func slogError(m dsl.Matcher) {
|
||||
Where(m["name"].Const && m["value"].Type.Is("error") && !m["name"].Text.Matches(`^"internal_error"$`)).
|
||||
Report(`Error should be logged using "slog.Error" instead.`)
|
||||
}
|
||||
|
||||
// withTimezoneUTC ensures that we don't just sprinkle dbtestutil.WithTimezone("UTC") about
|
||||
// to work around real timezone bugs in our code.
|
||||
//
|
||||
//nolint:unused,deadcode,varnamelen
|
||||
func withTimezoneUTC(m dsl.Matcher) {
|
||||
m.Match(
|
||||
`dbtestutil.WithTimezone($tz)`,
|
||||
).Where(
|
||||
m["tz"].Text.Matches(`[uU][tT][cC]"$`),
|
||||
).Report(`Setting database timezone to UTC may mask timezone-related bugs.`).
|
||||
At(m["tz"])
|
||||
}
|
||||
|
Reference in New Issue
Block a user