@@ -137,6 +137,8 @@ func (g *Generator) User(ctx context.Context, seed database.User) database.User
137
137
return populate (ctx , g , "" , seed )
138
138
}
139
139
140
+ // Populate uses `require` which calls `t.FailNow()` and must be called from the
141
+ // go routine running the test or benchmark function.
140
142
func (g * Generator ) Populate (ctx context.Context , seed map [string ]interface {}) map [string ]interface {} {
141
143
db := g .db
142
144
t := g .testT
@@ -156,10 +158,10 @@ func (g *Generator) Populate(ctx context.Context, seed map[string]interface{}) m
156
158
HashedSecret : takeFirstBytes (orig .HashedSecret , hashed [:]),
157
159
IPAddress : pqtype.Inet {},
158
160
UserID : takeFirst (orig .UserID , uuid .New ()),
159
- LastUsed : takeFirstTime (orig .LastUsed , time .Now ()),
160
- ExpiresAt : takeFirstTime (orig .ExpiresAt , time .Now ().Add (time .Hour )),
161
- CreatedAt : takeFirstTime (orig .CreatedAt , time .Now ()),
162
- UpdatedAt : takeFirstTime (orig .UpdatedAt , time .Now ()),
161
+ LastUsed : takeFirst (orig .LastUsed , time .Now ()),
162
+ ExpiresAt : takeFirst (orig .ExpiresAt , time .Now ().Add (time .Hour )),
163
+ CreatedAt : takeFirst (orig .CreatedAt , time .Now ()),
164
+ UpdatedAt : takeFirst (orig .UpdatedAt , time .Now ()),
163
165
LoginType : takeFirst (orig .LoginType , database .LoginTypePassword ),
164
166
Scope : takeFirst (orig .Scope , database .APIKeyScopeAll ),
165
167
})
@@ -171,8 +173,8 @@ func (g *Generator) Populate(ctx context.Context, seed map[string]interface{}) m
171
173
case database.Template :
172
174
template , err := db .InsertTemplate (ctx , database.InsertTemplateParams {
173
175
ID : takeFirst (orig .ID , g .Lookup (name )),
174
- CreatedAt : takeFirstTime (orig .CreatedAt , time .Now ()),
175
- UpdatedAt : takeFirstTime (orig .UpdatedAt , time .Now ()),
176
+ CreatedAt : takeFirst (orig .CreatedAt , time .Now ()),
177
+ UpdatedAt : takeFirst (orig .UpdatedAt , time .Now ()),
176
178
OrganizationID : takeFirst (orig .OrganizationID , g .PrimaryOrg (ctx ).ID ),
177
179
Name : takeFirst (orig .Name , namesgenerator .GetRandomName (1 )),
178
180
Provisioner : takeFirst (orig .Provisioner , database .ProvisionerTypeEcho ),
@@ -198,8 +200,8 @@ func (g *Generator) Populate(ctx context.Context, seed map[string]interface{}) m
198
200
Valid : takeFirst (orig .TemplateID .Valid , true ),
199
201
},
200
202
OrganizationID : takeFirst (orig .OrganizationID , g .PrimaryOrg (ctx ).ID ),
201
- CreatedAt : takeFirstTime (orig .CreatedAt , time .Now ()),
202
- UpdatedAt : takeFirstTime (orig .UpdatedAt , time .Now ()),
203
+ CreatedAt : takeFirst (orig .CreatedAt , time .Now ()),
204
+ UpdatedAt : takeFirst (orig .UpdatedAt , time .Now ()),
203
205
Name : takeFirst (orig .Name , namesgenerator .GetRandomName (1 )),
204
206
Readme : takeFirst (orig .Readme , namesgenerator .GetRandomName (1 )),
205
207
JobID : takeFirst (orig .JobID , uuid .New ()),
@@ -212,8 +214,8 @@ func (g *Generator) Populate(ctx context.Context, seed map[string]interface{}) m
212
214
workspace , err := db .InsertWorkspace (ctx , database.InsertWorkspaceParams {
213
215
ID : takeFirst (orig .ID , g .Lookup (name )),
214
216
OwnerID : takeFirst (orig .OwnerID , uuid .New ()),
215
- CreatedAt : takeFirstTime (orig .CreatedAt , time .Now ()),
216
- UpdatedAt : takeFirstTime (orig .UpdatedAt , time .Now ()),
217
+ CreatedAt : takeFirst (orig .CreatedAt , time .Now ()),
218
+ UpdatedAt : takeFirst (orig .UpdatedAt , time .Now ()),
217
219
OrganizationID : takeFirst (orig .OrganizationID , g .PrimaryOrg (ctx ).ID ),
218
220
TemplateID : takeFirst (orig .TemplateID , uuid .New ()),
219
221
Name : takeFirst (orig .Name , namesgenerator .GetRandomName (1 )),
@@ -226,16 +228,16 @@ func (g *Generator) Populate(ctx context.Context, seed map[string]interface{}) m
226
228
case database.WorkspaceBuild :
227
229
build , err := db .InsertWorkspaceBuild (ctx , database.InsertWorkspaceBuildParams {
228
230
ID : takeFirst (orig .ID , g .Lookup (name )),
229
- CreatedAt : takeFirstTime (orig .CreatedAt , time .Now ()),
230
- UpdatedAt : takeFirstTime (orig .UpdatedAt , time .Now ()),
231
+ CreatedAt : takeFirst (orig .CreatedAt , time .Now ()),
232
+ UpdatedAt : takeFirst (orig .UpdatedAt , time .Now ()),
231
233
WorkspaceID : takeFirst (orig .WorkspaceID , uuid .New ()),
232
234
TemplateVersionID : takeFirst (orig .TemplateVersionID , uuid .New ()),
233
235
BuildNumber : takeFirst (orig .BuildNumber , 0 ),
234
236
Transition : takeFirst (orig .Transition , database .WorkspaceTransitionStart ),
235
237
InitiatorID : takeFirst (orig .InitiatorID , uuid .New ()),
236
238
JobID : takeFirst (orig .JobID , uuid .New ()),
237
239
ProvisionerState : takeFirstBytes (orig .ProvisionerState , []byte {}),
238
- Deadline : takeFirstTime (orig .Deadline , time .Now ().Add (time .Hour )),
240
+ Deadline : takeFirst (orig .Deadline , time .Now ().Add (time .Hour )),
239
241
Reason : takeFirst (orig .Reason , database .BuildReasonInitiator ),
240
242
})
241
243
require .NoError (t , err , "insert workspace build" )
@@ -247,8 +249,8 @@ func (g *Generator) Populate(ctx context.Context, seed map[string]interface{}) m
247
249
Email : takeFirst (orig .Email , namesgenerator .GetRandomName (1 )),
248
250
Username : takeFirst (orig .Username , namesgenerator .GetRandomName (1 )),
249
251
HashedPassword : takeFirstBytes (orig .HashedPassword , []byte {}),
250
- CreatedAt : takeFirstTime (orig .CreatedAt , time .Now ()),
251
- UpdatedAt : takeFirstTime (orig .UpdatedAt , time .Now ()),
252
+ CreatedAt : takeFirst (orig .CreatedAt , time .Now ()),
253
+ UpdatedAt : takeFirst (orig .UpdatedAt , time .Now ()),
252
254
RBACRoles : []string {},
253
255
LoginType : takeFirst (orig .LoginType , database .LoginTypePassword ),
254
256
})
@@ -261,8 +263,8 @@ func (g *Generator) Populate(ctx context.Context, seed map[string]interface{}) m
261
263
ID : takeFirst (orig .ID , g .Lookup (name )),
262
264
Name : takeFirst (orig .Name , namesgenerator .GetRandomName (1 )),
263
265
Description : takeFirst (orig .Description , namesgenerator .GetRandomName (1 )),
264
- CreatedAt : takeFirstTime (orig .CreatedAt , time .Now ()),
265
- UpdatedAt : takeFirstTime (orig .UpdatedAt , time .Now ()),
266
+ CreatedAt : takeFirst (orig .CreatedAt , time .Now ()),
267
+ UpdatedAt : takeFirst (orig .UpdatedAt , time .Now ()),
266
268
})
267
269
require .NoError (t , err , "insert organization" )
268
270
@@ -283,8 +285,8 @@ func (g *Generator) Populate(ctx context.Context, seed map[string]interface{}) m
283
285
case database.ProvisionerJob :
284
286
job , err := db .InsertProvisionerJob (ctx , database.InsertProvisionerJobParams {
285
287
ID : takeFirst (orig .ID , g .Lookup (name )),
286
- CreatedAt : takeFirstTime (orig .CreatedAt , time .Now ()),
287
- UpdatedAt : takeFirstTime (orig .UpdatedAt , time .Now ()),
288
+ CreatedAt : takeFirst (orig .CreatedAt , time .Now ()),
289
+ UpdatedAt : takeFirst (orig .UpdatedAt , time .Now ()),
288
290
OrganizationID : takeFirst (orig .OrganizationID , g .PrimaryOrg (ctx ).ID ),
289
291
InitiatorID : takeFirst (orig .InitiatorID , uuid .New ()),
290
292
Provisioner : takeFirst (orig .Provisioner , database .ProvisionerTypeEcho ),
@@ -301,14 +303,13 @@ func (g *Generator) Populate(ctx context.Context, seed map[string]interface{}) m
301
303
case database.WorkspaceResource :
302
304
resource , err := db .InsertWorkspaceResource (ctx , database.InsertWorkspaceResourceParams {
303
305
ID : takeFirst (orig .ID , g .Lookup (name )),
304
- CreatedAt : takeFirstTime (orig .CreatedAt , time .Now ()),
306
+ CreatedAt : takeFirst (orig .CreatedAt , time .Now ()),
305
307
JobID : takeFirst (orig .JobID , uuid .New ()),
306
308
Transition : takeFirst (orig .Transition , database .WorkspaceTransitionStart ),
307
- // TODO: What type to put here?
308
- Type : takeFirst (orig .Type , "" ),
309
- Name : takeFirst (orig .Name , namesgenerator .GetRandomName (1 )),
310
- Hide : takeFirst (orig .Hide , false ),
311
- Icon : takeFirst (orig .Icon , "" ),
309
+ Type : takeFirst (orig .Type , "fake_resource" ),
310
+ Name : takeFirst (orig .Name , namesgenerator .GetRandomName (1 )),
311
+ Hide : takeFirst (orig .Hide , false ),
312
+ Icon : takeFirst (orig .Icon , "" ),
312
313
InstanceType : sql.NullString {
313
314
String : takeFirst (orig .InstanceType .String , "" ),
314
315
Valid : takeFirst (orig .InstanceType .Valid , false ),
@@ -323,7 +324,7 @@ func (g *Generator) Populate(ctx context.Context, seed map[string]interface{}) m
323
324
file , err := db .InsertFile (ctx , database.InsertFileParams {
324
325
ID : takeFirst (orig .ID , g .Lookup (name )),
325
326
Hash : takeFirst (orig .Hash , hex .EncodeToString (make ([]byte , 32 ))),
326
- CreatedAt : takeFirstTime (orig .CreatedAt , time .Now ()),
327
+ CreatedAt : takeFirst (orig .CreatedAt , time .Now ()),
327
328
CreatedBy : takeFirst (orig .CreatedBy , uuid .New ()),
328
329
Mimetype : takeFirst (orig .Mimetype , "application/x-tar" ),
329
330
Data : takeFirstBytes (orig .Data , []byte {}),
@@ -338,7 +339,7 @@ func (g *Generator) Populate(ctx context.Context, seed map[string]interface{}) m
338
339
LinkedID : takeFirst (orig .LinkedID ),
339
340
OAuthAccessToken : takeFirst (orig .OAuthAccessToken , uuid .NewString ()),
340
341
OAuthRefreshToken : takeFirst (orig .OAuthAccessToken , uuid .NewString ()),
341
- OAuthExpiry : takeFirstTime (orig .OAuthExpiry , time .Now ().Add (time .Hour * 24 )),
342
+ OAuthExpiry : takeFirst (orig .OAuthExpiry , time .Now ().Add (time .Hour * 24 )),
342
343
})
343
344
344
345
require .NoError (t , err , "insert link" )
@@ -367,12 +368,8 @@ func (g *Generator) Lookup(name string) uuid.UUID {
367
368
return id
368
369
}
369
370
370
- func takeFirstTime (values ... time.Time ) time.Time {
371
- return takeFirstF (values , func (v time.Time ) bool {
372
- return ! v .IsZero ()
373
- })
374
- }
375
-
371
+ // takeFirstBytes implements takeFirst for []byte.
372
+ // []byte is not a comparable type.
376
373
func takeFirstBytes (values ... []byte ) []byte {
377
374
return takeFirstF (values , func (v []byte ) bool {
378
375
return len (v ) != 0
0 commit comments