@@ -186,8 +186,6 @@ func TestWorkspaceBuildByName(t *testing.T) {
186
186
}
187
187
188
188
func TestWorkspaceUpdateAutostart (t * testing.T ) {
189
- // fri -> monday
190
- // TODO(cian): mon -> tue
191
189
// TODO(cian): CST -> CDT
192
190
// TODO(cian): CDT -> CST
193
191
@@ -200,13 +198,35 @@ func TestWorkspaceUpdateAutostart(t *testing.T) {
200
198
at time.Time
201
199
expectedNext time.Time
202
200
}{
201
+ {
202
+ name : "disable autostart" ,
203
+ schedule : "" ,
204
+ expectedError : "" ,
205
+ },
203
206
{
204
207
name : "friday to monday" ,
205
208
schedule : "CRON_TZ=Europe/Dublin 30 9 1-5" ,
206
209
expectedError : "" ,
207
210
at : time .Date (2022 , 5 , 6 , 9 , 31 , 0 , 0 , dublinLoc ),
208
211
expectedNext : time .Date (2022 , 5 , 9 , 9 , 30 , 0 , 0 , dublinLoc ),
209
212
},
213
+ {
214
+ name : "monday to tuesday" ,
215
+ schedule : "CRON_TZ=Europe/Dublin 30 9 1-5" ,
216
+ expectedError : "" ,
217
+ at : time .Date (2022 , 5 , 9 , 9 , 31 , 0 , 0 , dublinLoc ),
218
+ expectedNext : time .Date (2022 , 5 , 10 , 9 , 30 , 0 , 0 , dublinLoc ),
219
+ },
220
+ {
221
+ name : "invalid location" ,
222
+ schedule : "CRON_TZ=Imaginary/Place 30 9 1-5" ,
223
+ expectedError : "status code 500: invalid autostart schedule: parse schedule: provided bad location Imaginary/Place: unknown time zone Imaginary/Place" ,
224
+ },
225
+ {
226
+ name : "invalid schedule" ,
227
+ schedule : "asdf asdf asdf " ,
228
+ expectedError : `status code 500: invalid autostart schedule: parse schedule: failed to parse int from asdf: strconv.Atoi: parsing "asdf": invalid syntax` ,
229
+ },
210
230
}
211
231
212
232
for _ , testCase := range testCases {
@@ -229,13 +249,22 @@ func TestWorkspaceUpdateAutostart(t *testing.T) {
229
249
err := client .UpdateWorkspaceAutostart (ctx , workspace .ID , codersdk.UpdateWorkspaceAutostartRequest {
230
250
Schedule : testCase .schedule ,
231
251
})
252
+
253
+ if testCase .expectedError != "" {
254
+ require .EqualError (t , err , testCase .expectedError , "unexpected error when setting workspace autostart schedule" )
255
+ return
256
+ }
257
+
232
258
require .NoError (t , err , "expected no error setting workspace autostart schedule" )
233
259
234
260
updated , err := client .Workspace (ctx , workspace .ID )
235
261
require .NoError (t , err , "fetch updated workspace" )
236
262
237
263
require .Equal (t , testCase .schedule , updated .AutostartSchedule , "expected autostart schedule to equal requested" )
238
264
265
+ if testCase .schedule == "" {
266
+ return
267
+ }
239
268
sched , err := schedule .Weekly (updated .AutostartSchedule )
240
269
require .NoError (t , err , "parse returned schedule" )
241
270
0 commit comments