Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix extend test
  • Loading branch information
BrunoQuaresma committed May 6, 2024
commit 2e15829f1608afeb818871e4b03043d947254d22
25 changes: 0 additions & 25 deletions coderd/workspaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2410,31 +2410,6 @@ func TestWorkspaceExtend(t *testing.T) {
require.WithinDuration(t, oldDeadline.Add(-time.Hour), updated.LatestBuild.Deadline.Time, time.Minute)
}

func TestWorkspaceExtendWithoutTemplateAllowingUserAutostop(t *testing.T) {
t.Parallel()
var (
client = coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
user = coderdtest.CreateFirstUser(t, client)
version = coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
tmpl = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID, func(req *codersdk.CreateTemplateRequest) {
v := false
req.AllowUserAutostop = &v
})
workspace = coderdtest.CreateWorkspace(t, client, user.OrganizationID, tmpl.ID)
)

ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()

newDeadline := time.Now().Add(9 * time.Hour).UTC()
req := codersdk.PutExtendWorkspaceRequest{
Deadline: newDeadline,
}
err := client.PutExtendWorkspace(ctx, workspace.ID, req)

require.ErrorContains(t, err, "template does not allow user autostop")
}

func TestWorkspaceUpdateAutomaticUpdates_OK(t *testing.T) {
t.Parallel()

Expand Down
34 changes: 33 additions & 1 deletion enterprise/coderd/workspaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -913,8 +913,12 @@ func TestWorkspaceAutobuild(t *testing.T) {
ws = coderdtest.MustWorkspace(t, client, ws.ID)
require.Equal(t, version2.ID, ws.LatestBuild.TemplateVersionID)
})
}

func TestTemplateDoesNotAllowUserAutostop(t *testing.T) {
t.Parallel()

t.Run("TemplateDoesNotAllowUserAutostop", func(t *testing.T) {
t.Run("TTLSetByTemplate", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, &coderdtest.Options{
IncludeProvisionerDaemon: true,
Expand Down Expand Up @@ -951,6 +955,34 @@ func TestWorkspaceAutobuild(t *testing.T) {
require.Equal(t, templateTTL, template.DefaultTTLMillis)
require.Equal(t, templateTTL, *workspace.TTLMillis)
})

t.Run("ExtendIsNotEnabledByTemplate", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, &coderdtest.Options{
IncludeProvisionerDaemon: true,
TemplateScheduleStore: schedule.NewEnterpriseTemplateScheduleStore(agplUserQuietHoursScheduleStore()),
})
user := coderdtest.CreateFirstUser(t, client)
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID, func(ctr *codersdk.CreateTemplateRequest) {
ctr.AllowUserAutostop = ptr.Ref(false)
})
coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
workspace := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID)
coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID)

require.Equal(t, false, template.AllowUserAutostop, "template should have AllowUserAutostop as false")

ctx := testutil.Context(t, testutil.WaitShort)
ttl := 8 * time.Hour
newDeadline := time.Now().Add(ttl + time.Hour).UTC()

err := client.PutExtendWorkspace(ctx, workspace.ID, codersdk.PutExtendWorkspaceRequest{
Deadline: newDeadline,
})

require.ErrorContains(t, err, "template does not allow user autostop")
})
}

// Blocked by autostart requirements
Expand Down