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:
Cian Johnston
2023-09-15 09:01:32 +01:00
committed by GitHub
parent 281faf9ccd
commit 65db7a71b7
12 changed files with 1270 additions and 131 deletions

View File

@ -1514,8 +1514,13 @@ func TestWorkspaceFilterManual(t *testing.T) {
t.Run("LastUsed", func(t *testing.T) {
t.Parallel()
// nolint:gocritic // https://github.com/coder/coder/issues/9682
db, ps := dbtestutil.NewDB(t, dbtestutil.WithTimezone("UTC"))
client, _, api := coderdtest.NewWithAPI(t, &coderdtest.Options{
IncludeProvisionerDaemon: true,
Database: db,
Pubsub: ps,
})
user := coderdtest.CreateFirstUser(t, client)
authToken := uuid.NewString()