Skip to content

chore(enterprise/coderd): remove dbmem from tests #18797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions enterprise/coderd/coderd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import (
"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/database/dbauthz"
"github.com/coder/coder/v2/coderd/database/dbfake"
"github.com/coder/coder/v2/coderd/database/dbmem"
"github.com/coder/coder/v2/coderd/database/dbtestutil"
"github.com/coder/coder/v2/coderd/database/dbtime"
"github.com/coder/coder/v2/coderd/rbac"
Expand Down Expand Up @@ -323,19 +322,21 @@ func TestAuditLogging(t *testing.T) {
t.Parallel()
t.Run("Enabled", func(t *testing.T) {
t.Parallel()
db, _ := dbtestutil.NewDB(t)
_, _, api, _ := coderdenttest.NewWithAPI(t, &coderdenttest.Options{
AuditLogging: true,
Options: &coderdtest.Options{
Auditor: audit.NewAuditor(dbmem.New(), audit.DefaultFilter),
Auditor: audit.NewAuditor(db, audit.DefaultFilter),
},
LicenseOptions: &coderdenttest.LicenseOptions{
Features: license.Features{
codersdk.FeatureAuditLog: 1,
},
},
})
db, _ = dbtestutil.NewDB(t)
auditor := *api.AGPL.Auditor.Load()
ea := audit.NewAuditor(dbmem.New(), audit.DefaultFilter)
ea := audit.NewAuditor(db, audit.DefaultFilter)
t.Logf("%T = %T", auditor, ea)
assert.EqualValues(t, reflect.ValueOf(ea).Type(), reflect.ValueOf(auditor).Type())
})
Expand Down
20 changes: 15 additions & 5 deletions enterprise/coderd/dormancy/dormantusersjob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/coder/coder/v2/coderd/audit"
"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/database/dbmem"
"github.com/coder/coder/v2/coderd/database/dbtestutil"
"github.com/coder/coder/v2/enterprise/coderd/dormancy"
"github.com/coder/quartz"
)
Expand All @@ -26,7 +26,7 @@ func TestCheckInactiveUsers(t *testing.T) {

// Add some dormant accounts
logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true})
db := dbmem.New()
db, _ := dbtestutil.NewDB(t)

ctx, cancelFunc := context.WithCancel(context.Background())
t.Cleanup(cancelFunc)
Expand Down Expand Up @@ -75,7 +75,7 @@ func TestCheckInactiveUsers(t *testing.T) {
allUsers := ignoreUpdatedAt(database.ConvertUserRows(rows))

// Verify user status
expectedUsers := []database.User{
expectedUsers := ignoreUpdatedAt([]database.User{
asDormant(inactiveUser1),
asDormant(inactiveUser2),
asDormant(inactiveUser3),
Expand All @@ -85,14 +85,24 @@ func TestCheckInactiveUsers(t *testing.T) {
suspendedUser1,
suspendedUser2,
suspendedUser3,
}
})

require.ElementsMatch(t, allUsers, expectedUsers)
}

func setupUser(ctx context.Context, t *testing.T, db database.Store, email string, status database.UserStatus, lastSeenAt time.Time) database.User {
t.Helper()

user, err := db.InsertUser(ctx, database.InsertUserParams{ID: uuid.New(), LoginType: database.LoginTypePassword, Username: uuid.NewString()[:8], Email: email})
now := dbtestutil.NowInDefaultTimezone()
user, err := db.InsertUser(ctx, database.InsertUserParams{
ID: uuid.New(),
LoginType: database.LoginTypePassword,
Username: uuid.NewString()[:8],
Email: email,
RBACRoles: []string{},
CreatedAt: now,
UpdatedAt: now,
})
require.NoError(t, err)
// At the beginning of the test all users are marked as active
user, err = db.UpdateUserStatus(ctx, database.UpdateUserStatusParams{ID: user.ID, Status: status})
Expand Down
4 changes: 0 additions & 4 deletions enterprise/coderd/enidpsync/organizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ type OrganizationSyncTestCase struct {
func TestOrganizationSync(t *testing.T) {
t.Parallel()

if dbtestutil.WillUsePostgres() {
t.Skip("Skipping test because it populates a lot of db entries, which is slow on postgres")
}

requireUserOrgs := func(t *testing.T, db database.Store, user database.User, expected []uuid.UUID) {
t.Helper()

Expand Down
58 changes: 32 additions & 26 deletions enterprise/coderd/license/license_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/database/dbmem"
"github.com/coder/coder/v2/coderd/database/dbtestutil"
"github.com/coder/coder/v2/coderd/database/dbtime"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/enterprise/coderd/coderdenttest"
Expand All @@ -30,7 +30,7 @@ func TestEntitlements(t *testing.T) {

t.Run("Defaults", func(t *testing.T) {
t.Parallel()
db := dbmem.New()
db, _ := dbtestutil.NewDB(t)
entitlements, err := license.Entitlements(context.Background(), db, 1, 1, coderdenttest.Keys, all)
require.NoError(t, err)
require.False(t, entitlements.HasLicense)
Expand All @@ -42,7 +42,7 @@ func TestEntitlements(t *testing.T) {
})
t.Run("Always return the current user count", func(t *testing.T) {
t.Parallel()
db := dbmem.New()
db, _ := dbtestutil.NewDB(t)
entitlements, err := license.Entitlements(context.Background(), db, 1, 1, coderdenttest.Keys, all)
require.NoError(t, err)
require.False(t, entitlements.HasLicense)
Expand All @@ -51,7 +51,7 @@ func TestEntitlements(t *testing.T) {
})
t.Run("SingleLicenseNothing", func(t *testing.T) {
t.Parallel()
db := dbmem.New()
db, _ := dbtestutil.NewDB(t)
db.InsertLicense(context.Background(), database.InsertLicenseParams{
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{}),
Exp: dbtime.Now().Add(time.Hour),
Expand All @@ -67,7 +67,7 @@ func TestEntitlements(t *testing.T) {
})
t.Run("SingleLicenseAll", func(t *testing.T) {
t.Parallel()
db := dbmem.New()
db, _ := dbtestutil.NewDB(t)
db.InsertLicense(context.Background(), database.InsertLicenseParams{
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
Features: func() license.Features {
Expand All @@ -90,7 +90,7 @@ func TestEntitlements(t *testing.T) {
})
t.Run("SingleLicenseGrace", func(t *testing.T) {
t.Parallel()
db := dbmem.New()
db, _ := dbtestutil.NewDB(t)
db.InsertLicense(context.Background(), database.InsertLicenseParams{
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
Features: license.Features{
Expand All @@ -116,7 +116,7 @@ func TestEntitlements(t *testing.T) {
})
t.Run("Expiration warning", func(t *testing.T) {
t.Parallel()
db := dbmem.New()
db, _ := dbtestutil.NewDB(t)
db.InsertLicense(context.Background(), database.InsertLicenseParams{
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
Features: license.Features{
Expand Down Expand Up @@ -145,7 +145,7 @@ func TestEntitlements(t *testing.T) {

t.Run("Expiration warning for license expiring in 1 day", func(t *testing.T) {
t.Parallel()
db := dbmem.New()
db, _ := dbtestutil.NewDB(t)
db.InsertLicense(context.Background(), database.InsertLicenseParams{
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
Features: license.Features{
Expand Down Expand Up @@ -174,7 +174,7 @@ func TestEntitlements(t *testing.T) {

t.Run("Expiration warning for trials", func(t *testing.T) {
t.Parallel()
db := dbmem.New()
db, _ := dbtestutil.NewDB(t)
db.InsertLicense(context.Background(), database.InsertLicenseParams{
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
Features: license.Features{
Expand Down Expand Up @@ -204,7 +204,7 @@ func TestEntitlements(t *testing.T) {

t.Run("Expiration warning for non trials", func(t *testing.T) {
t.Parallel()
db := dbmem.New()
db, _ := dbtestutil.NewDB(t)
db.InsertLicense(context.Background(), database.InsertLicenseParams{
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
Features: license.Features{
Expand Down Expand Up @@ -233,7 +233,7 @@ func TestEntitlements(t *testing.T) {

t.Run("SingleLicenseNotEntitled", func(t *testing.T) {
t.Parallel()
db := dbmem.New()
db, _ := dbtestutil.NewDB(t)
db.InsertLicense(context.Background(), database.InsertLicenseParams{
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{}),
Exp: time.Now().Add(time.Hour),
Expand Down Expand Up @@ -261,11 +261,13 @@ func TestEntitlements(t *testing.T) {
})
t.Run("TooManyUsers", func(t *testing.T) {
t.Parallel()
db := dbmem.New()
db, _ := dbtestutil.NewDB(t)
activeUser1, err := db.InsertUser(context.Background(), database.InsertUserParams{
ID: uuid.New(),
Username: "test1",
Email: "test1@coder.com",
LoginType: database.LoginTypePassword,
RBACRoles: []string{},
})
require.NoError(t, err)
_, err = db.UpdateUserStatus(context.Background(), database.UpdateUserStatusParams{
Expand All @@ -277,7 +279,9 @@ func TestEntitlements(t *testing.T) {
activeUser2, err := db.InsertUser(context.Background(), database.InsertUserParams{
ID: uuid.New(),
Username: "test2",
Email: "test2@coder.com",
LoginType: database.LoginTypePassword,
RBACRoles: []string{},
})
require.NoError(t, err)
_, err = db.UpdateUserStatus(context.Background(), database.UpdateUserStatusParams{
Expand All @@ -289,7 +293,9 @@ func TestEntitlements(t *testing.T) {
_, err = db.InsertUser(context.Background(), database.InsertUserParams{
ID: uuid.New(),
Username: "dormant-user",
Email: "dormant-user@coder.com",
LoginType: database.LoginTypePassword,
RBACRoles: []string{},
})
require.NoError(t, err)
db.InsertLicense(context.Background(), database.InsertLicenseParams{
Expand All @@ -307,7 +313,7 @@ func TestEntitlements(t *testing.T) {
})
t.Run("MaximizeUserLimit", func(t *testing.T) {
t.Parallel()
db := dbmem.New()
db, _ := dbtestutil.NewDB(t)
db.InsertUser(context.Background(), database.InsertUserParams{})
db.InsertUser(context.Background(), database.InsertUserParams{})
db.InsertLicense(context.Background(), database.InsertLicenseParams{
Expand Down Expand Up @@ -335,7 +341,7 @@ func TestEntitlements(t *testing.T) {
})
t.Run("MultipleLicenseEnabled", func(t *testing.T) {
t.Parallel()
db := dbmem.New()
db, _ := dbtestutil.NewDB(t)
// One trial
db.InsertLicense(context.Background(), database.InsertLicenseParams{
Exp: time.Now().Add(time.Hour),
Expand All @@ -359,7 +365,7 @@ func TestEntitlements(t *testing.T) {

t.Run("Enterprise", func(t *testing.T) {
t.Parallel()
db := dbmem.New()
db, _ := dbtestutil.NewDB(t)
_, err := db.InsertLicense(context.Background(), database.InsertLicenseParams{
Exp: time.Now().Add(time.Hour),
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
Expand Down Expand Up @@ -390,7 +396,7 @@ func TestEntitlements(t *testing.T) {

t.Run("Premium", func(t *testing.T) {
t.Parallel()
db := dbmem.New()
db, _ := dbtestutil.NewDB(t)
_, err := db.InsertLicense(context.Background(), database.InsertLicenseParams{
Exp: time.Now().Add(time.Hour),
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
Expand Down Expand Up @@ -421,7 +427,7 @@ func TestEntitlements(t *testing.T) {

t.Run("SetNone", func(t *testing.T) {
t.Parallel()
db := dbmem.New()
db, _ := dbtestutil.NewDB(t)
_, err := db.InsertLicense(context.Background(), database.InsertLicenseParams{
Exp: time.Now().Add(time.Hour),
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
Expand All @@ -443,7 +449,7 @@ func TestEntitlements(t *testing.T) {
// AllFeatures uses the deprecated 'AllFeatures' boolean.
t.Run("AllFeatures", func(t *testing.T) {
t.Parallel()
db := dbmem.New()
db, _ := dbtestutil.NewDB(t)
db.InsertLicense(context.Background(), database.InsertLicenseParams{
Exp: time.Now().Add(time.Hour),
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
Expand Down Expand Up @@ -473,7 +479,7 @@ func TestEntitlements(t *testing.T) {

t.Run("AllFeaturesAlwaysEnable", func(t *testing.T) {
t.Parallel()
db := dbmem.New()
db, _ := dbtestutil.NewDB(t)
db.InsertLicense(context.Background(), database.InsertLicenseParams{
Exp: dbtime.Now().Add(time.Hour),
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
Expand Down Expand Up @@ -504,7 +510,7 @@ func TestEntitlements(t *testing.T) {

t.Run("AllFeaturesGrace", func(t *testing.T) {
t.Parallel()
db := dbmem.New()
db, _ := dbtestutil.NewDB(t)
db.InsertLicense(context.Background(), database.InsertLicenseParams{
Exp: dbtime.Now().Add(time.Hour),
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
Expand Down Expand Up @@ -535,7 +541,7 @@ func TestEntitlements(t *testing.T) {

t.Run("MultipleReplicasNoLicense", func(t *testing.T) {
t.Parallel()
db := dbmem.New()
db, _ := dbtestutil.NewDB(t)
entitlements, err := license.Entitlements(context.Background(), db, 2, 1, coderdenttest.Keys, all)
require.NoError(t, err)
require.False(t, entitlements.HasLicense)
Expand All @@ -545,7 +551,7 @@ func TestEntitlements(t *testing.T) {

t.Run("MultipleReplicasNotEntitled", func(t *testing.T) {
t.Parallel()
db := dbmem.New()
db, _ := dbtestutil.NewDB(t)
db.InsertLicense(context.Background(), database.InsertLicenseParams{
Exp: time.Now().Add(time.Hour),
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
Expand All @@ -565,7 +571,7 @@ func TestEntitlements(t *testing.T) {

t.Run("MultipleReplicasGrace", func(t *testing.T) {
t.Parallel()
db := dbmem.New()
db, _ := dbtestutil.NewDB(t)
db.InsertLicense(context.Background(), database.InsertLicenseParams{
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
Features: license.Features{
Expand All @@ -587,7 +593,7 @@ func TestEntitlements(t *testing.T) {

t.Run("MultipleGitAuthNoLicense", func(t *testing.T) {
t.Parallel()
db := dbmem.New()
db, _ := dbtestutil.NewDB(t)
entitlements, err := license.Entitlements(context.Background(), db, 1, 2, coderdenttest.Keys, all)
require.NoError(t, err)
require.False(t, entitlements.HasLicense)
Expand All @@ -597,7 +603,7 @@ func TestEntitlements(t *testing.T) {

t.Run("MultipleGitAuthNotEntitled", func(t *testing.T) {
t.Parallel()
db := dbmem.New()
db, _ := dbtestutil.NewDB(t)
db.InsertLicense(context.Background(), database.InsertLicenseParams{
Exp: time.Now().Add(time.Hour),
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
Expand All @@ -617,7 +623,7 @@ func TestEntitlements(t *testing.T) {

t.Run("MultipleGitAuthGrace", func(t *testing.T) {
t.Parallel()
db := dbmem.New()
db, _ := dbtestutil.NewDB(t)
db.InsertLicense(context.Background(), database.InsertLicenseParams{
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
GraceAt: time.Now().Add(-time.Hour),
Expand Down
Loading
Loading