@@ -12,7 +12,7 @@ import (
12
12
"github.com/stretchr/testify/require"
13
13
14
14
"github.com/coder/coder/v2/coderd/database"
15
- "github.com/coder/coder/v2/coderd/database/dbmem "
15
+ "github.com/coder/coder/v2/coderd/database/dbtestutil "
16
16
"github.com/coder/coder/v2/coderd/database/dbtime"
17
17
"github.com/coder/coder/v2/codersdk"
18
18
"github.com/coder/coder/v2/enterprise/coderd/coderdenttest"
@@ -30,7 +30,7 @@ func TestEntitlements(t *testing.T) {
30
30
31
31
t .Run ("Defaults" , func (t * testing.T ) {
32
32
t .Parallel ()
33
- db := dbmem . New ( )
33
+ db , _ := dbtestutil . NewDB ( t )
34
34
entitlements , err := license .Entitlements (context .Background (), db , 1 , 1 , coderdenttest .Keys , all )
35
35
require .NoError (t , err )
36
36
require .False (t , entitlements .HasLicense )
@@ -42,7 +42,7 @@ func TestEntitlements(t *testing.T) {
42
42
})
43
43
t .Run ("Always return the current user count" , func (t * testing.T ) {
44
44
t .Parallel ()
45
- db := dbmem . New ( )
45
+ db , _ := dbtestutil . NewDB ( t )
46
46
entitlements , err := license .Entitlements (context .Background (), db , 1 , 1 , coderdenttest .Keys , all )
47
47
require .NoError (t , err )
48
48
require .False (t , entitlements .HasLicense )
@@ -51,7 +51,7 @@ func TestEntitlements(t *testing.T) {
51
51
})
52
52
t .Run ("SingleLicenseNothing" , func (t * testing.T ) {
53
53
t .Parallel ()
54
- db := dbmem . New ( )
54
+ db , _ := dbtestutil . NewDB ( t )
55
55
db .InsertLicense (context .Background (), database.InsertLicenseParams {
56
56
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {}),
57
57
Exp : dbtime .Now ().Add (time .Hour ),
@@ -67,7 +67,7 @@ func TestEntitlements(t *testing.T) {
67
67
})
68
68
t .Run ("SingleLicenseAll" , func (t * testing.T ) {
69
69
t .Parallel ()
70
- db := dbmem . New ( )
70
+ db , _ := dbtestutil . NewDB ( t )
71
71
db .InsertLicense (context .Background (), database.InsertLicenseParams {
72
72
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
73
73
Features : func () license.Features {
@@ -90,7 +90,7 @@ func TestEntitlements(t *testing.T) {
90
90
})
91
91
t .Run ("SingleLicenseGrace" , func (t * testing.T ) {
92
92
t .Parallel ()
93
- db := dbmem . New ( )
93
+ db , _ := dbtestutil . NewDB ( t )
94
94
db .InsertLicense (context .Background (), database.InsertLicenseParams {
95
95
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
96
96
Features : license.Features {
@@ -116,7 +116,7 @@ func TestEntitlements(t *testing.T) {
116
116
})
117
117
t .Run ("Expiration warning" , func (t * testing.T ) {
118
118
t .Parallel ()
119
- db := dbmem . New ( )
119
+ db , _ := dbtestutil . NewDB ( t )
120
120
db .InsertLicense (context .Background (), database.InsertLicenseParams {
121
121
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
122
122
Features : license.Features {
@@ -145,7 +145,7 @@ func TestEntitlements(t *testing.T) {
145
145
146
146
t .Run ("Expiration warning for license expiring in 1 day" , func (t * testing.T ) {
147
147
t .Parallel ()
148
- db := dbmem . New ( )
148
+ db , _ := dbtestutil . NewDB ( t )
149
149
db .InsertLicense (context .Background (), database.InsertLicenseParams {
150
150
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
151
151
Features : license.Features {
@@ -174,7 +174,7 @@ func TestEntitlements(t *testing.T) {
174
174
175
175
t .Run ("Expiration warning for trials" , func (t * testing.T ) {
176
176
t .Parallel ()
177
- db := dbmem . New ( )
177
+ db , _ := dbtestutil . NewDB ( t )
178
178
db .InsertLicense (context .Background (), database.InsertLicenseParams {
179
179
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
180
180
Features : license.Features {
@@ -204,7 +204,7 @@ func TestEntitlements(t *testing.T) {
204
204
205
205
t .Run ("Expiration warning for non trials" , func (t * testing.T ) {
206
206
t .Parallel ()
207
- db := dbmem . New ( )
207
+ db , _ := dbtestutil . NewDB ( t )
208
208
db .InsertLicense (context .Background (), database.InsertLicenseParams {
209
209
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
210
210
Features : license.Features {
@@ -233,7 +233,7 @@ func TestEntitlements(t *testing.T) {
233
233
234
234
t .Run ("SingleLicenseNotEntitled" , func (t * testing.T ) {
235
235
t .Parallel ()
236
- db := dbmem . New ( )
236
+ db , _ := dbtestutil . NewDB ( t )
237
237
db .InsertLicense (context .Background (), database.InsertLicenseParams {
238
238
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {}),
239
239
Exp : time .Now ().Add (time .Hour ),
@@ -261,11 +261,13 @@ func TestEntitlements(t *testing.T) {
261
261
})
262
262
t .Run ("TooManyUsers" , func (t * testing.T ) {
263
263
t .Parallel ()
264
- db := dbmem . New ( )
264
+ db , _ := dbtestutil . NewDB ( t )
265
265
activeUser1 , err := db .InsertUser (context .Background (), database.InsertUserParams {
266
266
ID : uuid .New (),
267
267
Username : "test1" ,
268
+ Email : "test1@coder.com" ,
268
269
LoginType : database .LoginTypePassword ,
270
+ RBACRoles : []string {},
269
271
})
270
272
require .NoError (t , err )
271
273
_ , err = db .UpdateUserStatus (context .Background (), database.UpdateUserStatusParams {
@@ -277,7 +279,9 @@ func TestEntitlements(t *testing.T) {
277
279
activeUser2 , err := db .InsertUser (context .Background (), database.InsertUserParams {
278
280
ID : uuid .New (),
279
281
Username : "test2" ,
282
+ Email : "test2@coder.com" ,
280
283
LoginType : database .LoginTypePassword ,
284
+ RBACRoles : []string {},
281
285
})
282
286
require .NoError (t , err )
283
287
_ , err = db .UpdateUserStatus (context .Background (), database.UpdateUserStatusParams {
@@ -289,7 +293,9 @@ func TestEntitlements(t *testing.T) {
289
293
_ , err = db .InsertUser (context .Background (), database.InsertUserParams {
290
294
ID : uuid .New (),
291
295
Username : "dormant-user" ,
296
+ Email : "dormant-user@coder.com" ,
292
297
LoginType : database .LoginTypePassword ,
298
+ RBACRoles : []string {},
293
299
})
294
300
require .NoError (t , err )
295
301
db .InsertLicense (context .Background (), database.InsertLicenseParams {
@@ -307,7 +313,7 @@ func TestEntitlements(t *testing.T) {
307
313
})
308
314
t .Run ("MaximizeUserLimit" , func (t * testing.T ) {
309
315
t .Parallel ()
310
- db := dbmem . New ( )
316
+ db , _ := dbtestutil . NewDB ( t )
311
317
db .InsertUser (context .Background (), database.InsertUserParams {})
312
318
db .InsertUser (context .Background (), database.InsertUserParams {})
313
319
db .InsertLicense (context .Background (), database.InsertLicenseParams {
@@ -335,7 +341,7 @@ func TestEntitlements(t *testing.T) {
335
341
})
336
342
t .Run ("MultipleLicenseEnabled" , func (t * testing.T ) {
337
343
t .Parallel ()
338
- db := dbmem . New ( )
344
+ db , _ := dbtestutil . NewDB ( t )
339
345
// One trial
340
346
db .InsertLicense (context .Background (), database.InsertLicenseParams {
341
347
Exp : time .Now ().Add (time .Hour ),
@@ -359,7 +365,7 @@ func TestEntitlements(t *testing.T) {
359
365
360
366
t .Run ("Enterprise" , func (t * testing.T ) {
361
367
t .Parallel ()
362
- db := dbmem . New ( )
368
+ db , _ := dbtestutil . NewDB ( t )
363
369
_ , err := db .InsertLicense (context .Background (), database.InsertLicenseParams {
364
370
Exp : time .Now ().Add (time .Hour ),
365
371
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
@@ -390,7 +396,7 @@ func TestEntitlements(t *testing.T) {
390
396
391
397
t .Run ("Premium" , func (t * testing.T ) {
392
398
t .Parallel ()
393
- db := dbmem . New ( )
399
+ db , _ := dbtestutil . NewDB ( t )
394
400
_ , err := db .InsertLicense (context .Background (), database.InsertLicenseParams {
395
401
Exp : time .Now ().Add (time .Hour ),
396
402
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
@@ -421,7 +427,7 @@ func TestEntitlements(t *testing.T) {
421
427
422
428
t .Run ("SetNone" , func (t * testing.T ) {
423
429
t .Parallel ()
424
- db := dbmem . New ( )
430
+ db , _ := dbtestutil . NewDB ( t )
425
431
_ , err := db .InsertLicense (context .Background (), database.InsertLicenseParams {
426
432
Exp : time .Now ().Add (time .Hour ),
427
433
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
@@ -443,7 +449,7 @@ func TestEntitlements(t *testing.T) {
443
449
// AllFeatures uses the deprecated 'AllFeatures' boolean.
444
450
t .Run ("AllFeatures" , func (t * testing.T ) {
445
451
t .Parallel ()
446
- db := dbmem . New ( )
452
+ db , _ := dbtestutil . NewDB ( t )
447
453
db .InsertLicense (context .Background (), database.InsertLicenseParams {
448
454
Exp : time .Now ().Add (time .Hour ),
449
455
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
@@ -473,7 +479,7 @@ func TestEntitlements(t *testing.T) {
473
479
474
480
t .Run ("AllFeaturesAlwaysEnable" , func (t * testing.T ) {
475
481
t .Parallel ()
476
- db := dbmem . New ( )
482
+ db , _ := dbtestutil . NewDB ( t )
477
483
db .InsertLicense (context .Background (), database.InsertLicenseParams {
478
484
Exp : dbtime .Now ().Add (time .Hour ),
479
485
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
@@ -504,7 +510,7 @@ func TestEntitlements(t *testing.T) {
504
510
505
511
t .Run ("AllFeaturesGrace" , func (t * testing.T ) {
506
512
t .Parallel ()
507
- db := dbmem . New ( )
513
+ db , _ := dbtestutil . NewDB ( t )
508
514
db .InsertLicense (context .Background (), database.InsertLicenseParams {
509
515
Exp : dbtime .Now ().Add (time .Hour ),
510
516
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
@@ -535,7 +541,7 @@ func TestEntitlements(t *testing.T) {
535
541
536
542
t .Run ("MultipleReplicasNoLicense" , func (t * testing.T ) {
537
543
t .Parallel ()
538
- db := dbmem . New ( )
544
+ db , _ := dbtestutil . NewDB ( t )
539
545
entitlements , err := license .Entitlements (context .Background (), db , 2 , 1 , coderdenttest .Keys , all )
540
546
require .NoError (t , err )
541
547
require .False (t , entitlements .HasLicense )
@@ -545,7 +551,7 @@ func TestEntitlements(t *testing.T) {
545
551
546
552
t .Run ("MultipleReplicasNotEntitled" , func (t * testing.T ) {
547
553
t .Parallel ()
548
- db := dbmem . New ( )
554
+ db , _ := dbtestutil . NewDB ( t )
549
555
db .InsertLicense (context .Background (), database.InsertLicenseParams {
550
556
Exp : time .Now ().Add (time .Hour ),
551
557
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
@@ -565,7 +571,7 @@ func TestEntitlements(t *testing.T) {
565
571
566
572
t .Run ("MultipleReplicasGrace" , func (t * testing.T ) {
567
573
t .Parallel ()
568
- db := dbmem . New ( )
574
+ db , _ := dbtestutil . NewDB ( t )
569
575
db .InsertLicense (context .Background (), database.InsertLicenseParams {
570
576
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
571
577
Features : license.Features {
@@ -587,7 +593,7 @@ func TestEntitlements(t *testing.T) {
587
593
588
594
t .Run ("MultipleGitAuthNoLicense" , func (t * testing.T ) {
589
595
t .Parallel ()
590
- db := dbmem . New ( )
596
+ db , _ := dbtestutil . NewDB ( t )
591
597
entitlements , err := license .Entitlements (context .Background (), db , 1 , 2 , coderdenttest .Keys , all )
592
598
require .NoError (t , err )
593
599
require .False (t , entitlements .HasLicense )
@@ -597,7 +603,7 @@ func TestEntitlements(t *testing.T) {
597
603
598
604
t .Run ("MultipleGitAuthNotEntitled" , func (t * testing.T ) {
599
605
t .Parallel ()
600
- db := dbmem . New ( )
606
+ db , _ := dbtestutil . NewDB ( t )
601
607
db .InsertLicense (context .Background (), database.InsertLicenseParams {
602
608
Exp : time .Now ().Add (time .Hour ),
603
609
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
@@ -617,7 +623,7 @@ func TestEntitlements(t *testing.T) {
617
623
618
624
t .Run ("MultipleGitAuthGrace" , func (t * testing.T ) {
619
625
t .Parallel ()
620
- db := dbmem . New ( )
626
+ db , _ := dbtestutil . NewDB ( t )
621
627
db .InsertLicense (context .Background (), database.InsertLicenseParams {
622
628
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
623
629
GraceAt : time .Now ().Add (- time .Hour ),
0 commit comments