Skip to content

Commit f83877b

Browse files
committed
fix a test
1 parent 6d119f8 commit f83877b

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

coderd/database/modelmethods.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,8 @@ func ConvertWorkspaceRows(rows []GetWorkspacesRow) []Workspace {
354354
AutostartSchedule: r.AutostartSchedule,
355355
Ttl: r.Ttl,
356356
LastUsedAt: r.LastUsedAt,
357+
LockedAt: r.LockedAt,
358+
DeletingAt: r.DeletingAt,
357359
}
358360
}
359361

coderd/database/modelqueries.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ func (q *sqlQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg GetWorkspa
236236
&i.Ttl,
237237
&i.LastUsedAt,
238238
&i.LockedAt,
239+
&i.DeletingAt,
239240
&i.Count,
240241
); err != nil {
241242
return nil, err

coderd/workspaces.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ func (api *API) workspaces(rw http.ResponseWriter, r *http.Request) {
185185
if v.DeletingAt == nil {
186186
continue
187187
}
188+
fmt.Println("WELL WE GOT ONE!")
188189
// get the beginning of the day on which deletion is scheduled
189190
truncatedDeletionAt := time.Date(v.DeletingAt.Year(), v.DeletingAt.Month(), v.DeletingAt.Day(), 0, 0, 0, 0, v.DeletingAt.Location())
190191
if truncatedDeletionAt.After(*postFilter.DeletingBy) {

enterprise/coderd/workspaces_test.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"testing"
88
"time"
99

10-
"github.com/stretchr/testify/assert"
1110
"github.com/stretchr/testify/require"
1211

1312
"cdr.dev/slog/sloggers/slogtest"
@@ -618,53 +617,53 @@ func TestWorkspaceAutobuild(t *testing.T) {
618617
func TestWorkspacesFiltering(t *testing.T) {
619618
t.Parallel()
620619

621-
t.Run("FilterQueryHasDeletingByAndLicensed", func(t *testing.T) {
620+
t.Run("DeletingBy", func(t *testing.T) {
622621
t.Parallel()
623622

624-
inactivityTTL := 1 * 24 * time.Hour
623+
lockedTTL := 24 * time.Hour
625624

626625
client := coderdenttest.New(t, &coderdenttest.Options{
627626
Options: &coderdtest.Options{
628627
IncludeProvisionerDaemon: true,
629628
},
630629
})
631630
user := coderdtest.CreateFirstUser(t, client)
632-
_ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
633-
Features: license.Features{
634-
codersdk.FeatureAdvancedTemplateScheduling: 1,
635-
},
636-
})
631+
_ = coderdenttest.AddFullLicense(t, client)
637632

638633
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
634+
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
639635
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
640636

641-
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
642-
643637
// update template with inactivity ttl
644638
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
645639
defer cancel()
646640

647641
template, err := client.UpdateTemplateMeta(ctx, template.ID, codersdk.UpdateTemplateMeta{
648-
InactivityTTLMillis: inactivityTTL.Milliseconds(),
642+
LockedTTLMillis: lockedTTL.Milliseconds(),
649643
})
650-
651-
assert.NoError(t, err)
652-
assert.Equal(t, inactivityTTL.Milliseconds(), template.InactivityTTLMillis)
644+
require.NoError(t, err)
645+
require.Equal(t, lockedTTL.Milliseconds(), template.LockedTTLMillis)
653646

654647
workspace := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID)
655-
coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID)
648+
_ = coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID)
656649

657650
// stop build so workspace is inactive
658651
stopBuild := coderdtest.CreateWorkspaceBuild(t, client, workspace, database.WorkspaceTransitionStop)
659652
coderdtest.AwaitWorkspaceBuildJob(t, client, stopBuild.ID)
653+
err = client.UpdateWorkspaceLock(ctx, workspace.ID, codersdk.UpdateWorkspaceLock{
654+
Lock: true,
655+
})
656+
require.NoError(t, err)
657+
workspace = coderdtest.MustWorkspace(t, client, workspace.ID)
658+
require.NotNil(t, workspace.DeletingAt)
660659

661660
res, err := client.Workspaces(ctx, codersdk.WorkspaceFilter{
662661
// adding a second to time.Now() to give some buffer in case test runs quickly
663-
FilterQuery: fmt.Sprintf("deleting_by:%s", time.Now().Add(time.Second).Add(inactivityTTL).Format("2006-01-02")),
662+
FilterQuery: fmt.Sprintf("deleting_by:%s", time.Now().Add(time.Second).Add(lockedTTL).Format("2006-01-02")),
664663
})
665-
assert.NoError(t, err)
666-
assert.Len(t, res.Workspaces, 1)
667-
assert.Equal(t, workspace.ID, res.Workspaces[0].ID)
664+
require.NoError(t, err)
665+
require.Len(t, res.Workspaces, 1)
666+
require.Equal(t, workspace.ID, res.Workspaces[0].ID)
668667
})
669668
}
670669

0 commit comments

Comments
 (0)