(t *testing.T)
| 30 | ) |
| 31 | |
| 32 | func TestSubAgentAPI(t *testing.T) { |
| 33 | t.Parallel() |
| 34 | |
| 35 | newDatabaseWithOrg := func(t *testing.T) (database.Store, database.Organization) { |
| 36 | db, _ := dbtestutil.NewDB(t) |
| 37 | org := dbgen.Organization(t, db, database.Organization{}) |
| 38 | return db, org |
| 39 | } |
| 40 | |
| 41 | newUserWithWorkspaceAgent := func(t *testing.T, db database.Store, org database.Organization) (database.User, database.WorkspaceAgent) { |
| 42 | user := dbgen.User(t, db, database.User{}) |
| 43 | template := dbgen.Template(t, db, database.Template{ |
| 44 | OrganizationID: org.ID, |
| 45 | CreatedBy: user.ID, |
| 46 | }) |
| 47 | templateVersion := dbgen.TemplateVersion(t, db, database.TemplateVersion{ |
| 48 | TemplateID: uuid.NullUUID{Valid: true, UUID: template.ID}, |
| 49 | OrganizationID: org.ID, |
| 50 | CreatedBy: user.ID, |
| 51 | }) |
| 52 | workspace := dbgen.Workspace(t, db, database.WorkspaceTable{ |
| 53 | OrganizationID: org.ID, |
| 54 | TemplateID: template.ID, |
| 55 | OwnerID: user.ID, |
| 56 | }) |
| 57 | job := dbgen.ProvisionerJob(t, db, nil, database.ProvisionerJob{ |
| 58 | Type: database.ProvisionerJobTypeWorkspaceBuild, |
| 59 | OrganizationID: org.ID, |
| 60 | }) |
| 61 | build := dbgen.WorkspaceBuild(t, db, database.WorkspaceBuild{ |
| 62 | JobID: job.ID, |
| 63 | WorkspaceID: workspace.ID, |
| 64 | TemplateVersionID: templateVersion.ID, |
| 65 | }) |
| 66 | resource := dbgen.WorkspaceResource(t, db, database.WorkspaceResource{ |
| 67 | JobID: build.JobID, |
| 68 | }) |
| 69 | agent := dbgen.WorkspaceAgent(t, db, database.WorkspaceAgent{ |
| 70 | ResourceID: resource.ID, |
| 71 | }) |
| 72 | |
| 73 | return user, agent |
| 74 | } |
| 75 | |
| 76 | newAgentAPI := func(t *testing.T, logger slog.Logger, db database.Store, clock quartz.Clock, user database.User, org database.Organization, agent database.WorkspaceAgent) *agentapi.SubAgentAPI { |
| 77 | auth := rbac.NewStrictCachingAuthorizer(prometheus.NewRegistry()) |
| 78 | |
| 79 | accessControlStore := &atomic.Pointer[dbauthz.AccessControlStore]{} |
| 80 | var acs dbauthz.AccessControlStore = dbauthz.AGPLTemplateAccessControlStore{} |
| 81 | accessControlStore.Store(&acs) |
| 82 | |
| 83 | return &agentapi.SubAgentAPI{ |
| 84 | OwnerID: user.ID, |
| 85 | OrganizationID: org.ID, |
| 86 | AgentFn: func(ctx context.Context) (database.WorkspaceAgent, error) { return agent, nil }, |
| 87 | Clock: clock, |
| 88 | Database: dbauthz.New(db, auth, logger, accessControlStore), |
| 89 | } |
nothing calls this directly
no test coverage detected