mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add dbfake for workspace builds and resources (#10426)
* feat: add dbfakedata for workspace builds and resources This creates `coderdtest.NewWithDatabase` and adds a series of helper functions to `dbfake` that insert structured fake data for resources into the database. It allows us to remove provisionerd from a significant amount of tests which should speed them up and reduce flakes. * Rename dbfakedata to dbfake * Migrate workspaceagents_test.go to use the new dbfake * Migrate agent_test.go to use the new fakes * Fix comments
This commit is contained in:
@@ -66,6 +66,12 @@ func AuditLog(t testing.TB, db database.Store, seed database.AuditLog) database.
|
||||
|
||||
func Template(t testing.TB, db database.Store, seed database.Template) database.Template {
|
||||
id := takeFirst(seed.ID, uuid.New())
|
||||
if seed.GroupACL == nil {
|
||||
// By default, all users in the organization can read the template.
|
||||
seed.GroupACL = database.TemplateACL{
|
||||
seed.OrganizationID.String(): []rbac.Action{rbac.ActionRead},
|
||||
}
|
||||
}
|
||||
err := db.InsertTemplate(genCtx, database.InsertTemplateParams{
|
||||
ID: id,
|
||||
CreatedAt: takeFirst(seed.CreatedAt, dbtime.Now()),
|
||||
@@ -84,7 +90,7 @@ func Template(t testing.TB, db database.Store, seed database.Template) database.
|
||||
})
|
||||
require.NoError(t, err, "insert template")
|
||||
|
||||
template, err := db.GetTemplateByID(context.Background(), id)
|
||||
template, err := db.GetTemplateByID(genCtx, id)
|
||||
require.NoError(t, err, "get template")
|
||||
return template
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user