Skip to content

chore: Rename databasefake --> dbfake #6011

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
Feb 3, 2023
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
6 changes: 3 additions & 3 deletions cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import (
"github.com/coder/coder/coderd"
"github.com/coder/coder/coderd/autobuild/executor"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/database/databasefake"
"github.com/coder/coder/coderd/database/dbfake"
"github.com/coder/coder/coderd/database/migrations"
"github.com/coder/coder/coderd/devtunnel"
"github.com/coder/coder/coderd/gitauth"
Expand Down Expand Up @@ -461,7 +461,7 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
AppHostname: appHostname,
AppHostnameRegex: appHostnameRegex,
Logger: logger.Named("coderd"),
Database: databasefake.New(),
Database: dbfake.New(),
DERPMap: derpMap,
Pubsub: database.NewPubsubInMemory(),
CacheDir: cacheDir,
Expand Down Expand Up @@ -560,7 +560,7 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
}

if cfg.InMemoryDatabase.Value {
options.Database = databasefake.New()
options.Database = dbfake.New()
options.Pubsub = database.NewPubsubInMemory()
} else {
logger.Debug(ctx, "connecting to postgresql")
Expand Down
4 changes: 2 additions & 2 deletions coderd/coderdtest/authorize.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"testing"
"time"

"github.com/coder/coder/coderd/database/databasefake"
"github.com/coder/coder/coderd/database/dbfake"

"github.com/go-chi/chi/v5"
"github.com/stretchr/testify/assert"
Expand All @@ -30,7 +30,7 @@ func AGPLRoutes(a *AuthTester) (map[string]string, map[string]RouteCheck) {
// in memory fake. This is because the in memory fake does not use SQL, and
// still uses rego. So this boolean indicates how to assert the expected
// behavior.
_, isMemoryDB := a.api.Database.(databasefake.FakeDatabase)
_, isMemoryDB := a.api.Database.(dbfake.FakeDatabase)

// Some quick reused objects
workspaceRBACObj := rbac.ResourceWorkspace.WithID(a.Workspace.ID).InOrg(a.Organization.ID).WithOwner(a.Workspace.OwnerID.String())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package databasefake
package dbfake

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package databasefake_test
package dbfake_test

import (
"context"
Expand All @@ -12,14 +12,14 @@ import (

"github.com/coder/coder/coderd/database"

"github.com/coder/coder/coderd/database/databasefake"
"github.com/coder/coder/coderd/database/dbfake"
)

// test that transactions don't deadlock, and that we don't see intermediate state.
func TestInTx(t *testing.T) {
t.Parallel()

uut := databasefake.New()
uut := dbfake.New()

inTx := make(chan any)
queriesDone := make(chan any)
Expand Down Expand Up @@ -77,7 +77,7 @@ func TestExactMethods(t *testing.T) {
"IsFakeDB": "Helper function used for unit testing",
}

fake := reflect.TypeOf(databasefake.New())
fake := reflect.TypeOf(dbfake.New())
fakeMethods := methods(fake)

store := reflect.TypeOf((*database.Store)(nil)).Elem()
Expand Down
40 changes: 20 additions & 20 deletions coderd/database/dbgen/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/database/databasefake"
"github.com/coder/coder/coderd/database/dbfake"
"github.com/coder/coder/coderd/database/dbgen"
)

Expand All @@ -17,64 +17,64 @@ func TestGenerator(t *testing.T) {

t.Run("AuditLog", func(t *testing.T) {
t.Parallel()
db := databasefake.New()
db := dbfake.New()
_ = dbgen.AuditLog(t, db, database.AuditLog{})
logs := must(db.GetAuditLogsOffset(context.Background(), database.GetAuditLogsOffsetParams{Limit: 1}))
require.Len(t, logs, 1)
})

t.Run("APIKey", func(t *testing.T) {
t.Parallel()
db := databasefake.New()
db := dbfake.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 := databasefake.New()
db := dbfake.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 := databasefake.New()
db := dbfake.New()
exp := dbgen.UserLink(t, db, database.UserLink{})
require.Equal(t, exp, must(db.GetUserLinkByLinkedID(context.Background(), exp.LinkedID)))
})

t.Run("WorkspaceResource", func(t *testing.T) {
t.Parallel()
db := databasefake.New()
db := dbfake.New()
exp := dbgen.WorkspaceResource(t, db, database.WorkspaceResource{})
require.Equal(t, exp, must(db.GetWorkspaceResourceByID(context.Background(), exp.ID)))
})

t.Run("WorkspaceResourceMetadatum", func(t *testing.T) {
t.Parallel()
db := databasefake.New()
db := dbfake.New()
exp := dbgen.WorkspaceResourceMetadatums(t, db, database.WorkspaceResourceMetadatum{})
require.Equal(t, exp, must(db.GetWorkspaceResourceMetadataByResourceIDs(context.Background(), []uuid.UUID{exp[0].WorkspaceResourceID})))
})

t.Run("Job", func(t *testing.T) {
t.Parallel()
db := databasefake.New()
db := dbfake.New()
exp := dbgen.ProvisionerJob(t, db, database.ProvisionerJob{})
require.Equal(t, exp, must(db.GetProvisionerJobByID(context.Background(), exp.ID)))
})

t.Run("Group", func(t *testing.T) {
t.Parallel()
db := databasefake.New()
db := dbfake.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 := databasefake.New()
db := dbfake.New()
g := dbgen.Group(t, db, database.Group{})
u := dbgen.User(t, db, database.User{})
exp := []database.User{u}
Expand All @@ -85,14 +85,14 @@ func TestGenerator(t *testing.T) {

t.Run("Organization", func(t *testing.T) {
t.Parallel()
db := databasefake.New()
db := dbfake.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 := databasefake.New()
db := dbfake.New()
exp := dbgen.OrganizationMember(t, db, database.OrganizationMember{})
require.Equal(t, exp, must(db.GetOrganizationMemberByUserID(context.Background(), database.GetOrganizationMemberByUserIDParams{
OrganizationID: exp.OrganizationID,
Expand All @@ -102,42 +102,42 @@ func TestGenerator(t *testing.T) {

t.Run("Workspace", func(t *testing.T) {
t.Parallel()
db := databasefake.New()
db := dbfake.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 := databasefake.New()
db := dbfake.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 := databasefake.New()
db := dbfake.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 := databasefake.New()
db := dbfake.New()
exp := dbgen.TemplateVersion(t, db, database.TemplateVersion{})
require.Equal(t, exp, must(db.GetTemplateVersionByID(context.Background(), exp.ID)))
})

t.Run("ParameterSchema", func(t *testing.T) {
t.Parallel()
db := databasefake.New()
db := dbfake.New()
exp := dbgen.ParameterSchema(t, db, database.ParameterSchema{})
require.Equal(t, []database.ParameterSchema{exp}, must(db.GetParameterSchemasByJobID(context.Background(), exp.JobID)))
})

t.Run("ParameterValue", func(t *testing.T) {
t.Parallel()
db := databasefake.New()
db := dbfake.New()
exp := dbgen.ParameterValue(t, db, database.ParameterValue{})
require.Equal(t, exp, must(db.GetParameterValueByScopeAndName(context.Background(), database.GetParameterValueByScopeAndNameParams{
Scope: exp.Scope,
Expand All @@ -148,14 +148,14 @@ func TestGenerator(t *testing.T) {

t.Run("WorkspaceBuild", func(t *testing.T) {
t.Parallel()
db := databasefake.New()
db := dbfake.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 := databasefake.New()
db := dbfake.New()
exp := dbgen.User(t, db, database.User{})
require.Equal(t, exp, must(db.GetUserByID(context.Background(), exp.ID)))
})
Expand Down
4 changes: 2 additions & 2 deletions coderd/database/dbtestutil/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
"github.com/stretchr/testify/require"

"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/database/databasefake"
"github.com/coder/coder/coderd/database/dbfake"
"github.com/coder/coder/coderd/database/postgres"
)

func NewDB(t *testing.T) (database.Store, database.Pubsub) {
t.Helper()

db := databasefake.New()
db := dbfake.New()
pubsub := database.NewPubsubInMemory()
if os.Getenv("DB") != "" {
connectionURL := os.Getenv("CODER_PG_CONNECTION_URL")
Expand Down
Loading