( t *testing.T, maxPortShareLevel database.AppSharingLevel, appCount int, )
| 265 | } |
| 266 | |
| 267 | func newMockSubAgentAPIWithMaxPortShareLevel( |
| 268 | t *testing.T, |
| 269 | maxPortShareLevel database.AppSharingLevel, |
| 270 | appCount int, |
| 271 | ) (context.Context, *agentapi.SubAgentAPI, *[]database.UpsertWorkspaceAppParams) { |
| 272 | t.Helper() |
| 273 | |
| 274 | ctx := testutil.Context(t, testutil.WaitShort) |
| 275 | log := testutil.Logger(t) |
| 276 | clock := quartz.NewMock(t) |
| 277 | ownerID := uuid.New() |
| 278 | organizationID := uuid.New() |
| 279 | templateID := uuid.New() |
| 280 | parentAgent := database.WorkspaceAgent{ |
| 281 | ID: uuid.New(), |
| 282 | ResourceID: uuid.New(), |
| 283 | } |
| 284 | workspace := database.Workspace{ |
| 285 | ID: uuid.New(), |
| 286 | OwnerID: ownerID, |
| 287 | OrganizationID: organizationID, |
| 288 | TemplateID: templateID, |
| 289 | } |
| 290 | template := database.Template{ |
| 291 | ID: templateID, |
| 292 | MaxPortSharingLevel: maxPortShareLevel, |
| 293 | } |
| 294 | upsertedApps := []database.UpsertWorkspaceAppParams{} |
| 295 | |
| 296 | db := dbmock.NewMockStore(gomock.NewController(t)) |
| 297 | db.EXPECT().GetWorkspaceByAgentID(gomock.Any(), parentAgent.ID).Return(workspace, nil) |
| 298 | db.EXPECT().GetTemplateByID(gomock.Any(), templateID).Return(template, nil) |
| 299 | db.EXPECT().InsertWorkspaceAgent(gomock.Any(), gomock.Any()).DoAndReturn( |
| 300 | func(_ context.Context, params database.InsertWorkspaceAgentParams) (database.WorkspaceAgent, error) { |
| 301 | require.True(t, params.ParentID.Valid) |
| 302 | require.Equal(t, parentAgent.ID, params.ParentID.UUID) |
| 303 | |
| 304 | return database.WorkspaceAgent{ |
| 305 | ID: params.ID, |
| 306 | Name: params.Name, |
| 307 | AuthToken: params.AuthToken, |
| 308 | }, nil |
| 309 | }, |
| 310 | ) |
| 311 | db.EXPECT().UpsertWorkspaceApp(gomock.Any(), gomock.Any()).DoAndReturn( |
| 312 | func(_ context.Context, params database.UpsertWorkspaceAppParams) (database.WorkspaceApp, error) { |
| 313 | upsertedApps = append(upsertedApps, params) |
| 314 | return database.WorkspaceApp{ |
| 315 | ID: params.ID, |
| 316 | AgentID: params.AgentID, |
| 317 | Slug: params.Slug, |
| 318 | SharingLevel: params.SharingLevel, |
| 319 | }, nil |
| 320 | }, |
| 321 | ).Times(appCount) |
| 322 | |
| 323 | portSharer := &atomic.Pointer[agplportsharing.PortSharer]{} |
| 324 | var ps agplportsharing.PortSharer = entportsharing.NewEnterprisePortSharer() |
no test coverage detected