mirror of https://github.com/coder/coder.git
chore: rename dbfake to dbmem (#10432)
This commit is contained in:
parent
7a8da08124
commit
5abfe5afd0
|
@ -20,7 +20,7 @@
|
|||
"codersdk",
|
||||
"cronstrue",
|
||||
"databasefake",
|
||||
"dbfake",
|
||||
"dbmem",
|
||||
"dbgen",
|
||||
"dbtype",
|
||||
"DERP",
|
||||
|
|
2
Makefile
2
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
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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)))
|
||||
})
|
||||
|
|
|
@ -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
|
|
@ -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 {
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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{}) {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()},
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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()
|
||||
)
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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{})
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
}),
|
||||
|
|
|
@ -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()
|
||||
)
|
||||
|
|
|
@ -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())
|
||||
})
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue