(t *testing.T)
| 3669 | } |
| 3670 | |
| 3671 | func TestWorkspacesFiltering(t *testing.T) { |
| 3672 | t.Parallel() |
| 3673 | |
| 3674 | t.Run("Dormant", func(t *testing.T) { |
| 3675 | t.Parallel() |
| 3676 | |
| 3677 | logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Leveled(slog.LevelDebug) |
| 3678 | client, db, owner := coderdenttest.NewWithDatabase(t, &coderdenttest.Options{ |
| 3679 | Options: &coderdtest.Options{ |
| 3680 | TemplateScheduleStore: schedule.NewEnterpriseTemplateScheduleStore(agplUserQuietHoursScheduleStore(), notifications.NewNoopEnqueuer(), logger, nil), |
| 3681 | }, |
| 3682 | LicenseOptions: &coderdenttest.LicenseOptions{ |
| 3683 | Features: license.Features{codersdk.FeatureAdvancedTemplateScheduling: 1}, |
| 3684 | }, |
| 3685 | }) |
| 3686 | templateAdminClient, templateAdmin := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.RoleTemplateAdmin()) |
| 3687 | |
| 3688 | resp := dbfake.TemplateVersion(t, db).Seed(database.TemplateVersion{ |
| 3689 | OrganizationID: owner.OrganizationID, |
| 3690 | CreatedBy: owner.UserID, |
| 3691 | }).Do() |
| 3692 | |
| 3693 | dormantWS1 := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{ |
| 3694 | OwnerID: templateAdmin.ID, |
| 3695 | OrganizationID: owner.OrganizationID, |
| 3696 | }).Do().Workspace |
| 3697 | |
| 3698 | dormantWS2 := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{ |
| 3699 | OwnerID: templateAdmin.ID, |
| 3700 | OrganizationID: owner.OrganizationID, |
| 3701 | TemplateID: resp.Template.ID, |
| 3702 | }).Do().Workspace |
| 3703 | |
| 3704 | _ = dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{ |
| 3705 | OwnerID: templateAdmin.ID, |
| 3706 | OrganizationID: owner.OrganizationID, |
| 3707 | TemplateID: resp.Template.ID, |
| 3708 | }).Do().Workspace |
| 3709 | |
| 3710 | ctx := testutil.Context(t, testutil.WaitMedium) |
| 3711 | |
| 3712 | err := templateAdminClient.UpdateWorkspaceDormancy(ctx, dormantWS1.ID, codersdk.UpdateWorkspaceDormancy{Dormant: true}) |
| 3713 | require.NoError(t, err) |
| 3714 | |
| 3715 | err = templateAdminClient.UpdateWorkspaceDormancy(ctx, dormantWS2.ID, codersdk.UpdateWorkspaceDormancy{Dormant: true}) |
| 3716 | require.NoError(t, err) |
| 3717 | |
| 3718 | workspaces, err := templateAdminClient.Workspaces(ctx, codersdk.WorkspaceFilter{ |
| 3719 | FilterQuery: "dormant:true", |
| 3720 | }) |
| 3721 | require.NoError(t, err) |
| 3722 | require.Len(t, workspaces.Workspaces, 2) |
| 3723 | |
| 3724 | for _, ws := range workspaces.Workspaces { |
| 3725 | if ws.ID != dormantWS1.ID && ws.ID != dormantWS2.ID { |
| 3726 | t.Fatalf("Unexpected workspace %+v", ws) |
| 3727 | } |
| 3728 | } |
nothing calls this directly
no test coverage detected