@@ -25,10 +25,10 @@ func Test_Executor_Autostart_OK(t *testing.T) {
25
25
LifecycleTicker :tickCh ,
26
26
})
27
27
// Given: we have a user with a workspace
28
- workspace = MustProvisionWorkspace (t ,client )
28
+ workspace = mustProvisionWorkspace (t ,client )
29
29
)
30
30
// Given: workspace is stopped
31
- MustTransitionWorkspace (t ,client ,workspace .ID ,database .WorkspaceTransitionStart ,database .WorkspaceTransitionStop )
31
+ mustTransitionWorkspace (t ,client ,workspace .ID ,database .WorkspaceTransitionStart ,database .WorkspaceTransitionStop )
32
32
33
33
// Given: the workspace initially has autostart disabled
34
34
require .Empty (t ,workspace .AutostartSchedule )
@@ -48,7 +48,7 @@ func Test_Executor_Autostart_OK(t *testing.T) {
48
48
49
49
// Then: the workspace should be started
50
50
require .Eventually (t ,func ()bool {
51
- ws := coderdtest . MustWorkspace (t ,client ,workspace .ID )
51
+ ws := mustWorkspace (t ,client ,workspace .ID )
52
52
return ws .LatestBuild .Job .Status == codersdk .ProvisionerJobSucceeded &&
53
53
ws .LatestBuild .Transition == database .WorkspaceTransitionStart
54
54
},5 * time .Second ,250 * time .Millisecond )
@@ -65,7 +65,7 @@ func Test_Executor_Autostart_AlreadyRunning(t *testing.T) {
65
65
LifecycleTicker :tickCh ,
66
66
})
67
67
// Given: we have a user with a workspace
68
- workspace = MustProvisionWorkspace (t ,client )
68
+ workspace = mustProvisionWorkspace (t ,client )
69
69
)
70
70
71
71
// Given: we ensure the workspace is running
@@ -89,7 +89,7 @@ func Test_Executor_Autostart_AlreadyRunning(t *testing.T) {
89
89
90
90
// Then: the workspace should not be started.
91
91
require .Never (t ,func ()bool {
92
- ws := coderdtest . MustWorkspace (t ,client ,workspace .ID )
92
+ ws := mustWorkspace (t ,client ,workspace .ID )
93
93
return ws .LatestBuild .ID != workspace .LatestBuild .ID && ws .LatestBuild .Transition == database .WorkspaceTransitionStart
94
94
},5 * time .Second ,250 * time .Millisecond )
95
95
}
@@ -103,11 +103,11 @@ func Test_Executor_Autostart_NotEnabled(t *testing.T) {
103
103
LifecycleTicker :tickCh ,
104
104
})
105
105
// Given: we have a user with a workspace
106
- workspace = MustProvisionWorkspace (t ,client )
106
+ workspace = mustProvisionWorkspace (t ,client )
107
107
)
108
108
109
109
// Given: workspace is stopped
110
- MustTransitionWorkspace (t ,client ,workspace .ID ,database .WorkspaceTransitionStart ,database .WorkspaceTransitionStop )
110
+ mustTransitionWorkspace (t ,client ,workspace .ID ,database .WorkspaceTransitionStart ,database .WorkspaceTransitionStop )
111
111
112
112
// Given: the workspace has autostart disabled
113
113
require .Empty (t ,workspace .AutostartSchedule )
@@ -120,7 +120,7 @@ func Test_Executor_Autostart_NotEnabled(t *testing.T) {
120
120
121
121
// Then: the workspace should not be started.
122
122
require .Never (t ,func ()bool {
123
- ws := coderdtest . MustWorkspace (t ,client ,workspace .ID )
123
+ ws := mustWorkspace (t ,client ,workspace .ID )
124
124
return ws .LatestBuild .ID != workspace .LatestBuild .ID && ws .LatestBuild .Transition == database .WorkspaceTransitionStart
125
125
},5 * time .Second ,250 * time .Millisecond )
126
126
}
@@ -136,7 +136,7 @@ func Test_Executor_Autostop_OK(t *testing.T) {
136
136
LifecycleTicker :tickCh ,
137
137
})
138
138
// Given: we have a user with a workspace
139
- workspace = MustProvisionWorkspace (t ,client )
139
+ workspace = mustProvisionWorkspace (t ,client )
140
140
)
141
141
// Given: workspace is running
142
142
require .Equal (t ,database .WorkspaceTransitionStart ,workspace .LatestBuild .Transition )
@@ -159,7 +159,7 @@ func Test_Executor_Autostop_OK(t *testing.T) {
159
159
160
160
// Then: the workspace should be started
161
161
require .Eventually (t ,func ()bool {
162
- ws := coderdtest . MustWorkspace (t ,client ,workspace .ID )
162
+ ws := mustWorkspace (t ,client ,workspace .ID )
163
163
return ws .LatestBuild .ID != workspace .LatestBuild .ID && ws .LatestBuild .Transition == database .WorkspaceTransitionStop
164
164
},5 * time .Second ,250 * time .Millisecond )
165
165
}
@@ -174,11 +174,11 @@ func Test_Executor_Autostop_AlreadyStopped(t *testing.T) {
174
174
LifecycleTicker :tickCh ,
175
175
})
176
176
// Given: we have a user with a workspace
177
- workspace = MustProvisionWorkspace (t ,client )
177
+ workspace = mustProvisionWorkspace (t ,client )
178
178
)
179
179
180
180
// Given: workspace is stopped
181
- MustTransitionWorkspace (t ,client ,workspace .ID ,database .WorkspaceTransitionStart ,database .WorkspaceTransitionStop )
181
+ mustTransitionWorkspace (t ,client ,workspace .ID ,database .WorkspaceTransitionStart ,database .WorkspaceTransitionStop )
182
182
183
183
// Given: the workspace initially has autostart disabled
184
184
require .Empty (t ,workspace .AutostopSchedule )
@@ -198,7 +198,7 @@ func Test_Executor_Autostop_AlreadyStopped(t *testing.T) {
198
198
199
199
// Then: the workspace should not be stopped.
200
200
require .Never (t ,func ()bool {
201
- ws := coderdtest . MustWorkspace (t ,client ,workspace .ID )
201
+ ws := mustWorkspace (t ,client ,workspace .ID )
202
202
return ws .LatestBuild .ID == workspace .LatestBuild .ID && ws .LatestBuild .Transition == database .WorkspaceTransitionStop
203
203
},5 * time .Second ,250 * time .Millisecond )
204
204
}
@@ -212,7 +212,7 @@ func Test_Executor_Autostop_NotEnabled(t *testing.T) {
212
212
LifecycleTicker :tickCh ,
213
213
})
214
214
// Given: we have a user with a workspace
215
- workspace = MustProvisionWorkspace (t ,client )
215
+ workspace = mustProvisionWorkspace (t ,client )
216
216
)
217
217
218
218
// Given: workspace is running
@@ -229,7 +229,7 @@ func Test_Executor_Autostop_NotEnabled(t *testing.T) {
229
229
230
230
// Then: the workspace should not be stopped.
231
231
require .Never (t ,func ()bool {
232
- ws := coderdtest . MustWorkspace (t ,client ,workspace .ID )
232
+ ws := mustWorkspace (t ,client ,workspace .ID )
233
233
return ws .LatestBuild .ID == workspace .LatestBuild .ID && ws .LatestBuild .Transition == database .WorkspaceTransitionStop
234
234
},5 * time .Second ,250 * time .Millisecond )
235
235
}
@@ -245,7 +245,7 @@ func Test_Executor_Workspace_Deleted(t *testing.T) {
245
245
LifecycleTicker :tickCh ,
246
246
})
247
247
// Given: we have a user with a workspace
248
- workspace = MustProvisionWorkspace (t ,client )
248
+ workspace = mustProvisionWorkspace (t ,client )
249
249
)
250
250
251
251
// Given: the workspace initially has autostart disabled
@@ -259,7 +259,7 @@ func Test_Executor_Workspace_Deleted(t *testing.T) {
259
259
}))
260
260
261
261
// Given: workspace is deleted
262
- MustTransitionWorkspace (t ,client ,workspace .ID ,database .WorkspaceTransitionStart ,database .WorkspaceTransitionDelete )
262
+ mustTransitionWorkspace (t ,client ,workspace .ID ,database .WorkspaceTransitionStart ,database .WorkspaceTransitionDelete )
263
263
264
264
// When: the lifecycle executor ticks
265
265
go func () {
@@ -269,12 +269,12 @@ func Test_Executor_Workspace_Deleted(t *testing.T) {
269
269
270
270
// Then: nothing should happen
271
271
require .Never (t ,func ()bool {
272
- ws := coderdtest . MustWorkspace (t ,client ,workspace .ID )
272
+ ws := mustWorkspace (t ,client ,workspace .ID )
273
273
return ws .LatestBuild .Transition != database .WorkspaceTransitionDelete
274
274
},5 * time .Second ,250 * time .Millisecond )
275
275
}
276
276
277
- func MustProvisionWorkspace (t * testing.T ,client * codersdk.Client ) codersdk.Workspace {
277
+ func mustProvisionWorkspace (t * testing.T ,client * codersdk.Client ) codersdk.Workspace {
278
278
t .Helper ()
279
279
coderdtest .NewProvisionerDaemon (t ,client )
280
280
user := coderdtest .CreateFirstUser (t ,client )
@@ -283,10 +283,10 @@ func MustProvisionWorkspace(t *testing.T, client *codersdk.Client) codersdk.Work
283
283
coderdtest .AwaitTemplateVersionJob (t ,client ,version .ID )
284
284
ws := coderdtest .CreateWorkspace (t ,client ,user .OrganizationID ,template .ID )
285
285
coderdtest .AwaitWorkspaceBuildJob (t ,client ,ws .LatestBuild .ID )
286
- return coderdtest . MustWorkspace (t ,client ,ws .ID )
286
+ return mustWorkspace (t ,client ,ws .ID )
287
287
}
288
288
289
- func MustTransitionWorkspace (t * testing.T ,client * codersdk.Client ,workspaceID uuid.UUID ,from ,to database.WorkspaceTransition ) {
289
+ func mustTransitionWorkspace (t * testing.T ,client * codersdk.Client ,workspaceID uuid.UUID ,from ,to database.WorkspaceTransition ) {
290
290
t .Helper ()
291
291
ctx := context .Background ()
292
292
workspace ,err := client .Workspace (ctx ,workspaceID )
@@ -304,6 +304,13 @@ func MustTransitionWorkspace(t *testing.T, client *codersdk.Client, workspaceID
304
304
305
305
_ = coderdtest .AwaitWorkspaceBuildJob (t ,client ,build .ID )
306
306
307
- updated := coderdtest . MustWorkspace (t ,client ,workspace .ID )
307
+ updated := mustWorkspace (t ,client ,workspace .ID )
308
308
require .Equal (t ,to ,updated .LatestBuild .Transition ,"expected workspace to be in state %s but got %s" ,to ,updated .LatestBuild .Transition )
309
309
}
310
+
311
+ func mustWorkspace (t * testing.T ,client * codersdk.Client ,workspaceID uuid.UUID ) codersdk.Workspace {
312
+ ctx := context .Background ()
313
+ ws ,err := client .Workspace (ctx ,workspaceID )
314
+ require .NoError (t ,err ,"no workspace found with id %s" ,workspaceID )
315
+ return ws
316
+ }