@@ -19,7 +19,6 @@ import (
19
19
"github.com/coder/coder/v2/coderd/database"
20
20
"github.com/coder/coder/v2/coderd/database/dbfake"
21
21
"github.com/coder/coder/v2/codersdk"
22
- "github.com/coder/coder/v2/provisioner/echo"
23
22
"github.com/coder/coder/v2/provisionersdk/proto"
24
23
"github.com/coder/coder/v2/pty/ptytest"
25
24
)
@@ -30,20 +29,12 @@ func TestWorkspaceAgent(t *testing.T) {
30
29
t .Run ("LogDirectory" , func (t * testing.T ) {
31
30
t .Parallel ()
32
31
33
- authToken := uuid .NewString ()
34
- client := coderdtest .New (t , & coderdtest.Options {
35
- IncludeProvisionerDaemon : true ,
36
- })
32
+ client , db := coderdtest .NewWithDatabase (t , nil )
37
33
user := coderdtest .CreateFirstUser (t , client )
38
- version := coderdtest . CreateTemplateVersion (t , client , user . OrganizationID , & echo. Responses {
39
- Parse : echo . ParseComplete ,
40
- ProvisionApply : echo . ProvisionApplyWithAgent ( authToken ) ,
34
+ ws , authToken := dbfake . CreateWorkspaceWithAgent (t , db , database. Workspace {
35
+ OrganizationID : user . OrganizationID ,
36
+ OwnerID : user . UserID ,
41
37
})
42
- template := coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
43
- coderdtest .AwaitTemplateVersionJobCompleted (t , client , version .ID )
44
- workspace := coderdtest .CreateWorkspace (t , client , user .OrganizationID , template .ID )
45
- coderdtest .AwaitWorkspaceBuildJobCompleted (t , client , workspace .LatestBuild .ID )
46
-
47
38
logDir := t .TempDir ()
48
39
inv , _ := clitest .New (t ,
49
40
"agent" ,
@@ -59,7 +50,7 @@ func TestWorkspaceAgent(t *testing.T) {
59
50
ctx := inv .Context ()
60
51
pty .ExpectMatchContext (ctx , "agent is starting now" )
61
52
62
- coderdtest .AwaitWorkspaceAgents (t , client , workspace .ID )
53
+ coderdtest .AwaitWorkspaceAgents (t , client , ws .ID )
63
54
64
55
info , err := os .Stat (filepath .Join (logDir , "coder-agent.log" ))
65
56
require .NoError (t , err )
@@ -154,35 +145,24 @@ func TestWorkspaceAgent(t *testing.T) {
154
145
t .Parallel ()
155
146
instanceID := "instanceidentifier"
156
147
validator , metadataClient := coderdtest .NewGoogleInstanceIdentity (t , instanceID , false )
157
- client := coderdtest .New (t , & coderdtest.Options {
158
- GoogleTokenValidator : validator ,
159
- IncludeProvisionerDaemon : true ,
148
+ client , db := coderdtest .NewWithDatabase (t , & coderdtest.Options {
149
+ GoogleTokenValidator : validator ,
160
150
})
161
151
owner := coderdtest .CreateFirstUser (t , client )
162
- member , _ := coderdtest .CreateAnotherUser (t , client , owner .OrganizationID )
163
- version := coderdtest .CreateTemplateVersion (t , client , owner .OrganizationID , & echo.Responses {
164
- Parse : echo .ParseComplete ,
165
- ProvisionApply : []* proto.Response {{
166
- Type : & proto.Response_Apply {
167
- Apply : & proto.ApplyComplete {
168
- Resources : []* proto.Resource {{
169
- Name : "somename" ,
170
- Type : "someinstance" ,
171
- Agents : []* proto.Agent {{
172
- Auth : & proto.Agent_InstanceId {
173
- InstanceId : instanceID ,
174
- },
175
- }},
176
- }},
177
- },
152
+ member , memberUser := coderdtest .CreateAnotherUser (t , client , owner .OrganizationID )
153
+ ws := dbfake .CreateWorkspace (t , db , database.Workspace {
154
+ OrganizationID : owner .OrganizationID ,
155
+ OwnerID : memberUser .ID ,
156
+ })
157
+ dbfake .CreateWorkspaceBuild (t , db , ws , database.WorkspaceBuild {}, & proto.Resource {
158
+ Name : "somename" ,
159
+ Type : "someinstance" ,
160
+ Agents : []* proto.Agent {{
161
+ Auth : & proto.Agent_InstanceId {
162
+ InstanceId : instanceID ,
178
163
},
179
164
}},
180
165
})
181
- template := coderdtest .CreateTemplate (t , client , owner .OrganizationID , version .ID )
182
- coderdtest .AwaitTemplateVersionJobCompleted (t , client , version .ID )
183
- workspace := coderdtest .CreateWorkspace (t , member , owner .OrganizationID , template .ID )
184
- coderdtest .AwaitWorkspaceBuildJobCompleted (t , client , workspace .LatestBuild .ID )
185
-
186
166
inv , cfg := clitest .New (t , "agent" , "--auth" , "google-instance-identity" , "--agent-url" , client .URL .String ())
187
167
ptytest .New (t ).Attach (inv )
188
168
clitest .SetupConfig (t , member , cfg )
@@ -194,9 +174,8 @@ func TestWorkspaceAgent(t *testing.T) {
194
174
)
195
175
196
176
ctx := inv .Context ()
197
-
198
- coderdtest .AwaitWorkspaceAgents (t , client , workspace .ID )
199
- workspace , err := client .Workspace (ctx , workspace .ID )
177
+ coderdtest .AwaitWorkspaceAgents (t , client , ws .ID )
178
+ workspace , err := client .Workspace (ctx , ws .ID )
200
179
require .NoError (t , err )
201
180
resources := workspace .LatestBuild .Resources
202
181
if assert .NotEmpty (t , resources ) && assert .NotEmpty (t , resources [0 ].Agents ) {
@@ -226,19 +205,12 @@ func TestWorkspaceAgent(t *testing.T) {
226
205
t .Run ("PostStartup" , func (t * testing.T ) {
227
206
t .Parallel ()
228
207
229
- authToken := uuid .NewString ()
230
- client := coderdtest .New (t , & coderdtest.Options {
231
- IncludeProvisionerDaemon : true ,
232
- })
208
+ client , db := coderdtest .NewWithDatabase (t , nil )
233
209
user := coderdtest .CreateFirstUser (t , client )
234
- version := coderdtest . CreateTemplateVersion (t , client , user . OrganizationID , & echo. Responses {
235
- Parse : echo . ParseComplete ,
236
- ProvisionApply : echo . ProvisionApplyWithAgent ( authToken ) ,
210
+ ws , authToken := dbfake . CreateWorkspaceWithAgent (t , db , database. Workspace {
211
+ OrganizationID : user . OrganizationID ,
212
+ OwnerID : user . UserID ,
237
213
})
238
- template := coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
239
- coderdtest .AwaitTemplateVersionJobCompleted (t , client , version .ID )
240
- workspace := coderdtest .CreateWorkspace (t , client , user .OrganizationID , template .ID )
241
- coderdtest .AwaitWorkspaceBuildJobCompleted (t , client , workspace .LatestBuild .ID )
242
214
243
215
logDir := t .TempDir ()
244
216
inv , _ := clitest .New (t ,
@@ -256,7 +228,7 @@ func TestWorkspaceAgent(t *testing.T) {
256
228
clitest .Start (t , inv )
257
229
pty .ExpectMatchContext (inv .Context (), "agent is starting now" )
258
230
259
- resources := coderdtest .AwaitWorkspaceAgents (t , client , workspace .ID )
231
+ resources := coderdtest .AwaitWorkspaceAgents (t , client , ws .ID )
260
232
require .Len (t , resources , 1 )
261
233
require .Len (t , resources [0 ].Agents , 1 )
262
234
require .Len (t , resources [0 ].Agents [0 ].Subsystems , 2 )
0 commit comments