()
| 3282 | } |
| 3283 | |
| 3284 | func (s *MethodTestSuite) TestWorkspace() { |
| 3285 | // The Workspace object differs it's type based on whether it's dormant or |
| 3286 | // not, which is why we have two tests for it. To ensure we are actually |
| 3287 | // testing the correct RBAC objects, we also explicitly create the expected |
| 3288 | // object here rather than passing in the model. |
| 3289 | s.Run("GetWorkspaceByID", s.Mocked(func(dbm *dbmock.MockStore, faker *gofakeit.Faker, check *expects) { |
| 3290 | ws := testutil.Fake(s.T(), faker, database.Workspace{}) |
| 3291 | ws.DormantAt = sql.NullTime{ |
| 3292 | Time: time.Time{}, |
| 3293 | Valid: false, |
| 3294 | } |
| 3295 | // Ensure the RBAC is not the dormant type. |
| 3296 | require.Equal(s.T(), rbac.ResourceWorkspace.Type, ws.RBACObject().Type) |
| 3297 | dbm.EXPECT().GetWorkspaceByID(gomock.Any(), ws.ID).Return(ws, nil).AnyTimes() |
| 3298 | // Explicitly create the expected object. |
| 3299 | expected := rbac.ResourceWorkspace.WithID(ws.ID). |
| 3300 | InOrg(ws.OrganizationID). |
| 3301 | WithOwner(ws.OwnerID.String()). |
| 3302 | WithGroupACL(ws.GroupACL.RBACACL()). |
| 3303 | WithACLUserList(ws.UserACL.RBACACL()) |
| 3304 | check.Args(ws.ID).Asserts(expected, policy.ActionRead).Returns(ws) |
| 3305 | })) |
| 3306 | s.Run("DormantWorkspace/GetWorkspaceByID", s.Mocked(func(dbm *dbmock.MockStore, faker *gofakeit.Faker, check *expects) { |
| 3307 | ws := testutil.Fake(s.T(), faker, database.Workspace{ |
| 3308 | DormantAt: sql.NullTime{ |
| 3309 | Time: time.Now().Add(-time.Hour), |
| 3310 | Valid: true, |
| 3311 | }, |
| 3312 | }) |
| 3313 | // Ensure the RBAC changed automatically. |
| 3314 | require.Equal(s.T(), rbac.ResourceWorkspaceDormant.Type, ws.RBACObject().Type) |
| 3315 | dbm.EXPECT().GetWorkspaceByID(gomock.Any(), ws.ID).Return(ws, nil).AnyTimes() |
| 3316 | // Explicitly create the expected object. |
| 3317 | expected := rbac.ResourceWorkspaceDormant. |
| 3318 | WithID(ws.ID). |
| 3319 | InOrg(ws.OrganizationID). |
| 3320 | WithOwner(ws.OwnerID.String()) |
| 3321 | check.Args(ws.ID).Asserts(expected, policy.ActionRead).Returns(ws) |
| 3322 | })) |
| 3323 | s.Run("GetWorkspaceByResourceID", s.Mocked(func(dbm *dbmock.MockStore, faker *gofakeit.Faker, check *expects) { |
| 3324 | ws := testutil.Fake(s.T(), faker, database.Workspace{}) |
| 3325 | res := testutil.Fake(s.T(), faker, database.WorkspaceResource{}) |
| 3326 | dbm.EXPECT().GetWorkspaceByResourceID(gomock.Any(), res.ID).Return(ws, nil).AnyTimes() |
| 3327 | check.Args(res.ID).Asserts(ws, policy.ActionRead).Returns(ws) |
| 3328 | })) |
| 3329 | s.Run("GetWorkspaces", s.Mocked(func(dbm *dbmock.MockStore, _ *gofakeit.Faker, check *expects) { |
| 3330 | arg := database.GetWorkspacesParams{} |
| 3331 | dbm.EXPECT().GetAuthorizedWorkspaces(gomock.Any(), arg, gomock.Any()).Return([]database.GetWorkspacesRow{}, nil).AnyTimes() |
| 3332 | // No asserts here because SQLFilter. |
| 3333 | check.Args(arg).Asserts() |
| 3334 | })) |
| 3335 | s.Run("GetWorkspaceAgentsForMetrics", s.Mocked(func(dbm *dbmock.MockStore, faker *gofakeit.Faker, check *expects) { |
| 3336 | row := testutil.Fake(s.T(), faker, database.GetWorkspaceAgentsForMetricsRow{}) |
| 3337 | dbm.EXPECT().GetWorkspaceAgentsForMetrics(gomock.Any()).Return([]database.GetWorkspaceAgentsForMetricsRow{row}, nil).AnyTimes() |
| 3338 | check.Args().Asserts(rbac.ResourceWorkspace, policy.ActionRead).Returns([]database.GetWorkspaceAgentsForMetricsRow{row}) |
| 3339 | })) |
| 3340 | s.Run("GetWorkspacesForWorkspaceMetrics", s.Mocked(func(dbm *dbmock.MockStore, _ *gofakeit.Faker, check *expects) { |
| 3341 | dbm.EXPECT().GetWorkspacesForWorkspaceMetrics(gomock.Any()).Return([]database.GetWorkspacesForWorkspaceMetricsRow{}, nil).AnyTimes() |
nothing calls this directly
no test coverage detected