Skip to content

Commit 6aec9e4

Browse files
committed
fix a test
1 parent 233d93b commit 6aec9e4

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-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
@@ -238,6 +238,7 @@ func (q *sqlQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg GetWorkspa
238238
&i.Ttl,
239239
&i.LastUsedAt,
240240
&i.LockedAt,
241+
&i.DeletingAt,
241242
&i.TemplateName,
242243
&i.TemplateVersionID,
243244
&i.TemplateVersionName,

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: 19 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"
@@ -625,52 +624,53 @@ func TestWorkspaceAutobuild(t *testing.T) {
625624
func TestWorkspacesFiltering(t *testing.T) {
626625
t.Parallel()
627626

628-
t.Run("FilterQueryHasDeletingByAndLicensed", func(t *testing.T) {
627+
t.Run("DeletingBy", func(t *testing.T) {
629628
t.Parallel()
630629

631-
inactivityTTL := 1 * 24 * time.Hour
630+
lockedTTL := 24 * time.Hour
632631

633632
client, user := coderdenttest.New(t, &coderdenttest.Options{
634633
Options: &coderdtest.Options{
635634
IncludeProvisionerDaemon: true,
636635
},
637-
LicenseOptions: &coderdenttest.LicenseOptions{
638-
Features: license.Features{
639-
codersdk.FeatureAdvancedTemplateScheduling: 1,
640-
},
641-
},
642636
})
637+
user := coderdtest.CreateFirstUser(t, client)
638+
_ = coderdenttest.AddFullLicense(t, client)
643639

644640
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
641+
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
645642
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
646643

647-
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
648-
649644
// update template with inactivity ttl
650645
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
651646
defer cancel()
652647

653648
template, err := client.UpdateTemplateMeta(ctx, template.ID, codersdk.UpdateTemplateMeta{
654-
InactivityTTLMillis: inactivityTTL.Milliseconds(),
649+
LockedTTLMillis: lockedTTL.Milliseconds(),
655650
})
656-
657-
assert.NoError(t, err)
658-
assert.Equal(t, inactivityTTL.Milliseconds(), template.InactivityTTLMillis)
651+
require.NoError(t, err)
652+
require.Equal(t, lockedTTL.Milliseconds(), template.LockedTTLMillis)
659653

660654
workspace := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID)
661-
coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID)
655+
_ = coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID)
662656

663657
// stop build so workspace is inactive
664658
stopBuild := coderdtest.CreateWorkspaceBuild(t, client, workspace, database.WorkspaceTransitionStop)
665659
coderdtest.AwaitWorkspaceBuildJob(t, client, stopBuild.ID)
660+
err = client.UpdateWorkspaceLock(ctx, workspace.ID, codersdk.UpdateWorkspaceLock{
661+
Lock: true,
662+
})
663+
require.NoError(t, err)
664+
workspace = coderdtest.MustWorkspace(t, client, workspace.ID)
665+
require.NotNil(t, workspace.DeletingAt)
666666

667667
res, err := client.Workspaces(ctx, codersdk.WorkspaceFilter{
668668
// adding a second to time.Now() to give some buffer in case test runs quickly
669-
FilterQuery: fmt.Sprintf("deleting_by:%s", time.Now().Add(time.Second).Add(inactivityTTL).Format("2006-01-02")),
669+
FilterQuery: fmt.Sprintf("deleting_by:%s", time.Now().Add(time.Second).Add(lockedTTL).Format("2006-01-02")),
670670
})
671-
assert.NoError(t, err)
672-
assert.Len(t, res.Workspaces, 1)
673-
assert.Equal(t, workspace.ID, res.Workspaces[0].ID)
671+
require.NoError(t, err)
672+
require.Len(t, res.Workspaces, 1)
673+
require.Equal(t, workspace.ID, res.Workspaces[0].ID)
674674
})
675675
}
676676

0 commit comments

Comments
 (0)