mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore(enterprise/coderd): remove dbmem from tests (#18797)
Related to https://github.com/coder/coder/issues/15109.
This commit is contained in:
@@ -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"
|
||||
@@ -323,10 +322,11 @@ 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{
|
||||
@@ -334,8 +334,9 @@ func TestAuditLogging(t *testing.T) {
|
||||
},
|
||||
},
|
||||
})
|
||||
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())
|
||||
})
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
@@ -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)
|
||||
@@ -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),
|
||||
@@ -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})
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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"
|
||||
@@ -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)
|
||||
@@ -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)
|
||||
@@ -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),
|
||||
@@ -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 {
|
||||
@@ -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{
|
||||
@@ -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{
|
||||
@@ -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{
|
||||
@@ -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{
|
||||
@@ -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{
|
||||
@@ -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),
|
||||
@@ -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{
|
||||
@@ -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{
|
||||
@@ -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{
|
||||
@@ -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{
|
||||
@@ -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),
|
||||
@@ -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{
|
||||
@@ -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{
|
||||
@@ -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{
|
||||
@@ -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{
|
||||
@@ -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{
|
||||
@@ -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{
|
||||
@@ -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)
|
||||
@@ -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{
|
||||
@@ -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{
|
||||
@@ -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)
|
||||
@@ -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{
|
||||
@@ -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),
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
"github.com/coder/coder/v2/coderd/database"
|
||||
"github.com/coder/coder/v2/coderd/database/dbgen"
|
||||
"github.com/coder/coder/v2/coderd/database/dbmem"
|
||||
"github.com/coder/coder/v2/coderd/database/dbtestutil"
|
||||
"github.com/coder/coder/v2/coderd/httpapi"
|
||||
"github.com/coder/coder/v2/codersdk"
|
||||
"github.com/coder/coder/v2/enterprise/coderd/proxyhealth"
|
||||
@@ -46,7 +46,7 @@ func TestProxyHealth_Nil(t *testing.T) {
|
||||
|
||||
func TestProxyHealth_Unregistered(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := dbmem.New()
|
||||
db, _ := dbtestutil.NewDB(t)
|
||||
|
||||
proxies := []database.WorkspaceProxy{
|
||||
insertProxy(t, db, ""),
|
||||
@@ -72,7 +72,7 @@ func TestProxyHealth_Unregistered(t *testing.T) {
|
||||
|
||||
func TestProxyHealth_Unhealthy(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := dbmem.New()
|
||||
db, _ := dbtestutil.NewDB(t)
|
||||
|
||||
srvBadReport := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
httpapi.Write(context.Background(), w, http.StatusOK, codersdk.ProxyHealthReport{
|
||||
@@ -112,7 +112,7 @@ func TestProxyHealth_Unhealthy(t *testing.T) {
|
||||
|
||||
func TestProxyHealth_Reachable(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := dbmem.New()
|
||||
db, _ := dbtestutil.NewDB(t)
|
||||
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
httpapi.Write(context.Background(), w, http.StatusOK, codersdk.ProxyHealthReport{
|
||||
@@ -147,7 +147,7 @@ func TestProxyHealth_Reachable(t *testing.T) {
|
||||
|
||||
func TestProxyHealth_Unreachable(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := dbmem.New()
|
||||
db, _ := dbtestutil.NewDB(t)
|
||||
|
||||
cli := &http.Client{
|
||||
Transport: &http.Transport{
|
||||
|
||||
Reference in New Issue
Block a user