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:
Kyle Carberry
2023-11-02 17:15:07 +00:00
committed by GitHub
parent ac9c16864c
commit 839a16e299
5 changed files with 413 additions and 530 deletions
+7 -1
View File
@@ -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
}