(t *testing.T)
| 7237 | } |
| 7238 | |
| 7239 | func TestWorkspaceAgentNameUniqueTrigger(t *testing.T) { |
| 7240 | t.Parallel() |
| 7241 | |
| 7242 | createWorkspaceWithAgent := func(t *testing.T, db database.Store, org database.Organization, agentName string) (database.WorkspaceBuild, database.WorkspaceResource, database.WorkspaceAgent) { |
| 7243 | t.Helper() |
| 7244 | |
| 7245 | user := dbgen.User(t, db, database.User{}) |
| 7246 | template := dbgen.Template(t, db, database.Template{ |
| 7247 | OrganizationID: org.ID, |
| 7248 | CreatedBy: user.ID, |
| 7249 | }) |
| 7250 | templateVersion := dbgen.TemplateVersion(t, db, database.TemplateVersion{ |
| 7251 | TemplateID: uuid.NullUUID{Valid: true, UUID: template.ID}, |
| 7252 | OrganizationID: org.ID, |
| 7253 | CreatedBy: user.ID, |
| 7254 | }) |
| 7255 | workspace := dbgen.Workspace(t, db, database.WorkspaceTable{ |
| 7256 | OrganizationID: org.ID, |
| 7257 | TemplateID: template.ID, |
| 7258 | OwnerID: user.ID, |
| 7259 | }) |
| 7260 | job := dbgen.ProvisionerJob(t, db, nil, database.ProvisionerJob{ |
| 7261 | Type: database.ProvisionerJobTypeWorkspaceBuild, |
| 7262 | OrganizationID: org.ID, |
| 7263 | }) |
| 7264 | build := dbgen.WorkspaceBuild(t, db, database.WorkspaceBuild{ |
| 7265 | BuildNumber: 1, |
| 7266 | JobID: job.ID, |
| 7267 | WorkspaceID: workspace.ID, |
| 7268 | TemplateVersionID: templateVersion.ID, |
| 7269 | }) |
| 7270 | resource := dbgen.WorkspaceResource(t, db, database.WorkspaceResource{ |
| 7271 | JobID: build.JobID, |
| 7272 | }) |
| 7273 | agent := dbgen.WorkspaceAgent(t, db, database.WorkspaceAgent{ |
| 7274 | ResourceID: resource.ID, |
| 7275 | Name: agentName, |
| 7276 | }) |
| 7277 | |
| 7278 | return build, resource, agent |
| 7279 | } |
| 7280 | |
| 7281 | t.Run("DuplicateNamesInSameWorkspaceResource", func(t *testing.T) { |
| 7282 | t.Parallel() |
| 7283 | |
| 7284 | db, _ := dbtestutil.NewDB(t) |
| 7285 | org := dbgen.Organization(t, db, database.Organization{}) |
| 7286 | ctx := testutil.Context(t, testutil.WaitShort) |
| 7287 | |
| 7288 | // Given: A workspace with an agent |
| 7289 | _, resource, _ := createWorkspaceWithAgent(t, db, org, "duplicate-agent") |
| 7290 | |
| 7291 | // When: Another agent is created for that workspace with the same name. |
| 7292 | _, err := db.InsertWorkspaceAgent(ctx, database.InsertWorkspaceAgentParams{ |
| 7293 | ID: uuid.New(), |
| 7294 | CreatedAt: time.Now(), |
| 7295 | UpdatedAt: time.Now(), |
| 7296 | Name: "duplicate-agent", // Same name as agent1 |
nothing calls this directly
no test coverage detected