@@ -122,40 +122,44 @@ func CreateInitialUser(t *testing.T, client *codersdk.Client) coderd.CreateIniti
122
122
return req
123
123
}
124
124
125
- // CreateProject creates a project with the "echo" provisioner for
126
- // compatibility with testing. The name assigned is randomly generated.
127
- func CreateProject (t * testing.T , client * codersdk.Client , organization string ) coderd.Project {
128
- project , err := client .CreateProject (context .Background (), organization , coderd.CreateProjectRequest {
129
- Name : randomUsername (),
130
- Provisioner : database .ProvisionerTypeEcho ,
125
+ // CreateProjectImportProvisionerJob creates a project import provisioner job
126
+ // with the responses provided. It uses the "echo" provisioner for compatibility
127
+ // with testing.
128
+ func CreateProjectImportProvisionerJob (t * testing.T , client * codersdk.Client , organization string , res * echo.Responses ) coderd.ProvisionerJob {
129
+ data , err := echo .Tar (res )
130
+ require .NoError (t , err )
131
+ file , err := client .UploadFile (context .Background (), codersdk .ContentTypeTar , data )
132
+ require .NoError (t , err )
133
+ job , err := client .CreateProjectVersionImportProvisionerJob (context .Background (), organization , coderd.CreateProjectImportJobRequest {
134
+ StorageSource : file .Hash ,
135
+ StorageMethod : database .ProvisionerStorageMethodFile ,
136
+ Provisioner : database .ProvisionerTypeEcho ,
131
137
})
132
138
require .NoError (t , err )
133
- return project
139
+ return job
134
140
}
135
141
136
- // CreateProjectVersion creates a project version for the "echo" provisioner
137
- // for compatibility with testing.
138
- func CreateProjectVersion (t * testing.T , client * codersdk.Client , organization , project string , responses * echo.Responses ) coderd.ProjectVersion {
139
- data , err := echo .Tar (responses )
140
- require .NoError (t , err )
141
- version , err := client .CreateProjectVersion (context .Background (), organization , project , coderd.CreateProjectVersionRequest {
142
- StorageMethod : database .ProjectStorageMethodInlineArchive ,
143
- StorageSource : data ,
142
+ // CreateProject creates a project with the "echo" provisioner for
143
+ // compatibility with testing. The name assigned is randomly generated.
144
+ func CreateProject (t * testing.T , client * codersdk.Client , organization string , job uuid.UUID ) coderd.Project {
145
+ project , err := client .CreateProject (context .Background (), organization , coderd.CreateProjectRequest {
146
+ Name : randomUsername (),
147
+ VersionImportJobID : job ,
144
148
})
145
149
require .NoError (t , err )
146
- return version
150
+ return project
147
151
}
148
152
149
- // AwaitProjectVersionImported awaits for the project import job to reach completed status.
150
- func AwaitProjectVersionImported (t * testing.T , client * codersdk.Client , organization , project , version string ) coderd.ProjectVersion {
151
- var projectVersion coderd.ProjectVersion
153
+ // AwaitProvisionerJob awaits for a job to reach completed status.
154
+ func AwaitProvisionerJob (t * testing.T , client * codersdk.Client , organization string , job uuid. UUID ) coderd.ProvisionerJob {
155
+ var provisionerJob coderd.ProvisionerJob
152
156
require .Eventually (t , func () bool {
153
157
var err error
154
- projectVersion , err = client .ProjectVersion (context .Background (), organization , project , version )
158
+ provisionerJob , err = client .ProvisionerJob (context .Background (), organization , job )
155
159
require .NoError (t , err )
156
- return projectVersion . Import .Status .Completed ()
160
+ return provisionerJob .Status .Completed ()
157
161
}, 3 * time .Second , 25 * time .Millisecond )
158
- return projectVersion
162
+ return provisionerJob
159
163
}
160
164
161
165
// CreateWorkspace creates a workspace for the user and project provided.
@@ -169,18 +173,6 @@ func CreateWorkspace(t *testing.T, client *codersdk.Client, user string, project
169
173
return workspace
170
174
}
171
175
172
- // AwaitWorkspaceHistoryProvisioned awaits for the workspace provision job to reach completed status.
173
- func AwaitWorkspaceHistoryProvisioned (t * testing.T , client * codersdk.Client , user , workspace , history string ) coderd.WorkspaceHistory {
174
- var workspaceHistory coderd.WorkspaceHistory
175
- require .Eventually (t , func () bool {
176
- var err error
177
- workspaceHistory , err = client .WorkspaceHistory (context .Background (), user , workspace , history )
178
- require .NoError (t , err )
179
- return workspaceHistory .Provision .Status .Completed ()
180
- }, 3 * time .Second , 25 * time .Millisecond )
181
- return workspaceHistory
182
- }
183
-
184
176
func randomUsername () string {
185
177
return strings .ReplaceAll (namesgenerator .GetRandomName (0 ), "_" , "-" )
186
178
}
0 commit comments