(t *testing.T)
| 11308 | } |
| 11309 | |
| 11310 | func TestGetWorkspaceBuildMetricsByResourceID(t *testing.T) { |
| 11311 | t.Parallel() |
| 11312 | |
| 11313 | t.Run("OK", func(t *testing.T) { |
| 11314 | t.Parallel() |
| 11315 | |
| 11316 | db, _ := dbtestutil.NewDB(t) |
| 11317 | ctx := context.Background() |
| 11318 | |
| 11319 | org := dbgen.Organization(t, db, database.Organization{}) |
| 11320 | user := dbgen.User(t, db, database.User{}) |
| 11321 | tmpl := dbgen.Template(t, db, database.Template{ |
| 11322 | OrganizationID: org.ID, |
| 11323 | CreatedBy: user.ID, |
| 11324 | }) |
| 11325 | tv := dbgen.TemplateVersion(t, db, database.TemplateVersion{ |
| 11326 | OrganizationID: org.ID, |
| 11327 | TemplateID: uuid.NullUUID{UUID: tmpl.ID, Valid: true}, |
| 11328 | CreatedBy: user.ID, |
| 11329 | }) |
| 11330 | ws := dbgen.Workspace(t, db, database.WorkspaceTable{ |
| 11331 | OrganizationID: org.ID, |
| 11332 | TemplateID: tmpl.ID, |
| 11333 | OwnerID: user.ID, |
| 11334 | AutomaticUpdates: database.AutomaticUpdatesNever, |
| 11335 | }) |
| 11336 | job := dbgen.ProvisionerJob(t, db, nil, database.ProvisionerJob{ |
| 11337 | OrganizationID: org.ID, |
| 11338 | Type: database.ProvisionerJobTypeWorkspaceBuild, |
| 11339 | }) |
| 11340 | _ = dbgen.WorkspaceBuild(t, db, database.WorkspaceBuild{ |
| 11341 | WorkspaceID: ws.ID, |
| 11342 | TemplateVersionID: tv.ID, |
| 11343 | JobID: job.ID, |
| 11344 | InitiatorID: user.ID, |
| 11345 | }) |
| 11346 | resource := dbgen.WorkspaceResource(t, db, database.WorkspaceResource{ |
| 11347 | JobID: job.ID, |
| 11348 | }) |
| 11349 | |
| 11350 | parentReadyAt := dbtime.Now() |
| 11351 | parentStartedAt := parentReadyAt.Add(-time.Second) |
| 11352 | _ = dbgen.WorkspaceAgent(t, db, database.WorkspaceAgent{ |
| 11353 | ResourceID: resource.ID, |
| 11354 | StartedAt: sql.NullTime{Time: parentStartedAt, Valid: true}, |
| 11355 | ReadyAt: sql.NullTime{Time: parentReadyAt, Valid: true}, |
| 11356 | LifecycleState: database.WorkspaceAgentLifecycleStateReady, |
| 11357 | }) |
| 11358 | |
| 11359 | row, err := db.GetWorkspaceBuildMetricsByResourceID(ctx, resource.ID) |
| 11360 | require.NoError(t, err) |
| 11361 | require.True(t, row.AllAgentsReady) |
| 11362 | require.True(t, parentReadyAt.Equal(row.LastAgentReadyAt)) |
| 11363 | require.Equal(t, "success", row.WorstStatus) |
| 11364 | }) |
| 11365 | |
| 11366 | t.Run("SubAgentExcluded", func(t *testing.T) { |
| 11367 | t.Parallel() |
nothing calls this directly
no test coverage detected