mirror of
https://github.com/coder/coder.git
synced 2025-07-08 11:39:50 +00:00
adds support for workspace presets to the coderd database. Support in the API and web frontend will be added in subsequent pull requests. This is the smallest meaningful contribution that I could get passing tests for.
* Add workspace preset tables to the database in a migration * Add queries to manipulate workspace presets to the database * Generate db related code for the newly added queries * Implement new methods to satisfy the Querier interface in dbauthz, dbmem, dbmock and querymetrics * Implement the required tests for dbauthz * Update the audit table to track changes to the new column in workspace builds
This commit is contained in:
@ -859,6 +859,40 @@ func (s *MethodTestSuite) TestOrganization() {
|
||||
rbac.ResourceAssignOrgRole.InOrg(o.ID), policy.ActionAssign,
|
||||
rbac.ResourceOrganizationMember.InOrg(o.ID).WithID(u.ID), policy.ActionCreate)
|
||||
}))
|
||||
s.Run("InsertPreset", s.Subtest(func(db database.Store, check *expects) {
|
||||
org := dbgen.Organization(s.T(), db, database.Organization{})
|
||||
user := dbgen.User(s.T(), db, database.User{})
|
||||
template := dbgen.Template(s.T(), db, database.Template{
|
||||
CreatedBy: user.ID,
|
||||
OrganizationID: org.ID,
|
||||
})
|
||||
templateVersion := dbgen.TemplateVersion(s.T(), db, database.TemplateVersion{
|
||||
TemplateID: uuid.NullUUID{UUID: template.ID, Valid: true},
|
||||
OrganizationID: org.ID,
|
||||
CreatedBy: user.ID,
|
||||
})
|
||||
workspace := dbgen.Workspace(s.T(), db, database.WorkspaceTable{
|
||||
OrganizationID: org.ID,
|
||||
OwnerID: user.ID,
|
||||
TemplateID: template.ID,
|
||||
})
|
||||
job := dbgen.ProvisionerJob(s.T(), db, nil, database.ProvisionerJob{
|
||||
OrganizationID: org.ID,
|
||||
})
|
||||
workspaceBuild := dbgen.WorkspaceBuild(s.T(), db, database.WorkspaceBuild{
|
||||
WorkspaceID: workspace.ID,
|
||||
TemplateVersionID: templateVersion.ID,
|
||||
InitiatorID: user.ID,
|
||||
JobID: job.ID,
|
||||
})
|
||||
params := database.InsertPresetParams{
|
||||
TemplateVersionID: workspaceBuild.TemplateVersionID,
|
||||
Name: "test",
|
||||
}
|
||||
_, err := db.InsertPreset(context.Background(), params)
|
||||
require.NoError(s.T(), err)
|
||||
check.Args(params).Asserts(rbac.ResourceTemplate, policy.ActionCreate)
|
||||
}))
|
||||
s.Run("DeleteOrganizationMember", s.Subtest(func(db database.Store, check *expects) {
|
||||
o := dbgen.Organization(s.T(), db, database.Organization{})
|
||||
u := dbgen.User(s.T(), db, database.User{})
|
||||
@ -3695,6 +3729,118 @@ func (s *MethodTestSuite) TestSystemFunctions() {
|
||||
ErrorsWithInMemDB(sql.ErrNoRows).
|
||||
Returns([]database.ParameterSchema{})
|
||||
}))
|
||||
s.Run("GetPresetByWorkspaceBuildID", s.Subtest(func(db database.Store, check *expects) {
|
||||
org := dbgen.Organization(s.T(), db, database.Organization{})
|
||||
user := dbgen.User(s.T(), db, database.User{})
|
||||
template := dbgen.Template(s.T(), db, database.Template{
|
||||
CreatedBy: user.ID,
|
||||
OrganizationID: org.ID,
|
||||
})
|
||||
templateVersion := dbgen.TemplateVersion(s.T(), db, database.TemplateVersion{
|
||||
TemplateID: uuid.NullUUID{UUID: template.ID, Valid: true},
|
||||
OrganizationID: org.ID,
|
||||
CreatedBy: user.ID,
|
||||
})
|
||||
workspace := dbgen.Workspace(s.T(), db, database.WorkspaceTable{
|
||||
OrganizationID: org.ID,
|
||||
OwnerID: user.ID,
|
||||
TemplateID: template.ID,
|
||||
})
|
||||
job := dbgen.ProvisionerJob(s.T(), db, nil, database.ProvisionerJob{
|
||||
OrganizationID: org.ID,
|
||||
})
|
||||
workspaceBuild := dbgen.WorkspaceBuild(s.T(), db, database.WorkspaceBuild{
|
||||
WorkspaceID: workspace.ID,
|
||||
TemplateVersionID: templateVersion.ID,
|
||||
InitiatorID: user.ID,
|
||||
JobID: job.ID,
|
||||
})
|
||||
_, err := db.InsertPreset(context.Background(), database.InsertPresetParams{
|
||||
TemplateVersionID: workspaceBuild.TemplateVersionID,
|
||||
Name: "test",
|
||||
})
|
||||
require.NoError(s.T(), err)
|
||||
db.GetPresetByWorkspaceBuildID(context.Background(), workspaceBuild.ID)
|
||||
check.Args(workspaceBuild.ID).Asserts(rbac.ResourceTemplate, policy.ActionRead)
|
||||
}))
|
||||
s.Run("GetPresetParametersByPresetID", s.Subtest(func(db database.Store, check *expects) {
|
||||
org := dbgen.Organization(s.T(), db, database.Organization{})
|
||||
user := dbgen.User(s.T(), db, database.User{})
|
||||
template := dbgen.Template(s.T(), db, database.Template{
|
||||
CreatedBy: user.ID,
|
||||
OrganizationID: org.ID,
|
||||
})
|
||||
templateVersion := dbgen.TemplateVersion(s.T(), db, database.TemplateVersion{
|
||||
TemplateID: uuid.NullUUID{UUID: template.ID, Valid: true},
|
||||
OrganizationID: org.ID,
|
||||
CreatedBy: user.ID,
|
||||
})
|
||||
workspace := dbgen.Workspace(s.T(), db, database.WorkspaceTable{
|
||||
OrganizationID: org.ID,
|
||||
OwnerID: user.ID,
|
||||
TemplateID: template.ID,
|
||||
})
|
||||
job := dbgen.ProvisionerJob(s.T(), db, nil, database.ProvisionerJob{
|
||||
OrganizationID: org.ID,
|
||||
})
|
||||
workspaceBuild := dbgen.WorkspaceBuild(s.T(), db, database.WorkspaceBuild{
|
||||
WorkspaceID: workspace.ID,
|
||||
TemplateVersionID: templateVersion.ID,
|
||||
InitiatorID: user.ID,
|
||||
JobID: job.ID,
|
||||
})
|
||||
_, err := db.InsertPreset(context.Background(), database.InsertPresetParams{
|
||||
TemplateVersionID: workspaceBuild.TemplateVersionID,
|
||||
Name: "test",
|
||||
})
|
||||
require.NoError(s.T(), err)
|
||||
preset, err := db.InsertPreset(context.Background(), database.InsertPresetParams{
|
||||
TemplateVersionID: workspaceBuild.TemplateVersionID,
|
||||
Name: "test",
|
||||
})
|
||||
require.NoError(s.T(), err)
|
||||
db.GetPresetParametersByPresetID(context.Background(), preset.ID)
|
||||
check.Args(preset.ID).Asserts(rbac.ResourceTemplate, policy.ActionRead)
|
||||
}))
|
||||
s.Run("GetPresetsByTemplateVersionID", s.Subtest(func(db database.Store, check *expects) {
|
||||
org := dbgen.Organization(s.T(), db, database.Organization{})
|
||||
user := dbgen.User(s.T(), db, database.User{})
|
||||
template := dbgen.Template(s.T(), db, database.Template{
|
||||
CreatedBy: user.ID,
|
||||
OrganizationID: org.ID,
|
||||
})
|
||||
templateVersion := dbgen.TemplateVersion(s.T(), db, database.TemplateVersion{
|
||||
TemplateID: uuid.NullUUID{UUID: template.ID, Valid: true},
|
||||
OrganizationID: org.ID,
|
||||
CreatedBy: user.ID,
|
||||
})
|
||||
workspace := dbgen.Workspace(s.T(), db, database.WorkspaceTable{
|
||||
OrganizationID: org.ID,
|
||||
OwnerID: user.ID,
|
||||
TemplateID: template.ID,
|
||||
})
|
||||
job := dbgen.ProvisionerJob(s.T(), db, nil, database.ProvisionerJob{
|
||||
OrganizationID: org.ID,
|
||||
})
|
||||
workspaceBuild := dbgen.WorkspaceBuild(s.T(), db, database.WorkspaceBuild{
|
||||
WorkspaceID: workspace.ID,
|
||||
TemplateVersionID: templateVersion.ID,
|
||||
InitiatorID: user.ID,
|
||||
JobID: job.ID,
|
||||
})
|
||||
_, err := db.InsertPreset(context.Background(), database.InsertPresetParams{
|
||||
TemplateVersionID: workspaceBuild.TemplateVersionID,
|
||||
Name: "test",
|
||||
})
|
||||
require.NoError(s.T(), err)
|
||||
_, err = db.InsertPreset(context.Background(), database.InsertPresetParams{
|
||||
TemplateVersionID: workspaceBuild.TemplateVersionID,
|
||||
Name: "test",
|
||||
})
|
||||
require.NoError(s.T(), err)
|
||||
db.GetPresetsByTemplateVersionID(context.Background(), templateVersion.ID)
|
||||
check.Args(templateVersion.ID).Asserts(rbac.ResourceTemplate, policy.ActionRead)
|
||||
}))
|
||||
s.Run("GetWorkspaceAppsByAgentIDs", s.Subtest(func(db database.Store, check *expects) {
|
||||
dbtestutil.DisableForeignKeysAndTriggers(s.T(), db)
|
||||
aWs := dbgen.Workspace(s.T(), db, database.WorkspaceTable{})
|
||||
|
Reference in New Issue
Block a user