Skip to content

Commit fdc9dfa

Browse files
test(coderd/database/dbpurge): use mock db in TestPurge (#19386)
Closes coder/internal#906 This test was using dbmem until we removed it. The test just makes sure the background job runs at all, so a mock db continues to be fine here. No other tests in this package used dbmem, so this is the only test I've changed.
1 parent 0a81502 commit fdc9dfa

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

coderd/database/dbpurge/dbpurge_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ import (
1515
"github.com/stretchr/testify/assert"
1616
"github.com/stretchr/testify/require"
1717
"go.uber.org/goleak"
18+
"go.uber.org/mock/gomock"
1819

1920
"cdr.dev/slog"
2021
"cdr.dev/slog/sloggers/slogtest"
2122

2223
"github.com/coder/coder/v2/coderd/database"
2324
"github.com/coder/coder/v2/coderd/database/dbgen"
25+
"github.com/coder/coder/v2/coderd/database/dbmock"
2426
"github.com/coder/coder/v2/coderd/database/dbpurge"
2527
"github.com/coder/coder/v2/coderd/database/dbrollup"
2628
"github.com/coder/coder/v2/coderd/database/dbtestutil"
@@ -46,8 +48,9 @@ func TestPurge(t *testing.T) {
4648
// We want to make sure dbpurge is actually started so that this test is meaningful.
4749
clk := quartz.NewMock(t)
4850
done := awaitDoTick(ctx, t, clk)
49-
db, _ := dbtestutil.NewDB(t)
50-
purger := dbpurge.New(context.Background(), testutil.Logger(t), db, clk)
51+
mDB := dbmock.NewMockStore(gomock.NewController(t))
52+
mDB.EXPECT().InTx(gomock.Any(), database.DefaultTXOptions().WithID("db_purge")).Return(nil).Times(2)
53+
purger := dbpurge.New(context.Background(), testutil.Logger(t), mDB, clk)
5154
<-done // wait for doTick() to run.
5255
require.NoError(t, purger.Close())
5356
}

0 commit comments

Comments
 (0)