mirror of
https://github.com/coder/coder.git
synced 2025-07-08 11:39:50 +00:00
chore: rename dbfake to dbmem (#10432)
This commit is contained in:
@ -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,
|
||||
|
Reference in New Issue
Block a user