From 5abfe5afd025ce0ae2bc3e816be1474b7b740422 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Mon, 30 Oct 2023 13:42:20 -0400 Subject: [PATCH] chore: rename dbfake to dbmem (#10432) --- .vscode/settings.json | 2 +- Makefile | 2 +- cli/server.go | 6 +-- coderd/database/dbauthz/dbauthz_test.go | 10 ++-- coderd/database/dbauthz/setup_test.go | 4 +- coderd/database/dbgen/dbgen_test.go | 44 +++++++++--------- .../{dbfake/dbfake.go => dbmem/dbmem.go} | 6 +-- .../dbfake_test.go => dbmem/dbmem_test.go} | 10 ++-- coderd/database/dbpurge/dbpurge_test.go | 4 +- coderd/database/dbtestutil/db.go | 4 +- coderd/externalauth/externalauth_test.go | 6 +-- coderd/httpmw/actor_test.go | 8 ++-- coderd/httpmw/apikey_test.go | 46 +++++++++---------- coderd/httpmw/groupparam_test.go | 6 +-- coderd/httpmw/organizationparam_test.go | 12 ++--- coderd/httpmw/ratelimit_test.go | 6 +-- coderd/httpmw/templateparam_test.go | 10 ++-- coderd/httpmw/templateversionparam_test.go | 8 ++-- coderd/httpmw/userparam_test.go | 4 +- coderd/httpmw/workspaceagentparam_test.go | 8 ++-- coderd/httpmw/workspacebuildparam_test.go | 8 ++-- coderd/httpmw/workspaceparam_test.go | 10 ++-- coderd/httpmw/workspaceproxy_test.go | 26 +++++------ coderd/httpmw/workspaceresourceparam_test.go | 10 ++-- coderd/metricscache/metricscache_test.go | 8 ++-- .../prometheusmetrics_test.go | 14 +++--- coderd/provisionerdserver/acquirer_test.go | 4 +- .../provisionerdserver_internal_test.go | 8 ++-- .../provisionerdserver_test.go | 16 +++---- coderd/telemetry/telemetry_test.go | 8 ++-- coderd/updatecheck/updatecheck_test.go | 6 +-- enterprise/audit/audit_test.go | 4 +- enterprise/audit/backends/postgres_test.go | 4 +- enterprise/coderd/coderd_test.go | 6 +-- .../coderd/coderdenttest/coderdenttest.go | 6 +-- .../coderd/dormancy/dormantusersjob_test.go | 4 +- enterprise/coderd/license/license_test.go | 46 +++++++++---------- .../coderd/proxyhealth/proxyhealth_test.go | 10 ++-- enterprise/replicasync/replicasync_test.go | 4 +- enterprise/trialer/trialer_test.go | 4 +- scripts/dbgen/main.go | 12 ++--- site/site_test.go | 6 +-- 42 files changed, 215 insertions(+), 215 deletions(-) rename coderd/database/{dbfake/dbfake.go => dbmem/dbmem.go} (99%) rename coderd/database/{dbfake/dbfake_test.go => dbmem/dbmem_test.go} (97%) diff --git a/.vscode/settings.json b/.vscode/settings.json index 0664d7e81c..6f726162d2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -20,7 +20,7 @@ "codersdk", "cronstrue", "databasefake", - "dbfake", + "dbmem", "dbgen", "dbtype", "DERP", diff --git a/Makefile b/Makefile index 948984d7c6..72e44308c6 100644 --- a/Makefile +++ b/Makefile @@ -448,7 +448,7 @@ lint/helm: DB_GEN_FILES := \ coderd/database/querier.go \ coderd/database/unique_constraint.go \ - coderd/database/dbfake/dbfake.go \ + coderd/database/dbmem/dbmem.go \ coderd/database/dbmetrics/dbmetrics.go \ coderd/database/dbauthz/dbauthz.go \ coderd/database/dbmock/dbmock.go diff --git a/cli/server.go b/cli/server.go index 9b10687ba3..6175584038 100644 --- a/cli/server.go +++ b/cli/server.go @@ -68,7 +68,7 @@ import ( "github.com/coder/coder/v2/coderd/autobuild" "github.com/coder/coder/v2/coderd/batchstats" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbfake" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/coderd/database/dbmetrics" "github.com/coder/coder/v2/coderd/database/dbpurge" "github.com/coder/coder/v2/coderd/database/migrations" @@ -542,7 +542,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd. AppHostname: appHostname, AppHostnameRegex: appHostnameRegex, Logger: logger.Named("coderd"), - Database: dbfake.New(), + Database: dbmem.New(), BaseDERPMap: derpMap, Pubsub: pubsub.NewInMemory(), CacheDir: cacheDir, @@ -633,7 +633,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd. if vals.InMemoryDatabase { // This is only used for testing. - options.Database = dbfake.New() + options.Database = dbmem.New() options.Pubsub = pubsub.NewInMemory() } else { sqlDB, err := ConnectToPostgres(ctx, logger, sqlDriver, vals.PostgresURL.String()) diff --git a/coderd/database/dbauthz/dbauthz_test.go b/coderd/database/dbauthz/dbauthz_test.go index a5847839b2..48239450eb 100644 --- a/coderd/database/dbauthz/dbauthz_test.go +++ b/coderd/database/dbauthz/dbauthz_test.go @@ -16,8 +16,8 @@ import ( "github.com/coder/coder/v2/coderd/coderdtest" "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/dbgen" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/coderd/database/dbtime" "github.com/coder/coder/v2/coderd/rbac" "github.com/coder/coder/v2/coderd/util/slice" @@ -62,7 +62,7 @@ func TestAsNoActor(t *testing.T) { func TestPing(t *testing.T) { t.Parallel() - q := dbauthz.New(dbfake.New(), &coderdtest.RecordingAuthorizer{}, slog.Make(), accessControlStorePointer()) + q := dbauthz.New(dbmem.New(), &coderdtest.RecordingAuthorizer{}, slog.Make(), accessControlStorePointer()) _, err := q.Ping(context.Background()) require.NoError(t, err, "must not error") } @@ -71,7 +71,7 @@ func TestPing(t *testing.T) { func TestInTX(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() q := dbauthz.New(db, &coderdtest.RecordingAuthorizer{ Wrapped: &coderdtest.FakeAuthorizer{AlwaysReturn: xerrors.New("custom error")}, }, slog.Make(), accessControlStorePointer()) @@ -99,7 +99,7 @@ func TestNew(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() exp = dbgen.Workspace(t, db, database.Workspace{}) rec = &coderdtest.RecordingAuthorizer{ Wrapped: &coderdtest.FakeAuthorizer{AlwaysReturn: nil}, @@ -126,7 +126,7 @@ func TestNew(t *testing.T) { // as only the first db call will be made. But it is better than nothing. func TestDBAuthzRecursive(t *testing.T) { t.Parallel() - q := dbauthz.New(dbfake.New(), &coderdtest.RecordingAuthorizer{ + q := dbauthz.New(dbmem.New(), &coderdtest.RecordingAuthorizer{ Wrapped: &coderdtest.FakeAuthorizer{AlwaysReturn: nil}, }, slog.Make(), accessControlStorePointer()) actor := rbac.Subject{ diff --git a/coderd/database/dbauthz/setup_test.go b/coderd/database/dbauthz/setup_test.go index 968b882f2d..304b8673a9 100644 --- a/coderd/database/dbauthz/setup_test.go +++ b/coderd/database/dbauthz/setup_test.go @@ -20,7 +20,7 @@ import ( "github.com/coder/coder/v2/coderd/coderdtest" "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/dbmock" "github.com/coder/coder/v2/coderd/rbac" "github.com/coder/coder/v2/coderd/rbac/regosql" @@ -104,7 +104,7 @@ func (s *MethodTestSuite) Subtest(testCaseF func(db database.Store, check *expec methodName := names[len(names)-1] s.methodAccounting[methodName]++ - db := dbfake.New() + db := dbmem.New() fakeAuthorizer := &coderdtest.FakeAuthorizer{ AlwaysReturn: nil, } diff --git a/coderd/database/dbgen/dbgen_test.go b/coderd/database/dbgen/dbgen_test.go index d7d961b1ae..531c8bb25c 100644 --- a/coderd/database/dbgen/dbgen_test.go +++ b/coderd/database/dbgen/dbgen_test.go @@ -8,8 +8,8 @@ import ( "github.com/stretchr/testify/require" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbfake" "github.com/coder/coder/v2/coderd/database/dbgen" + "github.com/coder/coder/v2/coderd/database/dbmem" ) func TestGenerator(t *testing.T) { @@ -17,7 +17,7 @@ func TestGenerator(t *testing.T) { t.Run("AuditLog", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() _ = dbgen.AuditLog(t, db, database.AuditLog{}) logs := must(db.GetAuditLogsOffset(context.Background(), database.GetAuditLogsOffsetParams{Limit: 1})) require.Len(t, logs, 1) @@ -25,28 +25,28 @@ func TestGenerator(t *testing.T) { t.Run("APIKey", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() exp, _ := dbgen.APIKey(t, db, database.APIKey{}) require.Equal(t, exp, must(db.GetAPIKeyByID(context.Background(), exp.ID))) }) t.Run("File", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() exp := dbgen.File(t, db, database.File{}) require.Equal(t, exp, must(db.GetFileByID(context.Background(), exp.ID))) }) t.Run("UserLink", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() exp := dbgen.UserLink(t, db, database.UserLink{}) require.Equal(t, exp, must(db.GetUserLinkByLinkedID(context.Background(), exp.LinkedID))) }) t.Run("GitAuthLink", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() exp := dbgen.ExternalAuthLink(t, db, database.ExternalAuthLink{}) require.Equal(t, exp, must(db.GetExternalAuthLink(context.Background(), database.GetExternalAuthLinkParams{ ProviderID: exp.ProviderID, @@ -56,28 +56,28 @@ func TestGenerator(t *testing.T) { t.Run("WorkspaceResource", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() exp := dbgen.WorkspaceResource(t, db, database.WorkspaceResource{}) require.Equal(t, exp, must(db.GetWorkspaceResourceByID(context.Background(), exp.ID))) }) t.Run("WorkspaceApp", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() exp := dbgen.WorkspaceApp(t, db, database.WorkspaceApp{}) require.Equal(t, exp, must(db.GetWorkspaceAppsByAgentID(context.Background(), exp.AgentID))[0]) }) t.Run("WorkspaceResourceMetadata", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() exp := dbgen.WorkspaceResourceMetadatums(t, db, database.WorkspaceResourceMetadatum{}) require.Equal(t, exp, must(db.GetWorkspaceResourceMetadataByResourceIDs(context.Background(), []uuid.UUID{exp[0].WorkspaceResourceID}))) }) t.Run("WorkspaceProxy", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() exp, secret := dbgen.WorkspaceProxy(t, db, database.WorkspaceProxy{}) require.Len(t, secret, 64) require.Equal(t, exp, must(db.GetWorkspaceProxyByID(context.Background(), exp.ID))) @@ -85,21 +85,21 @@ func TestGenerator(t *testing.T) { t.Run("Job", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() exp := dbgen.ProvisionerJob(t, db, nil, database.ProvisionerJob{}) require.Equal(t, exp, must(db.GetProvisionerJobByID(context.Background(), exp.ID))) }) t.Run("Group", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() exp := dbgen.Group(t, db, database.Group{}) require.Equal(t, exp, must(db.GetGroupByID(context.Background(), exp.ID))) }) t.Run("GroupMember", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() g := dbgen.Group(t, db, database.Group{}) u := dbgen.User(t, db, database.User{}) exp := []database.User{u} @@ -110,14 +110,14 @@ func TestGenerator(t *testing.T) { t.Run("Organization", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() exp := dbgen.Organization(t, db, database.Organization{}) require.Equal(t, exp, must(db.GetOrganizationByID(context.Background(), exp.ID))) }) t.Run("OrganizationMember", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() exp := dbgen.OrganizationMember(t, db, database.OrganizationMember{}) require.Equal(t, exp, must(db.GetOrganizationMemberByUserID(context.Background(), database.GetOrganizationMemberByUserIDParams{ OrganizationID: exp.OrganizationID, @@ -127,49 +127,49 @@ func TestGenerator(t *testing.T) { t.Run("Workspace", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() exp := dbgen.Workspace(t, db, database.Workspace{}) require.Equal(t, exp, must(db.GetWorkspaceByID(context.Background(), exp.ID))) }) t.Run("WorkspaceAgent", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() exp := dbgen.WorkspaceAgent(t, db, database.WorkspaceAgent{}) require.Equal(t, exp, must(db.GetWorkspaceAgentByID(context.Background(), exp.ID))) }) t.Run("Template", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() exp := dbgen.Template(t, db, database.Template{}) require.Equal(t, exp, must(db.GetTemplateByID(context.Background(), exp.ID))) }) t.Run("TemplateVersion", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() exp := dbgen.TemplateVersion(t, db, database.TemplateVersion{}) require.Equal(t, exp, must(db.GetTemplateVersionByID(context.Background(), exp.ID))) }) t.Run("WorkspaceBuild", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() exp := dbgen.WorkspaceBuild(t, db, database.WorkspaceBuild{}) require.Equal(t, exp, must(db.GetWorkspaceBuildByID(context.Background(), exp.ID))) }) t.Run("User", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() exp := dbgen.User(t, db, database.User{}) require.Equal(t, exp, must(db.GetUserByID(context.Background(), exp.ID))) }) t.Run("SSHKey", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() exp := dbgen.GitSSHKey(t, db, database.GitSSHKey{}) require.Equal(t, exp, must(db.GetGitSSHKey(context.Background(), exp.UserID))) }) diff --git a/coderd/database/dbfake/dbfake.go b/coderd/database/dbmem/dbmem.go similarity index 99% rename from coderd/database/dbfake/dbfake.go rename to coderd/database/dbmem/dbmem.go index e2ddde14e2..a0e4847360 100644 --- a/coderd/database/dbfake/dbfake.go +++ b/coderd/database/dbmem/dbmem.go @@ -1,4 +1,4 @@ -package dbfake +package dbmem import ( "context" @@ -705,7 +705,7 @@ func provisonerJobStatus(j database.ProvisionerJob) database.ProvisionerJobStatu return database.ProvisionerJobStatusRunning } -// isNull is only used in dbfake, so reflect is ok. Use this to make the logic +// isNull is only used in dbmem, so reflect is ok. Use this to make the logic // look more similar to the postgres. func isNull(v interface{}) bool { return !isNotNull(v) @@ -4868,7 +4868,7 @@ func (q *FakeQuerier) InsertUser(_ context.Context, arg database.InsertUserParam return database.User{}, err } - // There is a common bug when using dbfake that 2 inserted users have the + // There is a common bug when using dbmem that 2 inserted users have the // same created_at time. This causes user order to not be deterministic, // which breaks some unit tests. // To fix this, we make sure that the created_at time is always greater diff --git a/coderd/database/dbfake/dbfake_test.go b/coderd/database/dbmem/dbmem_test.go similarity index 97% rename from coderd/database/dbfake/dbfake_test.go rename to coderd/database/dbmem/dbmem_test.go index 3cbc54042f..e7d7bd76bd 100644 --- a/coderd/database/dbfake/dbfake_test.go +++ b/coderd/database/dbmem/dbmem_test.go @@ -1,4 +1,4 @@ -package dbfake_test +package dbmem_test import ( "context" @@ -11,8 +11,8 @@ import ( "github.com/stretchr/testify/require" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbfake" "github.com/coder/coder/v2/coderd/database/dbgen" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/coderd/database/dbtime" ) @@ -20,7 +20,7 @@ import ( func TestInTx(t *testing.T) { t.Parallel() - uut := dbfake.New() + uut := dbmem.New() inTx := make(chan any) queriesDone := make(chan any) @@ -67,7 +67,7 @@ func TestInTx(t *testing.T) { func TestUserOrder(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() now := dbtime.Now() usernames := []string{"b-user", "d-user", "a-user", "c-user", "e-user"} @@ -88,7 +88,7 @@ func TestUserOrder(t *testing.T) { func TestProxyByHostname(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() // Insert a bunch of different proxies. proxies := []struct { diff --git a/coderd/database/dbpurge/dbpurge_test.go b/coderd/database/dbpurge/dbpurge_test.go index f83d1b81a1..64fc74b477 100644 --- a/coderd/database/dbpurge/dbpurge_test.go +++ b/coderd/database/dbpurge/dbpurge_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/require" "cdr.dev/slog/sloggers/slogtest" - "github.com/coder/coder/v2/coderd/database/dbfake" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/coderd/database/dbpurge" ) @@ -20,7 +20,7 @@ func TestMain(m *testing.M) { // Ensures no goroutines leak. func TestPurge(t *testing.T) { t.Parallel() - purger := dbpurge.New(context.Background(), slogtest.Make(t, nil), dbfake.New()) + purger := dbpurge.New(context.Background(), slogtest.Make(t, nil), dbmem.New()) err := purger.Close() require.NoError(t, err) } diff --git a/coderd/database/dbtestutil/db.go b/coderd/database/dbtestutil/db.go index 65e1afecc7..c179917c05 100644 --- a/coderd/database/dbtestutil/db.go +++ b/coderd/database/dbtestutil/db.go @@ -18,7 +18,7 @@ import ( "golang.org/x/xerrors" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbfake" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/coderd/database/postgres" "github.com/coder/coder/v2/coderd/database/pubsub" ) @@ -79,7 +79,7 @@ func NewDB(t testing.TB, opts ...Option) (database.Store, pubsub.Pubsub) { opt(&o) } - db := dbfake.New() + db := dbmem.New() ps := pubsub.NewInMemory() if WillUsePostgres() { connectionURL := os.Getenv("CODER_PG_CONNECTION_URL") diff --git a/coderd/externalauth/externalauth_test.go b/coderd/externalauth/externalauth_test.go index d790c32989..2108063b91 100644 --- a/coderd/externalauth/externalauth_test.go +++ b/coderd/externalauth/externalauth_test.go @@ -19,7 +19,7 @@ import ( "github.com/coder/coder/v2/coderd/coderdtest/oidctest" "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/externalauth" "github.com/coder/coder/v2/codersdk" "github.com/coder/coder/v2/testutil" @@ -223,7 +223,7 @@ func TestRefreshToken(t *testing.T) { t.Run("Updates", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() validateCalls := 0 refreshCalls := 0 fake, config, link := setupOauth2Test(t, testConfig{ @@ -265,7 +265,7 @@ func TestRefreshToken(t *testing.T) { t.Run("WithExtra", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() fake, config, link := setupOauth2Test(t, testConfig{ FakeIDPOpts: []oidctest.FakeIDPOpt{ oidctest.WithMutateToken(func(token map[string]interface{}) { diff --git a/coderd/httpmw/actor_test.go b/coderd/httpmw/actor_test.go index fc95801662..ef05a8cb3a 100644 --- a/coderd/httpmw/actor_test.go +++ b/coderd/httpmw/actor_test.go @@ -11,8 +11,8 @@ import ( "github.com/stretchr/testify/require" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbfake" "github.com/coder/coder/v2/coderd/database/dbgen" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/coderd/database/dbtime" "github.com/coder/coder/v2/coderd/httpmw" "github.com/coder/coder/v2/codersdk" @@ -38,7 +38,7 @@ func TestRequireAPIKeyOrWorkspaceProxyAuth(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() user = dbgen.User(t, db, database.User{}) _, token = dbgen.APIKey(t, db, database.APIKey{ UserID: user.ID, @@ -75,7 +75,7 @@ func TestRequireAPIKeyOrWorkspaceProxyAuth(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() user = dbgen.User(t, db, database.User{}) _, userToken = dbgen.APIKey(t, db, database.APIKey{ UserID: user.ID, @@ -114,7 +114,7 @@ func TestRequireAPIKeyOrWorkspaceProxyAuth(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() proxy, token = dbgen.WorkspaceProxy(t, db, database.WorkspaceProxy{}) r = httptest.NewRequest("GET", "/", nil) diff --git a/coderd/httpmw/apikey_test.go b/coderd/httpmw/apikey_test.go index f3ceba017d..33ba90a4d7 100644 --- a/coderd/httpmw/apikey_test.go +++ b/coderd/httpmw/apikey_test.go @@ -19,8 +19,8 @@ import ( "golang.org/x/oauth2" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbfake" "github.com/coder/coder/v2/coderd/database/dbgen" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/coderd/database/dbtime" "github.com/coder/coder/v2/coderd/httpapi" "github.com/coder/coder/v2/coderd/httpmw" @@ -48,7 +48,7 @@ func TestAPIKey(t *testing.T) { t.Run("NoCookie", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() r = httptest.NewRequest("GET", "/", nil) rw = httptest.NewRecorder() ) @@ -64,7 +64,7 @@ func TestAPIKey(t *testing.T) { t.Run("NoCookieRedirects", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() r = httptest.NewRequest("GET", "/", nil) rw = httptest.NewRecorder() ) @@ -83,7 +83,7 @@ func TestAPIKey(t *testing.T) { t.Run("InvalidFormat", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() r = httptest.NewRequest("GET", "/", nil) rw = httptest.NewRecorder() ) @@ -101,7 +101,7 @@ func TestAPIKey(t *testing.T) { t.Run("InvalidIDLength", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() r = httptest.NewRequest("GET", "/", nil) rw = httptest.NewRecorder() ) @@ -119,7 +119,7 @@ func TestAPIKey(t *testing.T) { t.Run("InvalidSecretLength", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() r = httptest.NewRequest("GET", "/", nil) rw = httptest.NewRecorder() ) @@ -137,7 +137,7 @@ func TestAPIKey(t *testing.T) { t.Run("NotFound", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() id, secret = randomAPIKeyParts() r = httptest.NewRequest("GET", "/", nil) rw = httptest.NewRecorder() @@ -156,7 +156,7 @@ func TestAPIKey(t *testing.T) { t.Run("UserLinkNotFound", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() r = httptest.NewRequest("GET", "/", nil) rw = httptest.NewRecorder() user = dbgen.User(t, db, database.User{ @@ -184,7 +184,7 @@ func TestAPIKey(t *testing.T) { t.Run("InvalidSecret", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() r = httptest.NewRequest("GET", "/", nil) rw = httptest.NewRecorder() user = dbgen.User(t, db, database.User{}) @@ -209,7 +209,7 @@ func TestAPIKey(t *testing.T) { t.Run("Expired", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() user = dbgen.User(t, db, database.User{}) _, token = dbgen.APIKey(t, db, database.APIKey{ UserID: user.ID, @@ -238,7 +238,7 @@ func TestAPIKey(t *testing.T) { t.Run("Valid", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() user = dbgen.User(t, db, database.User{}) sentAPIKey, token = dbgen.APIKey(t, db, database.APIKey{ UserID: user.ID, @@ -273,7 +273,7 @@ func TestAPIKey(t *testing.T) { t.Run("ValidWithScope", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() user = dbgen.User(t, db, database.User{}) _, token = dbgen.APIKey(t, db, database.APIKey{ UserID: user.ID, @@ -310,7 +310,7 @@ func TestAPIKey(t *testing.T) { t.Run("QueryParameter", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() user = dbgen.User(t, db, database.User{}) _, token = dbgen.APIKey(t, db, database.APIKey{ UserID: user.ID, @@ -342,7 +342,7 @@ func TestAPIKey(t *testing.T) { t.Run("ValidUpdateLastUsed", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() user = dbgen.User(t, db, database.User{}) sentAPIKey, token = dbgen.APIKey(t, db, database.APIKey{ UserID: user.ID, @@ -373,7 +373,7 @@ func TestAPIKey(t *testing.T) { t.Run("ValidUpdateExpiry", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() user = dbgen.User(t, db, database.User{}) sentAPIKey, token = dbgen.APIKey(t, db, database.APIKey{ UserID: user.ID, @@ -404,7 +404,7 @@ func TestAPIKey(t *testing.T) { t.Run("NoRefresh", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() user = dbgen.User(t, db, database.User{}) sentAPIKey, token = dbgen.APIKey(t, db, database.APIKey{ UserID: user.ID, @@ -436,7 +436,7 @@ func TestAPIKey(t *testing.T) { t.Run("OAuthNotExpired", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() user = dbgen.User(t, db, database.User{}) sentAPIKey, token = dbgen.APIKey(t, db, database.APIKey{ UserID: user.ID, @@ -472,7 +472,7 @@ func TestAPIKey(t *testing.T) { t.Run("OAuthRefresh", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() user = dbgen.User(t, db, database.User{}) sentAPIKey, token = dbgen.APIKey(t, db, database.APIKey{ UserID: user.ID, @@ -520,7 +520,7 @@ func TestAPIKey(t *testing.T) { t.Run("RemoteIPUpdates", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() user = dbgen.User(t, db, database.User{}) sentAPIKey, token = dbgen.APIKey(t, db, database.APIKey{ UserID: user.ID, @@ -551,7 +551,7 @@ func TestAPIKey(t *testing.T) { t.Run("RedirectToLogin", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() r = httptest.NewRequest("GET", "/", nil) rw = httptest.NewRecorder() ) @@ -572,7 +572,7 @@ func TestAPIKey(t *testing.T) { t.Run("Optional", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() r = httptest.NewRequest("GET", "/", nil) rw = httptest.NewRecorder() @@ -603,7 +603,7 @@ func TestAPIKey(t *testing.T) { t.Run("Tokens", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() user = dbgen.User(t, db, database.User{}) sentAPIKey, token = dbgen.APIKey(t, db, database.APIKey{ UserID: user.ID, @@ -636,7 +636,7 @@ func TestAPIKey(t *testing.T) { t.Run("MissongConfig", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() user = dbgen.User(t, db, database.User{}) _, token = dbgen.APIKey(t, db, database.APIKey{ UserID: user.ID, diff --git a/coderd/httpmw/groupparam_test.go b/coderd/httpmw/groupparam_test.go index a0c50ee085..a44fbc52df 100644 --- a/coderd/httpmw/groupparam_test.go +++ b/coderd/httpmw/groupparam_test.go @@ -11,8 +11,8 @@ import ( "github.com/stretchr/testify/require" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbfake" "github.com/coder/coder/v2/coderd/database/dbgen" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/coderd/httpmw" ) @@ -23,7 +23,7 @@ func TestGroupParam(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() group = dbgen.Group(t, db, database.Group{}) r = httptest.NewRequest("GET", "/", nil) w = httptest.NewRecorder() @@ -52,7 +52,7 @@ func TestGroupParam(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() group = dbgen.Group(t, db, database.Group{}) r = httptest.NewRequest("GET", "/", nil) w = httptest.NewRecorder() diff --git a/coderd/httpmw/organizationparam_test.go b/coderd/httpmw/organizationparam_test.go index 0457168132..d492353e68 100644 --- a/coderd/httpmw/organizationparam_test.go +++ b/coderd/httpmw/organizationparam_test.go @@ -11,8 +11,8 @@ import ( "github.com/stretchr/testify/require" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbfake" "github.com/coder/coder/v2/coderd/database/dbgen" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/coderd/database/dbtime" "github.com/coder/coder/v2/coderd/httpmw" "github.com/coder/coder/v2/codersdk" @@ -38,7 +38,7 @@ func TestOrganizationParam(t *testing.T) { t.Run("None", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() rw = httptest.NewRecorder() r, _ = setupAuthentication(db) rtr = chi.NewRouter() @@ -60,7 +60,7 @@ func TestOrganizationParam(t *testing.T) { t.Run("NotFound", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() rw = httptest.NewRecorder() r, _ = setupAuthentication(db) rtr = chi.NewRouter() @@ -83,7 +83,7 @@ func TestOrganizationParam(t *testing.T) { t.Run("InvalidUUID", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() rw = httptest.NewRecorder() r, _ = setupAuthentication(db) rtr = chi.NewRouter() @@ -106,7 +106,7 @@ func TestOrganizationParam(t *testing.T) { t.Run("NotInOrganization", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() rw = httptest.NewRecorder() r, u = setupAuthentication(db) rtr = chi.NewRouter() @@ -139,7 +139,7 @@ func TestOrganizationParam(t *testing.T) { t.Run("Success", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() rw = httptest.NewRecorder() r, user = setupAuthentication(db) rtr = chi.NewRouter() diff --git a/coderd/httpmw/ratelimit_test.go b/coderd/httpmw/ratelimit_test.go index edb368829c..a320e05af7 100644 --- a/coderd/httpmw/ratelimit_test.go +++ b/coderd/httpmw/ratelimit_test.go @@ -13,8 +13,8 @@ import ( "github.com/stretchr/testify/require" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbfake" "github.com/coder/coder/v2/coderd/database/dbgen" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/coderd/httpmw" "github.com/coder/coder/v2/coderd/rbac" "github.com/coder/coder/v2/codersdk" @@ -71,7 +71,7 @@ func TestRateLimit(t *testing.T) { t.Run("RegularUser", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() u := dbgen.User(t, db, database.User{}) _, key := dbgen.APIKey(t, db, database.APIKey{UserID: u.ID}) @@ -114,7 +114,7 @@ func TestRateLimit(t *testing.T) { t.Run("OwnerBypass", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() u := dbgen.User(t, db, database.User{ RBACRoles: []string{rbac.RoleOwner()}, diff --git a/coderd/httpmw/templateparam_test.go b/coderd/httpmw/templateparam_test.go index d860878190..18b0b2f584 100644 --- a/coderd/httpmw/templateparam_test.go +++ b/coderd/httpmw/templateparam_test.go @@ -11,8 +11,8 @@ import ( "github.com/stretchr/testify/require" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbfake" "github.com/coder/coder/v2/coderd/database/dbgen" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/coderd/httpmw" "github.com/coder/coder/v2/codersdk" ) @@ -43,7 +43,7 @@ func TestTemplateParam(t *testing.T) { t.Run("None", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() rtr := chi.NewRouter() rtr.Use(httpmw.ExtractTemplateParam(db)) rtr.Get("/", nil) @@ -58,7 +58,7 @@ func TestTemplateParam(t *testing.T) { t.Run("NotFound", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() rtr := chi.NewRouter() rtr.Use(httpmw.ExtractTemplateParam(db)) rtr.Get("/", nil) @@ -75,7 +75,7 @@ func TestTemplateParam(t *testing.T) { t.Run("BadUUID", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() rtr := chi.NewRouter() rtr.Use(httpmw.ExtractTemplateParam(db)) rtr.Get("/", nil) @@ -92,7 +92,7 @@ func TestTemplateParam(t *testing.T) { t.Run("Template", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() rtr := chi.NewRouter() rtr.Use( httpmw.ExtractAPIKeyMW(httpmw.ExtractAPIKeyConfig{ diff --git a/coderd/httpmw/templateversionparam_test.go b/coderd/httpmw/templateversionparam_test.go index 1cf4da6e83..3f67aafbcf 100644 --- a/coderd/httpmw/templateversionparam_test.go +++ b/coderd/httpmw/templateversionparam_test.go @@ -11,8 +11,8 @@ import ( "github.com/stretchr/testify/require" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbfake" "github.com/coder/coder/v2/coderd/database/dbgen" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/coderd/httpmw" "github.com/coder/coder/v2/codersdk" ) @@ -47,7 +47,7 @@ func TestTemplateVersionParam(t *testing.T) { t.Run("None", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() rtr := chi.NewRouter() rtr.Use(httpmw.ExtractTemplateVersionParam(db)) rtr.Get("/", nil) @@ -62,7 +62,7 @@ func TestTemplateVersionParam(t *testing.T) { t.Run("NotFound", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() rtr := chi.NewRouter() rtr.Use(httpmw.ExtractTemplateVersionParam(db)) rtr.Get("/", nil) @@ -79,7 +79,7 @@ func TestTemplateVersionParam(t *testing.T) { t.Run("TemplateVersion", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() rtr := chi.NewRouter() rtr.Use( httpmw.ExtractAPIKeyMW(httpmw.ExtractAPIKeyConfig{ diff --git a/coderd/httpmw/userparam_test.go b/coderd/httpmw/userparam_test.go index 040948ff60..bda00193e9 100644 --- a/coderd/httpmw/userparam_test.go +++ b/coderd/httpmw/userparam_test.go @@ -10,8 +10,8 @@ import ( "github.com/stretchr/testify/require" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbfake" "github.com/coder/coder/v2/coderd/database/dbgen" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/coderd/httpmw" "github.com/coder/coder/v2/codersdk" ) @@ -20,7 +20,7 @@ func TestUserParam(t *testing.T) { t.Parallel() setup := func(t *testing.T) (database.Store, *httptest.ResponseRecorder, *http.Request) { var ( - db = dbfake.New() + db = dbmem.New() r = httptest.NewRequest("GET", "/", nil) rw = httptest.NewRecorder() ) diff --git a/coderd/httpmw/workspaceagentparam_test.go b/coderd/httpmw/workspaceagentparam_test.go index 0ac2bb9eb0..16f81124d1 100644 --- a/coderd/httpmw/workspaceagentparam_test.go +++ b/coderd/httpmw/workspaceagentparam_test.go @@ -11,8 +11,8 @@ import ( "github.com/stretchr/testify/require" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbfake" "github.com/coder/coder/v2/coderd/database/dbgen" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/coderd/httpmw" "github.com/coder/coder/v2/codersdk" ) @@ -61,7 +61,7 @@ func TestWorkspaceAgentParam(t *testing.T) { t.Run("None", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() rtr := chi.NewRouter() rtr.Use(httpmw.ExtractWorkspaceBuildParam(db)) rtr.Get("/", nil) @@ -76,7 +76,7 @@ func TestWorkspaceAgentParam(t *testing.T) { t.Run("NotFound", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() rtr := chi.NewRouter() rtr.Use(httpmw.ExtractWorkspaceAgentParam(db)) rtr.Get("/", nil) @@ -93,7 +93,7 @@ func TestWorkspaceAgentParam(t *testing.T) { t.Run("WorkspaceAgent", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() rtr := chi.NewRouter() rtr.Use( httpmw.ExtractAPIKeyMW(httpmw.ExtractAPIKeyConfig{ diff --git a/coderd/httpmw/workspacebuildparam_test.go b/coderd/httpmw/workspacebuildparam_test.go index bade2b19d8..fb2d2f044f 100644 --- a/coderd/httpmw/workspacebuildparam_test.go +++ b/coderd/httpmw/workspacebuildparam_test.go @@ -11,8 +11,8 @@ import ( "github.com/stretchr/testify/require" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbfake" "github.com/coder/coder/v2/coderd/database/dbgen" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/coderd/httpmw" "github.com/coder/coder/v2/codersdk" ) @@ -43,7 +43,7 @@ func TestWorkspaceBuildParam(t *testing.T) { t.Run("None", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() rtr := chi.NewRouter() rtr.Use(httpmw.ExtractWorkspaceBuildParam(db)) rtr.Get("/", nil) @@ -58,7 +58,7 @@ func TestWorkspaceBuildParam(t *testing.T) { t.Run("NotFound", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() rtr := chi.NewRouter() rtr.Use(httpmw.ExtractWorkspaceBuildParam(db)) rtr.Get("/", nil) @@ -75,7 +75,7 @@ func TestWorkspaceBuildParam(t *testing.T) { t.Run("WorkspaceBuild", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() rtr := chi.NewRouter() rtr.Use( httpmw.ExtractAPIKeyMW(httpmw.ExtractAPIKeyConfig{ diff --git a/coderd/httpmw/workspaceparam_test.go b/coderd/httpmw/workspaceparam_test.go index d65fb53f8f..54daf661c3 100644 --- a/coderd/httpmw/workspaceparam_test.go +++ b/coderd/httpmw/workspaceparam_test.go @@ -16,8 +16,8 @@ import ( "github.com/stretchr/testify/require" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbfake" "github.com/coder/coder/v2/coderd/database/dbgen" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/coderd/database/dbtime" "github.com/coder/coder/v2/coderd/httpmw" "github.com/coder/coder/v2/codersdk" @@ -75,7 +75,7 @@ func TestWorkspaceParam(t *testing.T) { t.Run("None", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() rtr := chi.NewRouter() rtr.Use(httpmw.ExtractWorkspaceParam(db)) rtr.Get("/", nil) @@ -90,7 +90,7 @@ func TestWorkspaceParam(t *testing.T) { t.Run("NotFound", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() rtr := chi.NewRouter() rtr.Use(httpmw.ExtractWorkspaceParam(db)) rtr.Get("/", nil) @@ -106,7 +106,7 @@ func TestWorkspaceParam(t *testing.T) { t.Run("Found", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() rtr := chi.NewRouter() rtr.Use( httpmw.ExtractAPIKeyMW(httpmw.ExtractAPIKeyConfig{ @@ -348,7 +348,7 @@ type setupConfig struct { func setupWorkspaceWithAgents(t testing.TB, cfg setupConfig) (database.Store, *http.Request) { t.Helper() - db := dbfake.New() + db := dbmem.New() var ( user = dbgen.User(t, db, database.User{}) diff --git a/coderd/httpmw/workspaceproxy_test.go b/coderd/httpmw/workspaceproxy_test.go index 27b85643ce..b0a028f3ca 100644 --- a/coderd/httpmw/workspaceproxy_test.go +++ b/coderd/httpmw/workspaceproxy_test.go @@ -12,8 +12,8 @@ import ( "github.com/stretchr/testify/require" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbfake" "github.com/coder/coder/v2/coderd/database/dbgen" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/coderd/httpapi" "github.com/coder/coder/v2/coderd/httpmw" "github.com/coder/coder/v2/codersdk" @@ -33,7 +33,7 @@ func TestExtractWorkspaceProxy(t *testing.T) { t.Run("NoHeader", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() r = httptest.NewRequest("GET", "/", nil) rw = httptest.NewRecorder() ) @@ -48,7 +48,7 @@ func TestExtractWorkspaceProxy(t *testing.T) { t.Run("InvalidFormat", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() r = httptest.NewRequest("GET", "/", nil) rw = httptest.NewRecorder() ) @@ -65,7 +65,7 @@ func TestExtractWorkspaceProxy(t *testing.T) { t.Run("InvalidID", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() r = httptest.NewRequest("GET", "/", nil) rw = httptest.NewRecorder() ) @@ -82,7 +82,7 @@ func TestExtractWorkspaceProxy(t *testing.T) { t.Run("InvalidSecretLength", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() r = httptest.NewRequest("GET", "/", nil) rw = httptest.NewRecorder() ) @@ -99,7 +99,7 @@ func TestExtractWorkspaceProxy(t *testing.T) { t.Run("NotFound", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() r = httptest.NewRequest("GET", "/", nil) rw = httptest.NewRecorder() ) @@ -119,7 +119,7 @@ func TestExtractWorkspaceProxy(t *testing.T) { t.Run("InvalidSecret", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() r = httptest.NewRequest("GET", "/", nil) rw = httptest.NewRecorder() @@ -142,7 +142,7 @@ func TestExtractWorkspaceProxy(t *testing.T) { t.Run("Valid", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() r = httptest.NewRequest("GET", "/", nil) rw = httptest.NewRecorder() @@ -165,7 +165,7 @@ func TestExtractWorkspaceProxy(t *testing.T) { t.Run("Deleted", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() r = httptest.NewRequest("GET", "/", nil) rw = httptest.NewRecorder() @@ -201,7 +201,7 @@ func TestExtractWorkspaceProxyParam(t *testing.T) { t.Run("OKName", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() r = httptest.NewRequest("GET", "/", nil) rw = httptest.NewRecorder() @@ -225,7 +225,7 @@ func TestExtractWorkspaceProxyParam(t *testing.T) { t.Run("OKID", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() r = httptest.NewRequest("GET", "/", nil) rw = httptest.NewRecorder() @@ -249,7 +249,7 @@ func TestExtractWorkspaceProxyParam(t *testing.T) { t.Run("NotFound", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() r = httptest.NewRequest("GET", "/", nil) rw = httptest.NewRecorder() ) @@ -267,7 +267,7 @@ func TestExtractWorkspaceProxyParam(t *testing.T) { t.Run("FetchPrimary", func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() r = httptest.NewRequest("GET", "/", nil) rw = httptest.NewRecorder() deploymentID = uuid.New() diff --git a/coderd/httpmw/workspaceresourceparam_test.go b/coderd/httpmw/workspaceresourceparam_test.go index e61e4016cb..9549e8e6d3 100644 --- a/coderd/httpmw/workspaceresourceparam_test.go +++ b/coderd/httpmw/workspaceresourceparam_test.go @@ -11,8 +11,8 @@ import ( "github.com/stretchr/testify/require" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbfake" "github.com/coder/coder/v2/coderd/database/dbgen" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/coderd/httpmw" ) @@ -46,7 +46,7 @@ func TestWorkspaceResourceParam(t *testing.T) { t.Run("None", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() rtr := chi.NewRouter() rtr.Use(httpmw.ExtractWorkspaceResourceParam(db)) rtr.Get("/", nil) @@ -61,7 +61,7 @@ func TestWorkspaceResourceParam(t *testing.T) { t.Run("NotFound", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() rtr := chi.NewRouter() rtr.Use( httpmw.ExtractWorkspaceResourceParam(db), @@ -80,7 +80,7 @@ func TestWorkspaceResourceParam(t *testing.T) { t.Run("FoundBadJobType", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() rtr := chi.NewRouter() rtr.Use( httpmw.ExtractWorkspaceResourceParam(db), @@ -102,7 +102,7 @@ func TestWorkspaceResourceParam(t *testing.T) { t.Run("Found", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() rtr := chi.NewRouter() rtr.Use( httpmw.ExtractWorkspaceResourceParam(db), diff --git a/coderd/metricscache/metricscache_test.go b/coderd/metricscache/metricscache_test.go index 1d34668559..996b9940d0 100644 --- a/coderd/metricscache/metricscache_test.go +++ b/coderd/metricscache/metricscache_test.go @@ -11,8 +11,8 @@ import ( "cdr.dev/slog/sloggers/slogtest" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbfake" "github.com/coder/coder/v2/coderd/database/dbgen" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/coderd/database/dbtime" "github.com/coder/coder/v2/coderd/metricscache" "github.com/coder/coder/v2/codersdk" @@ -210,7 +210,7 @@ func TestCache_TemplateUsers(t *testing.T) { t.Run(tt.name, func(t *testing.T) { t.Parallel() var ( - db = dbfake.New() + db = dbmem.New() cache = metricscache.New(db, slogtest.Make(t, nil), metricscache.Intervals{ TemplateDAUs: testutil.IntervalFast, }) @@ -342,7 +342,7 @@ func TestCache_BuildTime(t *testing.T) { ctx := context.Background() var ( - db = dbfake.New() + db = dbmem.New() cache = metricscache.New(db, slogtest.Make(t, nil), metricscache.Intervals{ TemplateDAUs: testutil.IntervalFast, }) @@ -436,7 +436,7 @@ func TestCache_BuildTime(t *testing.T) { func TestCache_DeploymentStats(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() cache := metricscache.New(db, slogtest.Make(t, nil), metricscache.Intervals{ DeploymentStats: testutil.IntervalFast, }) diff --git a/coderd/prometheusmetrics/prometheusmetrics_test.go b/coderd/prometheusmetrics/prometheusmetrics_test.go index fb00ced6d9..8256c2f7e2 100644 --- a/coderd/prometheusmetrics/prometheusmetrics_test.go +++ b/coderd/prometheusmetrics/prometheusmetrics_test.go @@ -26,8 +26,8 @@ import ( "github.com/coder/coder/v2/coderd/coderdtest" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbfake" "github.com/coder/coder/v2/coderd/database/dbgen" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/coderd/prometheusmetrics" "github.com/coder/coder/v2/codersdk" "github.com/coder/coder/v2/codersdk/agentsdk" @@ -48,13 +48,13 @@ func TestActiveUsers(t *testing.T) { }{{ Name: "None", Database: func(t *testing.T) database.Store { - return dbfake.New() + return dbmem.New() }, Count: 0, }, { Name: "One", Database: func(t *testing.T) database.Store { - db := dbfake.New() + db := dbmem.New() dbgen.APIKey(t, db, database.APIKey{ LastUsed: dbtime.Now(), }) @@ -64,7 +64,7 @@ func TestActiveUsers(t *testing.T) { }, { Name: "OneWithExpired", Database: func(t *testing.T) database.Store { - db := dbfake.New() + db := dbmem.New() dbgen.APIKey(t, db, database.APIKey{ LastUsed: dbtime.Now(), @@ -81,7 +81,7 @@ func TestActiveUsers(t *testing.T) { }, { Name: "Multiple", Database: func(t *testing.T) database.Store { - db := dbfake.New() + db := dbmem.New() dbgen.APIKey(t, db, database.APIKey{ LastUsed: dbtime.Now(), }) @@ -200,13 +200,13 @@ func TestWorkspaces(t *testing.T) { }{{ Name: "None", Database: func() database.Store { - return dbfake.New() + return dbmem.New() }, Total: 0, }, { Name: "Multiple", Database: func() database.Store { - db := dbfake.New() + db := dbmem.New() insertCanceled(db) insertFailed(db) insertFailed(db) diff --git a/coderd/provisionerdserver/acquirer_test.go b/coderd/provisionerdserver/acquirer_test.go index 7036df817b..bed8eccb68 100644 --- a/coderd/provisionerdserver/acquirer_test.go +++ b/coderd/provisionerdserver/acquirer_test.go @@ -17,7 +17,7 @@ import ( "cdr.dev/slog" "cdr.dev/slog/sloggers/slogtest" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbfake" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/coderd/database/provisionerjobs" "github.com/coder/coder/v2/coderd/database/pubsub" "github.com/coder/coder/v2/coderd/provisionerdserver" @@ -31,7 +31,7 @@ func TestMain(m *testing.M) { // TestAcquirer_Store tests that a database.Store is accepted as a provisionerdserver.AcquirerStore func TestAcquirer_Store(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() ps := pubsub.NewInMemory() ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort) defer cancel() diff --git a/coderd/provisionerdserver/provisionerdserver_internal_test.go b/coderd/provisionerdserver/provisionerdserver_internal_test.go index 427a1c428b..acf9508307 100644 --- a/coderd/provisionerdserver/provisionerdserver_internal_test.go +++ b/coderd/provisionerdserver/provisionerdserver_internal_test.go @@ -10,8 +10,8 @@ import ( "golang.org/x/oauth2" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbfake" "github.com/coder/coder/v2/coderd/database/dbgen" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/coderd/database/dbtime" "github.com/coder/coder/v2/testutil" ) @@ -21,14 +21,14 @@ func TestObtainOIDCAccessToken(t *testing.T) { ctx := context.Background() t.Run("NoToken", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() _, err := obtainOIDCAccessToken(ctx, db, nil, uuid.Nil) require.NoError(t, err) }) t.Run("InvalidConfig", func(t *testing.T) { // We still want OIDC to succeed even if exchanging the token fails. t.Parallel() - db := dbfake.New() + db := dbmem.New() user := dbgen.User(t, db, database.User{}) dbgen.UserLink(t, db, database.UserLink{ UserID: user.ID, @@ -40,7 +40,7 @@ func TestObtainOIDCAccessToken(t *testing.T) { }) t.Run("Exchange", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() user := dbgen.User(t, db, database.User{}) dbgen.UserLink(t, db, database.UserLink{ UserID: user.ID, diff --git a/coderd/provisionerdserver/provisionerdserver_test.go b/coderd/provisionerdserver/provisionerdserver_test.go index db97724c72..bc16b01c1e 100644 --- a/coderd/provisionerdserver/provisionerdserver_test.go +++ b/coderd/provisionerdserver/provisionerdserver_test.go @@ -27,8 +27,8 @@ import ( "github.com/coder/coder/v2/cli/clibase" "github.com/coder/coder/v2/coderd/audit" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbfake" "github.com/coder/coder/v2/coderd/database/dbgen" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/coderd/database/dbtime" "github.com/coder/coder/v2/coderd/database/pubsub" "github.com/coder/coder/v2/coderd/externalauth" @@ -1525,7 +1525,7 @@ func TestInsertWorkspaceResource(t *testing.T) { } t.Run("NoAgents", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() job := uuid.New() err := insert(db, job, &sdkproto.Resource{ Name: "something", @@ -1538,7 +1538,7 @@ func TestInsertWorkspaceResource(t *testing.T) { }) t.Run("InvalidAgentToken", func(t *testing.T) { t.Parallel() - err := insert(dbfake.New(), uuid.New(), &sdkproto.Resource{ + err := insert(dbmem.New(), uuid.New(), &sdkproto.Resource{ Name: "something", Type: "aws_instance", Agents: []*sdkproto.Agent{{ @@ -1551,7 +1551,7 @@ func TestInsertWorkspaceResource(t *testing.T) { }) t.Run("DuplicateApps", func(t *testing.T) { t.Parallel() - err := insert(dbfake.New(), uuid.New(), &sdkproto.Resource{ + err := insert(dbmem.New(), uuid.New(), &sdkproto.Resource{ Name: "something", Type: "aws_instance", Agents: []*sdkproto.Agent{{ @@ -1566,7 +1566,7 @@ func TestInsertWorkspaceResource(t *testing.T) { }) t.Run("Success", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() job := uuid.New() err := insert(db, job, &sdkproto.Resource{ Name: "something", @@ -1623,7 +1623,7 @@ func TestInsertWorkspaceResource(t *testing.T) { t.Run("AllDisplayApps", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() job := uuid.New() err := insert(db, job, &sdkproto.Resource{ Name: "something", @@ -1651,7 +1651,7 @@ func TestInsertWorkspaceResource(t *testing.T) { t.Run("DisableDefaultApps", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() job := uuid.New() err := insert(db, job, &sdkproto.Resource{ Name: "something", @@ -1689,7 +1689,7 @@ func setup(t *testing.T, ignoreLogErrors bool, ov *overrides) (proto.DRPCProvisi ctx, cancel := context.WithCancel(context.Background()) t.Cleanup(cancel) logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug) - db := dbfake.New() + db := dbmem.New() ps := pubsub.NewInMemory() deploymentValues := &codersdk.DeploymentValues{} var externalAuthConfigs []*externalauth.Config diff --git a/coderd/telemetry/telemetry_test.go b/coderd/telemetry/telemetry_test.go index cec216564b..5df6be77f7 100644 --- a/coderd/telemetry/telemetry_test.go +++ b/coderd/telemetry/telemetry_test.go @@ -18,8 +18,8 @@ import ( "cdr.dev/slog/sloggers/slogtest" "github.com/coder/coder/v2/buildinfo" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbfake" "github.com/coder/coder/v2/coderd/database/dbgen" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/coderd/database/dbtime" "github.com/coder/coder/v2/coderd/telemetry" "github.com/coder/coder/v2/testutil" @@ -36,7 +36,7 @@ func TestTelemetry(t *testing.T) { var err error - db := dbfake.New() + db := dbmem.New() ctx := testutil.Context(t, testutil.WaitMedium) _, _ = dbgen.APIKey(t, db, database.APIKey{}) @@ -106,7 +106,7 @@ func TestTelemetry(t *testing.T) { }) t.Run("HashedEmail", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() _ = dbgen.User(t, db, database.User{ Email: "kyle@coder.com", }) @@ -119,7 +119,7 @@ func TestTelemetry(t *testing.T) { // nolint:paralleltest func TestTelemetryInstallSource(t *testing.T) { t.Setenv("CODER_TELEMETRY_INSTALL_SOURCE", "aws_marketplace") - db := dbfake.New() + db := dbmem.New() deployment, _ := collectSnapshot(t, db) require.Equal(t, "aws_marketplace", deployment.InstallSource) } diff --git a/coderd/updatecheck/updatecheck_test.go b/coderd/updatecheck/updatecheck_test.go index 103064eb7e..afc0f57cbd 100644 --- a/coderd/updatecheck/updatecheck_test.go +++ b/coderd/updatecheck/updatecheck_test.go @@ -14,7 +14,7 @@ import ( "cdr.dev/slog/sloggers/slogtest" - "github.com/coder/coder/v2/coderd/database/dbfake" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/coderd/updatecheck" "github.com/coder/coder/v2/testutil" ) @@ -49,7 +49,7 @@ func TestChecker_Notify(t *testing.T) { })) defer srv.Close() - db := dbfake.New() + db := dbmem.New() logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Named(t.Name()) notify := make(chan updatecheck.Result, len(wantVersion)) c := updatecheck.New(db, logger, updatecheck.Options{ @@ -131,7 +131,7 @@ func TestChecker_Latest(t *testing.T) { })) defer srv.Close() - db := dbfake.New() + db := dbmem.New() logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Named(t.Name()) c := updatecheck.New(db, logger, updatecheck.Options{ URL: srv.URL, diff --git a/enterprise/audit/audit_test.go b/enterprise/audit/audit_test.go index b4f5e0f2aa..6d825306c3 100644 --- a/enterprise/audit/audit_test.go +++ b/enterprise/audit/audit_test.go @@ -8,7 +8,7 @@ import ( "golang.org/x/xerrors" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbfake" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/enterprise/audit" "github.com/coder/coder/v2/enterprise/audit/audittest" ) @@ -91,7 +91,7 @@ func TestAuditor(t *testing.T) { var ( backend = &testBackend{decision: test.backendDecision, err: test.backendError} exporter = audit.NewAuditor( - dbfake.New(), + dbmem.New(), audit.FilterFunc(func(_ context.Context, _ database.AuditLog) (audit.FilterDecision, error) { return test.filterDecision, test.filterError }), diff --git a/enterprise/audit/backends/postgres_test.go b/enterprise/audit/backends/postgres_test.go index b3fa1f31d0..f566db9cb5 100644 --- a/enterprise/audit/backends/postgres_test.go +++ b/enterprise/audit/backends/postgres_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbfake" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/enterprise/audit" "github.com/coder/coder/v2/enterprise/audit/audittest" "github.com/coder/coder/v2/enterprise/audit/backends" @@ -20,7 +20,7 @@ func TestPostgresBackend(t *testing.T) { var ( ctx, cancel = context.WithCancel(context.Background()) - db = dbfake.New() + db = dbmem.New() pgb = backends.NewPostgres(db, true) alog = audittest.RandomLog() ) diff --git a/enterprise/coderd/coderd_test.go b/enterprise/coderd/coderd_test.go index 873618842b..855ecef059 100644 --- a/enterprise/coderd/coderd_test.go +++ b/enterprise/coderd/coderd_test.go @@ -17,7 +17,7 @@ import ( "github.com/coder/coder/v2/coderd/coderdtest" "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" @@ -191,7 +191,7 @@ func TestAuditLogging(t *testing.T) { _, _, api, _ := coderdenttest.NewWithAPI(t, &coderdenttest.Options{ AuditLogging: true, Options: &coderdtest.Options{ - Auditor: audit.NewAuditor(dbfake.New(), audit.DefaultFilter), + Auditor: audit.NewAuditor(dbmem.New(), audit.DefaultFilter), }, LicenseOptions: &coderdenttest.LicenseOptions{ Features: license.Features{ @@ -200,7 +200,7 @@ func TestAuditLogging(t *testing.T) { }, }) auditor := *api.AGPL.Auditor.Load() - ea := audit.NewAuditor(dbfake.New(), audit.DefaultFilter) + ea := audit.NewAuditor(dbmem.New(), audit.DefaultFilter) t.Logf("%T = %T", auditor, ea) assert.EqualValues(t, reflect.ValueOf(ea).Type(), reflect.ValueOf(auditor).Type()) }) diff --git a/enterprise/coderd/coderdenttest/coderdenttest.go b/enterprise/coderd/coderdenttest/coderdenttest.go index 1c3f7c4fc8..26e3bfaef2 100644 --- a/enterprise/coderd/coderdenttest/coderdenttest.go +++ b/enterprise/coderd/coderdenttest/coderdenttest.go @@ -10,7 +10,7 @@ import ( "testing" "time" - "github.com/coder/coder/v2/coderd/database/dbfake" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/coderd/database/pubsub" "github.com/golang-jwt/jwt/v4" @@ -133,8 +133,8 @@ func NewWithAPI(t *testing.T, options *Options) ( // we check for the in-memory test types so that the real types don't have to exported _, ok := coderAPI.Pubsub.(*pubsub.MemoryPubsub) require.False(t, ok, "FeatureHighAvailability is incompatible with MemoryPubsub") - _, ok = coderAPI.Database.(*dbfake.FakeQuerier) - require.False(t, ok, "FeatureHighAvailability is incompatible with dbfake") + _, ok = coderAPI.Database.(*dbmem.FakeQuerier) + require.False(t, ok, "FeatureHighAvailability is incompatible with dbmem") } } _ = AddLicense(t, client, lo) diff --git a/enterprise/coderd/dormancy/dormantusersjob_test.go b/enterprise/coderd/dormancy/dormantusersjob_test.go index 4c3853cc98..c752e84bc1 100644 --- a/enterprise/coderd/dormancy/dormantusersjob_test.go +++ b/enterprise/coderd/dormancy/dormantusersjob_test.go @@ -11,7 +11,7 @@ import ( "cdr.dev/slog/sloggers/slogtest" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbfake" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/enterprise/coderd/dormancy" "github.com/coder/coder/v2/testutil" ) @@ -25,7 +25,7 @@ func TestCheckInactiveUsers(t *testing.T) { // Add some dormant accounts logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}) - db := dbfake.New() + db := dbmem.New() ctx, cancelFunc := context.WithCancel(context.Background()) t.Cleanup(cancelFunc) diff --git a/enterprise/coderd/license/license_test.go b/enterprise/coderd/license/license_test.go index 1335a89aca..f57dd0292d 100644 --- a/enterprise/coderd/license/license_test.go +++ b/enterprise/coderd/license/license_test.go @@ -11,7 +11,7 @@ import ( "cdr.dev/slog" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbfake" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/coderd/database/dbtime" "github.com/coder/coder/v2/codersdk" "github.com/coder/coder/v2/enterprise/coderd/coderdenttest" @@ -29,7 +29,7 @@ func TestEntitlements(t *testing.T) { t.Run("Defaults", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() entitlements, err := license.Entitlements(context.Background(), db, slog.Logger{}, 1, 1, coderdenttest.Keys, all) require.NoError(t, err) require.False(t, entitlements.HasLicense) @@ -41,7 +41,7 @@ func TestEntitlements(t *testing.T) { }) t.Run("Always return the current user count", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() entitlements, err := license.Entitlements(context.Background(), db, slog.Logger{}, 1, 1, coderdenttest.Keys, all) require.NoError(t, err) require.False(t, entitlements.HasLicense) @@ -50,7 +50,7 @@ func TestEntitlements(t *testing.T) { }) t.Run("SingleLicenseNothing", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() db.InsertLicense(context.Background(), database.InsertLicenseParams{ JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{}), Exp: time.Now().Add(time.Hour), @@ -66,7 +66,7 @@ func TestEntitlements(t *testing.T) { }) t.Run("SingleLicenseAll", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() db.InsertLicense(context.Background(), database.InsertLicenseParams{ JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{ Features: func() license.Features { @@ -89,7 +89,7 @@ func TestEntitlements(t *testing.T) { }) t.Run("SingleLicenseGrace", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() db.InsertLicense(context.Background(), database.InsertLicenseParams{ JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{ Features: license.Features{ @@ -115,7 +115,7 @@ func TestEntitlements(t *testing.T) { }) t.Run("Expiration warning", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() db.InsertLicense(context.Background(), database.InsertLicenseParams{ JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{ Features: license.Features{ @@ -144,7 +144,7 @@ func TestEntitlements(t *testing.T) { t.Run("Expiration warning for license expiring in 1 day", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() db.InsertLicense(context.Background(), database.InsertLicenseParams{ JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{ Features: license.Features{ @@ -173,7 +173,7 @@ func TestEntitlements(t *testing.T) { t.Run("Expiration warning for trials", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() db.InsertLicense(context.Background(), database.InsertLicenseParams{ JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{ Features: license.Features{ @@ -203,7 +203,7 @@ func TestEntitlements(t *testing.T) { t.Run("Expiration warning for non trials", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() db.InsertLicense(context.Background(), database.InsertLicenseParams{ JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{ Features: license.Features{ @@ -232,7 +232,7 @@ func TestEntitlements(t *testing.T) { t.Run("SingleLicenseNotEntitled", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() db.InsertLicense(context.Background(), database.InsertLicenseParams{ JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{}), Exp: time.Now().Add(time.Hour), @@ -260,7 +260,7 @@ func TestEntitlements(t *testing.T) { }) t.Run("TooManyUsers", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() activeUser1, err := db.InsertUser(context.Background(), database.InsertUserParams{ ID: uuid.New(), Username: "test1", @@ -306,7 +306,7 @@ func TestEntitlements(t *testing.T) { }) t.Run("MaximizeUserLimit", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() db.InsertUser(context.Background(), database.InsertUserParams{}) db.InsertUser(context.Background(), database.InsertUserParams{}) db.InsertLicense(context.Background(), database.InsertLicenseParams{ @@ -334,7 +334,7 @@ func TestEntitlements(t *testing.T) { }) t.Run("MultipleLicenseEnabled", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() // One trial db.InsertLicense(context.Background(), database.InsertLicenseParams{ Exp: time.Now().Add(time.Hour), @@ -358,7 +358,7 @@ func TestEntitlements(t *testing.T) { t.Run("AllFeatures", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() db.InsertLicense(context.Background(), database.InsertLicenseParams{ Exp: time.Now().Add(time.Hour), JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{ @@ -380,7 +380,7 @@ func TestEntitlements(t *testing.T) { t.Run("AllFeaturesAlwaysEnable", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() db.InsertLicense(context.Background(), database.InsertLicenseParams{ Exp: dbtime.Now().Add(time.Hour), JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{ @@ -403,7 +403,7 @@ func TestEntitlements(t *testing.T) { t.Run("AllFeaturesGrace", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() db.InsertLicense(context.Background(), database.InsertLicenseParams{ Exp: dbtime.Now().Add(time.Hour), JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{ @@ -427,7 +427,7 @@ func TestEntitlements(t *testing.T) { t.Run("MultipleReplicasNoLicense", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() entitlements, err := license.Entitlements(context.Background(), db, slog.Logger{}, 2, 1, coderdenttest.Keys, all) require.NoError(t, err) require.False(t, entitlements.HasLicense) @@ -437,7 +437,7 @@ func TestEntitlements(t *testing.T) { t.Run("MultipleReplicasNotEntitled", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() db.InsertLicense(context.Background(), database.InsertLicenseParams{ Exp: time.Now().Add(time.Hour), JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{ @@ -457,7 +457,7 @@ func TestEntitlements(t *testing.T) { t.Run("MultipleReplicasGrace", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() db.InsertLicense(context.Background(), database.InsertLicenseParams{ JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{ Features: license.Features{ @@ -479,7 +479,7 @@ func TestEntitlements(t *testing.T) { t.Run("MultipleGitAuthNoLicense", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() entitlements, err := license.Entitlements(context.Background(), db, slog.Logger{}, 1, 2, coderdenttest.Keys, all) require.NoError(t, err) require.False(t, entitlements.HasLicense) @@ -489,7 +489,7 @@ func TestEntitlements(t *testing.T) { t.Run("MultipleGitAuthNotEntitled", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() db.InsertLicense(context.Background(), database.InsertLicenseParams{ Exp: time.Now().Add(time.Hour), JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{ @@ -509,7 +509,7 @@ func TestEntitlements(t *testing.T) { t.Run("MultipleGitAuthGrace", func(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() db.InsertLicense(context.Background(), database.InsertLicenseParams{ JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{ GraceAt: time.Now().Add(-time.Hour), diff --git a/enterprise/coderd/proxyhealth/proxyhealth_test.go b/enterprise/coderd/proxyhealth/proxyhealth_test.go index 96502fa1f5..6f20c1e48e 100644 --- a/enterprise/coderd/proxyhealth/proxyhealth_test.go +++ b/enterprise/coderd/proxyhealth/proxyhealth_test.go @@ -12,8 +12,8 @@ import ( "cdr.dev/slog/sloggers/slogtest" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbfake" "github.com/coder/coder/v2/coderd/database/dbgen" + "github.com/coder/coder/v2/coderd/database/dbmem" "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 := dbfake.New() + db := dbmem.New() 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 := dbfake.New() + db := dbmem.New() 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 := dbfake.New() + db := dbmem.New() 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 := dbfake.New() + db := dbmem.New() cli := &http.Client{ Transport: &http.Transport{ diff --git a/enterprise/replicasync/replicasync_test.go b/enterprise/replicasync/replicasync_test.go index 343dd940a5..89ee49bec2 100644 --- a/enterprise/replicasync/replicasync_test.go +++ b/enterprise/replicasync/replicasync_test.go @@ -16,7 +16,7 @@ import ( "cdr.dev/slog/sloggers/slogtest" "github.com/coder/coder/v2/coderd/database" - "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/database/pubsub" @@ -218,7 +218,7 @@ func TestReplica(t *testing.T) { // This doesn't use the database fake because creating // this many PostgreSQL connections takes some // configuration tweaking. - db := dbfake.New() + db := dbmem.New() pubsub := pubsub.NewInMemory() logger := slogtest.Make(t, nil) srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { diff --git a/enterprise/trialer/trialer_test.go b/enterprise/trialer/trialer_test.go index 6a160e1ab5..22a9eeaca3 100644 --- a/enterprise/trialer/trialer_test.go +++ b/enterprise/trialer/trialer_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/coder/coder/v2/coderd/database/dbfake" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/enterprise/coderd/coderdenttest" "github.com/coder/coder/v2/enterprise/trialer" ) @@ -23,7 +23,7 @@ func TestTrialer(t *testing.T) { _, _ = w.Write([]byte(license)) })) defer srv.Close() - db := dbfake.New() + db := dbmem.New() gen := trialer.New(db, srv.URL, coderdenttest.Keys) err := gen(context.Background(), "kyle@coder.com") diff --git a/scripts/dbgen/main.go b/scripts/dbgen/main.go index ac946ff8a5..54b104d04f 100644 --- a/scripts/dbgen/main.go +++ b/scripts/dbgen/main.go @@ -53,11 +53,11 @@ func run() error { } databasePath := filepath.Join(localPath, "..", "..", "..", "coderd", "database") - err = orderAndStubDatabaseFunctions(filepath.Join(databasePath, "dbfake", "dbfake.go"), "q", "FakeQuerier", func(params stubParams) string { + err = orderAndStubDatabaseFunctions(filepath.Join(databasePath, "dbmem", "dbmem.go"), "q", "FakeQuerier", func(params stubParams) string { return `panic("not implemented")` }) if err != nil { - return xerrors.Errorf("stub dbfake: %w", err) + return xerrors.Errorf("stub dbmem: %w", err) } err = orderAndStubDatabaseFunctions(filepath.Join(databasePath, "dbmetrics", "dbmetrics.go"), "m", "metricsStore", func(params stubParams) string { @@ -257,13 +257,13 @@ func orderAndStubDatabaseFunctions(filePath, receiver, structName string, stub f contents, err := os.ReadFile(filePath) if err != nil { - return xerrors.Errorf("read dbfake: %w", err) + return xerrors.Errorf("read dbmem: %w", err) } // Required to preserve imports! f, err := decorator.NewDecoratorWithImports(token.NewFileSet(), packageName, goast.New()).Parse(contents) if err != nil { - return xerrors.Errorf("parse dbfake: %w", err) + return xerrors.Errorf("parse dbmem: %w", err) } pointer := false @@ -298,8 +298,8 @@ func orderAndStubDatabaseFunctions(filePath, receiver, structName string, stub f for _, fn := range funcs { var bodyStmts []dst.Stmt - // Add input validation, only relevant for dbfake. - if strings.Contains(filePath, "dbfake") && len(fn.Func.Params.List) == 2 && fn.Func.Params.List[1].Names[0].Name == "arg" { + // Add input validation, only relevant for dbmem. + if strings.Contains(filePath, "dbmem") && len(fn.Func.Params.List) == 2 && fn.Func.Params.List[1].Names[0].Name == "arg" { /* err := validateDatabaseType(arg) if err != nil { diff --git a/site/site_test.go b/site/site_test.go index bf40be9b1c..b240a065fe 100644 --- a/site/site_test.go +++ b/site/site_test.go @@ -24,8 +24,8 @@ import ( "github.com/coder/coder/v2/coderd/database" "github.com/coder/coder/v2/coderd/database/db2sdk" - "github.com/coder/coder/v2/coderd/database/dbfake" "github.com/coder/coder/v2/coderd/database/dbgen" + "github.com/coder/coder/v2/coderd/database/dbmem" "github.com/coder/coder/v2/coderd/database/dbtime" "github.com/coder/coder/v2/coderd/httpmw" "github.com/coder/coder/v2/codersdk" @@ -42,7 +42,7 @@ func TestInjection(t *testing.T) { }, } binFs := http.FS(fstest.MapFS{}) - db := dbfake.New() + db := dbmem.New() handler := site.New(&site.Options{ BinFS: binFs, Database: db, @@ -74,7 +74,7 @@ func TestInjection(t *testing.T) { func TestInjectionFailureProducesCleanHTML(t *testing.T) { t.Parallel() - db := dbfake.New() + db := dbmem.New() // Create an expired user with a refresh token, but provide no OAuth2 // configuration so that refresh is impossible, this should result in