Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 66e80cf

Browse files
chore: changes from feedback
1 parent d1cb4d0 commit 66e80cf

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

coderd/schedule/template_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ func TestTemplateTTL(t *testing.T) {
3636
toTTL: 36 * time.Hour,
3737
expected: sql.NullInt64{Valid: true, Int64: int64(36 * time.Hour)},
3838
},
39+
{
40+
name: "ModifyTTLDurationSame",
41+
fromTTL: 24 * time.Hour,
42+
toTTL: 24 * time.Hour,
43+
expected: sql.NullInt64{Valid: true, Int64: int64(24 * time.Hour)},
44+
},
3945
{
4046
name: "DisableTTL",
4147
fromTTL: 24 * time.Hour,

enterprise/coderd/schedule/template.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,7 @@ func (s *EnterpriseTemplateScheduleStore) Set(ctx context.Context, db database.S
198198
// Update all workspace's TTL using this template if either of the following:
199199
// - The template's AllowUserAutostop has just been disabled
200200
// - The template's TTL has been modified and AllowUserAutostop is disabled
201-
if (!opts.UserAutostopEnabled && opts.UserAutostopEnabled != tpl.AllowUserAutostop) ||
202-
(!template.AllowUserAutostop && int64(opts.DefaultTTL) != tpl.DefaultTTL) {
201+
if !opts.UserAutostopEnabled && (tpl.AllowUserAutostop || int64(opts.DefaultTTL) != tpl.DefaultTTL) {
203202
var ttl sql.NullInt64
204203
if opts.DefaultTTL != 0 {
205204
ttl = sql.NullInt64{Valid: true, Int64: int64(opts.DefaultTTL)}

enterprise/coderd/schedule/template_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,13 @@ func TestTemplateTTL(t *testing.T) {
733733
toTTL: 36 * time.Hour,
734734
expected: sql.NullInt64{Valid: true, Int64: int64(36 * time.Hour)},
735735
},
736+
{
737+
name: "AllowUserAutostopFalse/ModifyTTLDurationSame",
738+
allowUserAutostop: false,
739+
fromTTL: 24 * time.Hour,
740+
toTTL: 24 * time.Hour,
741+
expected: sql.NullInt64{Valid: true, Int64: int64(24 * time.Hour)},
742+
},
736743
{
737744
name: "AllowUserAutostopFalse/DisableTTL",
738745
allowUserAutostop: false,
@@ -754,6 +761,13 @@ func TestTemplateTTL(t *testing.T) {
754761
toTTL: 36 * time.Hour,
755762
expected: sql.NullInt64{Valid: true, Int64: int64(24 * time.Hour)},
756763
},
764+
{
765+
name: "AllowUserAutostopTrue/ModifyTTLDurationSame",
766+
allowUserAutostop: true,
767+
fromTTL: 24 * time.Hour,
768+
toTTL: 24 * time.Hour,
769+
expected: sql.NullInt64{Valid: true, Int64: int64(24 * time.Hour)},
770+
},
757771
{
758772
name: "AllowUserAutostopTrue/DisableTTL",
759773
allowUserAutostop: true,
@@ -929,15 +943,15 @@ func TestTemplateTTL(t *testing.T) {
929943

930944
// Disable AllowUserAutostop
931945
template, err = templateScheduleStore.Set(ctx, db, template, agplschedule.TemplateScheduleOptions{
932-
DefaultTTL: 24 * time.Hour,
946+
DefaultTTL: 23 * time.Hour,
933947
UserAutostopEnabled: false,
934948
})
935949
require.NoError(t, err)
936950

937951
// Ensure the workspace ends with the correct TTLs
938952
ws, err := db.GetWorkspaceByID(ctx, workspace.ID)
939953
require.NoError(t, err)
940-
require.Equal(t, sql.NullInt64{Valid: true, Int64: int64(24 * time.Hour)}, ws.Ttl)
954+
require.Equal(t, sql.NullInt64{Valid: true, Int64: int64(23 * time.Hour)}, ws.Ttl)
941955
})
942956
}
943957

0 commit comments

Comments
 (0)