@@ -26,8 +26,6 @@ import (
26
26
"github.com/coder/coder/v2/provisioner/echo"
27
27
"github.com/coder/coder/v2/provisionersdk/proto"
28
28
"github.com/coder/coder/v2/testutil"
29
-
30
- enterpriseSchedule "github.com/coder/coder/v2/enterprise/coderd/schedule"
31
29
)
32
30
33
31
func TestExecutorAutostartOK (t * testing.T ) {
@@ -1075,41 +1073,46 @@ func TestNotifications(t *testing.T) {
1075
1073
var (
1076
1074
ticker = make (chan time.Time )
1077
1075
statCh = make (chan autobuild.Stats )
1078
- logger = slogtest .Make (t , & slogtest.Options {})
1079
1076
notificationsEnqueuer = testutil.FakeNotificationsEnqueuer {}
1077
+ timeTilDormant = time .Minute
1080
1078
client = coderdtest .New (t , & coderdtest.Options {
1081
1079
AutobuildTicker : ticker ,
1082
1080
AutobuildStats : statCh ,
1083
1081
IncludeProvisionerDaemon : true ,
1084
1082
NotificationsEnqueuer : & notificationsEnqueuer ,
1085
- TemplateScheduleStore : enterpriseSchedule .NewEnterpriseTemplateScheduleStore (userQuietHoursScheduleStore (), & notificationsEnqueuer , logger ),
1083
+ TemplateScheduleStore : schedule.MockTemplateScheduleStore {
1084
+ GetFn : func (_ context.Context , _ database.Store , _ uuid.UUID ) (schedule.TemplateScheduleOptions , error ) {
1085
+ return schedule.TemplateScheduleOptions {
1086
+ UserAutostartEnabled : false ,
1087
+ UserAutostopEnabled : true ,
1088
+ DefaultTTL : 0 ,
1089
+ AutostopRequirement : schedule.TemplateAutostopRequirement {},
1090
+ TimeTilDormant : timeTilDormant ,
1091
+ }, nil
1092
+ },
1093
+ },
1086
1094
})
1087
- admin = coderdtest .CreateFirstUser (t , client )
1088
- version = coderdtest .CreateTemplateVersion (t , client , admin .OrganizationID , nil )
1089
- timeTilDormant = 1000
1095
+ admin = coderdtest .CreateFirstUser (t , client )
1096
+ version = coderdtest .CreateTemplateVersion (t , client , admin .OrganizationID , nil )
1090
1097
)
1091
1098
1092
1099
coderdtest .AwaitTemplateVersionJobCompleted (t , client , version .ID )
1093
- template := coderdtest .CreateTemplate (t , client , admin .OrganizationID , version .ID , func (ctr * codersdk.CreateTemplateRequest ) {
1094
- ctr .TimeTilDormantMillis = ptr .Ref (int64 (timeTilDormant ))
1095
- })
1100
+ template := coderdtest .CreateTemplate (t , client , admin .OrganizationID , version .ID )
1096
1101
userClient , _ := coderdtest .CreateAnotherUser (t , client , admin .OrganizationID )
1097
1102
workspace := coderdtest .CreateWorkspace (t , userClient , admin .OrganizationID , template .ID )
1098
1103
coderdtest .AwaitWorkspaceBuildJobCompleted (t , userClient , workspace .LatestBuild .ID )
1099
1104
1100
1105
// Stop workspace
1101
1106
workspace = coderdtest .MustTransitionWorkspace (t , client , workspace .ID , database .WorkspaceTransitionStart , database .WorkspaceTransitionStop )
1102
- build : = coderdtest .AwaitWorkspaceBuildJobCompleted (t , userClient , workspace .LatestBuild .ID )
1107
+ _ = coderdtest .AwaitWorkspaceBuildJobCompleted (t , userClient , workspace .LatestBuild .ID )
1103
1108
1104
1109
// Wait for workspace to become dormant
1105
- ticker <- build . Job . CompletedAt . Add (time . Millisecond * time . Duration ( timeTilDormant ) * 2 )
1110
+ ticker <- workspace . LastUsedAt . Add (timeTilDormant * 3 )
1106
1111
<- statCh
1107
1112
1108
1113
// Check that the workspace is dormant
1109
1114
workspace = coderdtest .MustWorkspace (t , client , workspace .ID )
1110
1115
require .NotNil (t , workspace .DormantAt )
1111
-
1112
- // TODO: Write test to check notification.
1113
1116
})
1114
1117
}
1115
1118
0 commit comments