@@ -58,15 +58,13 @@ func TestEntitlements(t *testing.T) {
58
58
db := databasefake .New ()
59
59
db .InsertLicense (context .Background (), database.InsertLicenseParams {
60
60
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
61
- UserLimit : 100 ,
62
- AuditLog : true ,
63
- BrowserOnly : true ,
64
- SCIM : true ,
65
- HighAvailability : true ,
66
- TemplateRBAC : true ,
67
- MultipleGitAuth : true ,
68
- ExternalProvisionerDaemons : true ,
69
- ServiceBanners : true ,
61
+ Features : func () license.Features {
62
+ f := make (license.Features )
63
+ for _ , name := range codersdk .FeatureNames {
64
+ f [name ] = 1
65
+ }
66
+ return f
67
+ }(),
70
68
}),
71
69
Exp : time .Now ().Add (time .Hour ),
72
70
})
@@ -83,37 +81,23 @@ func TestEntitlements(t *testing.T) {
83
81
db := databasefake .New ()
84
82
db .InsertLicense (context .Background (), database.InsertLicenseParams {
85
83
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
86
- UserLimit : 100 ,
87
- AuditLog : true ,
88
- BrowserOnly : true ,
89
- SCIM : true ,
90
- HighAvailability : true ,
91
- TemplateRBAC : true ,
92
- ExternalProvisionerDaemons : true ,
93
- ServiceBanners : true ,
94
- GraceAt : time .Now ().Add (- time .Hour ),
95
- ExpiresAt : time .Now ().Add (time .Hour ),
84
+ Features : license.Features {
85
+ codersdk .FeatureUserLimit : 100 ,
86
+ },
87
+
88
+ GraceAt : time .Now ().Add (- time .Hour ),
89
+ ExpiresAt : time .Now ().Add (time .Hour ),
96
90
}),
97
91
Exp : time .Now ().Add (time .Hour ),
98
92
})
99
93
entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 1 , coderdenttest .Keys , all )
100
94
require .NoError (t , err )
101
95
require .True (t , entitlements .HasLicense )
102
96
require .False (t , entitlements .Trial )
103
- for _ , featureName := range codersdk .FeatureNames {
104
- if featureName == codersdk .FeatureUserLimit {
105
- continue
106
- }
107
- if featureName == codersdk .FeatureHighAvailability {
108
- continue
109
- }
110
- if featureName == codersdk .FeatureMultipleGitAuth {
111
- continue
112
- }
113
- niceName := featureName .Humanize ()
114
- require .Equal (t , codersdk .EntitlementGracePeriod , entitlements .Features [featureName ].Entitlement )
115
- require .Contains (t , entitlements .Warnings , fmt .Sprintf ("%s is enabled but your license for this feature is expired." , niceName ))
116
- }
97
+
98
+ require .Equal (t , codersdk .EntitlementGracePeriod , entitlements .Features [codersdk .FeatureUserLimit ].Entitlement )
99
+ require .Contains (t , entitlements .Warnings , fmt .Sprintf ("%s is enabled but your license for this feature is expired." , codersdk .FeatureUserLimit .Humanize ()))
100
+
117
101
})
118
102
t .Run ("SingleLicenseNotEntitled" , func (t * testing.T ) {
119
103
t .Parallel ()
@@ -154,7 +138,9 @@ func TestEntitlements(t *testing.T) {
154
138
})
155
139
db .InsertLicense (context .Background (), database.InsertLicenseParams {
156
140
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
157
- UserLimit : 1 ,
141
+ Features : license.Features {
142
+ codersdk .FeatureUserLimit : 1 ,
143
+ },
158
144
}),
159
145
Exp : time .Now ().Add (time .Hour ),
160
146
})
@@ -170,13 +156,17 @@ func TestEntitlements(t *testing.T) {
170
156
db .InsertUser (context .Background (), database.InsertUserParams {})
171
157
db .InsertLicense (context .Background (), database.InsertLicenseParams {
172
158
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
173
- UserLimit : 10 ,
159
+ Features : license.Features {
160
+ codersdk .FeatureUserLimit : 10 ,
161
+ },
174
162
}),
175
163
Exp : time .Now ().Add (time .Hour ),
176
164
})
177
165
db .InsertLicense (context .Background (), database.InsertLicenseParams {
178
166
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
179
- UserLimit : 1 ,
167
+ Features : license.Features {
168
+ codersdk .FeatureUserLimit : 1 ,
169
+ },
180
170
}),
181
171
Exp : time .Now ().Add (time .Hour ),
182
172
})
@@ -247,7 +237,9 @@ func TestEntitlements(t *testing.T) {
247
237
db .InsertLicense (context .Background (), database.InsertLicenseParams {
248
238
Exp : time .Now ().Add (time .Hour ),
249
239
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
250
- AuditLog : true ,
240
+ Features : license.Features {
241
+ codersdk .FeatureAuditLog : 1 ,
242
+ },
251
243
}),
252
244
})
253
245
entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 2 , 1 , coderdenttest .Keys , map [codersdk.FeatureName ]bool {
@@ -264,9 +256,11 @@ func TestEntitlements(t *testing.T) {
264
256
db := databasefake .New ()
265
257
db .InsertLicense (context .Background (), database.InsertLicenseParams {
266
258
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
267
- HighAvailability : true ,
268
- GraceAt : time .Now ().Add (- time .Hour ),
269
- ExpiresAt : time .Now ().Add (time .Hour ),
259
+ Features : license.Features {
260
+ codersdk .FeatureHighAvailability : 1 ,
261
+ },
262
+ GraceAt : time .Now ().Add (- time .Hour ),
263
+ ExpiresAt : time .Now ().Add (time .Hour ),
270
264
}),
271
265
Exp : time .Now ().Add (time .Hour ),
272
266
})
@@ -295,7 +289,9 @@ func TestEntitlements(t *testing.T) {
295
289
db .InsertLicense (context .Background (), database.InsertLicenseParams {
296
290
Exp : time .Now ().Add (time .Hour ),
297
291
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
298
- AuditLog : true ,
292
+ Features : license.Features {
293
+ codersdk .FeatureAuditLog : 1 ,
294
+ },
299
295
}),
300
296
})
301
297
entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 2 , coderdenttest .Keys , map [codersdk.FeatureName ]bool {
@@ -312,9 +308,11 @@ func TestEntitlements(t *testing.T) {
312
308
db := databasefake .New ()
313
309
db .InsertLicense (context .Background (), database.InsertLicenseParams {
314
310
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
315
- MultipleGitAuth : true ,
316
- GraceAt : time .Now ().Add (- time .Hour ),
317
- ExpiresAt : time .Now ().Add (time .Hour ),
311
+ GraceAt : time .Now ().Add (- time .Hour ),
312
+ ExpiresAt : time .Now ().Add (time .Hour ),
313
+ Features : license.Features {
314
+ codersdk .FeatureMultipleGitAuth : 1 ,
315
+ },
318
316
}),
319
317
Exp : time .Now ().Add (time .Hour ),
320
318
})
0 commit comments