Skip to content

Commit e62c5db

Browse files
authored
chore: remove references to dbtestutil.WillUsePostgres (coder#20436)
Addresses coder/internal#758. This PR only cleans up dead code, it makes no changes to test logic.
1 parent 4244b20 commit e62c5db

33 files changed

+26
-380
lines changed

cli/delete_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,6 @@ func TestDelete(t *testing.T) {
185185

186186
t.Run("WarnNoProvisioners", func(t *testing.T) {
187187
t.Parallel()
188-
if !dbtestutil.WillUsePostgres() {
189-
t.Skip("this test requires postgres")
190-
}
191188

192189
store, ps, db := dbtestutil.NewDBWithSQLDB(t)
193190
client, closeDaemon := coderdtest.NewWithProvisionerCloser(t, &coderdtest.Options{
@@ -228,9 +225,6 @@ func TestDelete(t *testing.T) {
228225

229226
t.Run("Prebuilt workspace delete permissions", func(t *testing.T) {
230227
t.Parallel()
231-
if !dbtestutil.WillUsePostgres() {
232-
t.Skip("this test requires postgres")
233-
}
234228

235229
// Setup
236230
db, pb := dbtestutil.NewDB(t, dbtestutil.WithDumpOnFailure())

cli/server_regenerate_vapid_keypair_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ import (
1717

1818
func TestRegenerateVapidKeypair(t *testing.T) {
1919
t.Parallel()
20-
if !dbtestutil.WillUsePostgres() {
21-
t.Skip("this test is only supported on postgres")
22-
}
2320

2421
t.Run("NoExistingVAPIDKeys", func(t *testing.T) {
2522
t.Parallel()

cli/server_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,6 @@ func TestServer(t *testing.T) {
348348

349349
runGitHubProviderTest := func(t *testing.T, tc testCase) {
350350
t.Parallel()
351-
if !dbtestutil.WillUsePostgres() {
352-
t.Skip("test requires postgres")
353-
}
354351

355352
ctx, cancelFunc := context.WithCancel(testutil.Context(t, testutil.WaitLong))
356353
defer cancelFunc()
@@ -2142,10 +2139,6 @@ func TestServerYAMLConfig(t *testing.T) {
21422139
func TestConnectToPostgres(t *testing.T) {
21432140
t.Parallel()
21442141

2145-
if !dbtestutil.WillUsePostgres() {
2146-
t.Skip("this test does not make sense without postgres")
2147-
}
2148-
21492142
t.Run("Migrate", func(t *testing.T) {
21502143
t.Parallel()
21512144

@@ -2256,10 +2249,6 @@ type runServerOpts struct {
22562249
func TestServer_TelemetryDisabled_FinalReport(t *testing.T) {
22572250
t.Parallel()
22582251

2259-
if !dbtestutil.WillUsePostgres() {
2260-
t.Skip("this test requires postgres")
2261-
}
2262-
22632252
telemetryServerURL, deployment, snapshot := mockTelemetryServer(t)
22642253
dbConnURL, err := dbtestutil.Open(t)
22652254
require.NoError(t, err)

coderd/aitasks_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/coder/coder/v2/coderd/database/dbauthz"
2323
"github.com/coder/coder/v2/coderd/database/dbfake"
2424
"github.com/coder/coder/v2/coderd/database/dbgen"
25-
"github.com/coder/coder/v2/coderd/database/dbtestutil"
2625
"github.com/coder/coder/v2/coderd/database/dbtime"
2726
"github.com/coder/coder/v2/coderd/notifications"
2827
"github.com/coder/coder/v2/coderd/notifications/notificationstest"
@@ -54,10 +53,6 @@ func TestAITasksPrompts(t *testing.T) {
5453
t.Run("MultipleBuilds", func(t *testing.T) {
5554
t.Parallel()
5655

57-
if !dbtestutil.WillUsePostgres() {
58-
t.Skip("This test checks RBAC, which is not supported in the in-memory database")
59-
}
60-
6156
adminClient := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
6257
first := coderdtest.CreateFirstUser(t, adminClient)
6358
memberClient, _ := coderdtest.CreateAnotherUser(t, adminClient, first.OrganizationID)

coderd/autobuild/lifecycle_executor_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -776,10 +776,6 @@ func TestExecutorWorkspaceAutostopNoWaitChangedMyMind(t *testing.T) {
776776
}
777777

778778
func TestExecutorAutostartMultipleOK(t *testing.T) {
779-
if !dbtestutil.WillUsePostgres() {
780-
t.Skip(`This test only really works when using a "real" database, similar to a HA setup`)
781-
}
782-
783779
t.Parallel()
784780

785781
var (
@@ -1259,10 +1255,6 @@ func TestNotifications(t *testing.T) {
12591255
func TestExecutorPrebuilds(t *testing.T) {
12601256
t.Parallel()
12611257

1262-
if !dbtestutil.WillUsePostgres() {
1263-
t.Skip("this test requires postgres")
1264-
}
1265-
12661258
// Prebuild workspaces should not be autostopped when the deadline is reached.
12671259
// After being claimed, the workspace should stop at the deadline.
12681260
t.Run("OnlyStopsAfterClaimed", func(t *testing.T) {

coderd/database/db_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ func TestNestedInTx(t *testing.T) {
8585
func testSQLDB(t testing.TB) *sql.DB {
8686
t.Helper()
8787

88-
if !dbtestutil.WillUsePostgres() {
89-
t.Skip("this test requires postgres")
90-
}
91-
9288
connection, err := dbtestutil.Open(t)
9389
require.NoError(t, err)
9490

coderd/database/dbauthz/dbauthz_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2946,7 +2946,6 @@ func (s *MethodTestSuite) TestSystemFunctions() {
29462946
dbm.EXPECT().GetParameterSchemasByJobID(gomock.Any(), jobID).Return([]database.ParameterSchema{}, nil).AnyTimes()
29472947
check.Args(jobID).
29482948
Asserts(tpl, policy.ActionRead).
2949-
ErrorsWithInMemDB(sql.ErrNoRows).
29502949
Returns([]database.ParameterSchema{})
29512950
}))
29522951
s.Run("GetWorkspaceAppsByAgentIDs", s.Mocked(func(dbm *dbmock.MockStore, faker *gofakeit.Faker, check *expects) {
@@ -3189,7 +3188,7 @@ func (s *MethodTestSuite) TestSystemFunctions() {
31893188
}))
31903189
s.Run("GetAppSecurityKey", s.Mocked(func(dbm *dbmock.MockStore, _ *gofakeit.Faker, check *expects) {
31913190
dbm.EXPECT().GetAppSecurityKey(gomock.Any()).Return("", sql.ErrNoRows).AnyTimes()
3192-
check.Args().Asserts(rbac.ResourceSystem, policy.ActionRead).ErrorsWithPG(sql.ErrNoRows)
3191+
check.Args().Asserts(rbac.ResourceSystem, policy.ActionRead).Errors(sql.ErrNoRows)
31933192
}))
31943193
s.Run("UpsertAppSecurityKey", s.Mocked(func(dbm *dbmock.MockStore, _ *gofakeit.Faker, check *expects) {
31953194
dbm.EXPECT().UpsertAppSecurityKey(gomock.Any(), "foo").Return(nil).AnyTimes()

coderd/database/dbauthz/setup_test.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -430,24 +430,6 @@ func (m *expects) Errors(err error) *expects {
430430
return m
431431
}
432432

433-
// ErrorsWithPG is optional. If it is never called, it will not be asserted.
434-
// It will only be asserted if the test is running with a Postgres database.
435-
func (m *expects) ErrorsWithPG(err error) *expects {
436-
if dbtestutil.WillUsePostgres() {
437-
return m.Errors(err)
438-
}
439-
return m
440-
}
441-
442-
// ErrorsWithInMemDB is optional. If it is never called, it will not be asserted.
443-
// It will only be asserted if the test is running with an in-memory database.
444-
func (m *expects) ErrorsWithInMemDB(err error) *expects {
445-
if !dbtestutil.WillUsePostgres() {
446-
return m.Errors(err)
447-
}
448-
return m
449-
}
450-
451433
func (m *expects) FailSystemObjectChecks() *expects {
452434
return m.WithSuccessAuthorizer(func(ctx context.Context, subject rbac.Subject, action policy.Action, obj rbac.Object) error {
453435
if obj.Type == rbac.ResourceSystem.Type {

coderd/database/dbrollup/dbrollup_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ func (w *wrapUpsertDB) UpsertTemplateUsageStats(ctx context.Context) error {
5252
func TestRollup_TwoInstancesUseLocking(t *testing.T) {
5353
t.Parallel()
5454

55-
if !dbtestutil.WillUsePostgres() {
56-
t.Skip("Skipping test; only works with PostgreSQL.")
57-
}
58-
5955
db, ps := dbtestutil.NewDB(t, dbtestutil.WithDumpOnFailure())
6056
logger := testutil.Logger(t)
6157

coderd/database/dbtestutil/db.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@ import (
2323
"github.com/coder/coder/v2/testutil"
2424
)
2525

26-
// WillUsePostgres returns true if a call to NewDB() will return a real, postgres-backed Store and Pubsub.
27-
// TODO(hugodutka): since we removed the in-memory database, this is always true,
28-
// and we need to remove this function. https://github.com/coder/internal/issues/758
29-
func WillUsePostgres() bool {
30-
return true
31-
}
32-
3326
type options struct {
3427
fixedTimezone string
3528
dumpOnFailure bool
@@ -75,10 +68,6 @@ func withReturnSQLDB(f func(*sql.DB)) Option {
7568
func NewDBWithSQLDB(t testing.TB, opts ...Option) (database.Store, pubsub.Pubsub, *sql.DB) {
7669
t.Helper()
7770

78-
if !WillUsePostgres() {
79-
t.Fatal("cannot use NewDBWithSQLDB without PostgreSQL, consider adding `if !dbtestutil.WillUsePostgres() { t.Skip() }` to this test")
80-
}
81-
8271
var sqlDB *sql.DB
8372
opts = append(opts, withReturnSQLDB(func(db *sql.DB) {
8473
sqlDB = db

0 commit comments

Comments
 (0)