@@ -186,7 +186,7 @@ func TestEntitlements(t *testing.T) {
186
186
187
187
// Insert the expiring license
188
188
graceDate := dbtime .Now ().AddDate (0 , 0 , 1 )
189
- db .InsertLicense (context .Background (), database.InsertLicenseParams {
189
+ _ , err := db .InsertLicense (context .Background (), database.InsertLicenseParams {
190
190
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
191
191
Features : license.Features {
192
192
codersdk .FeatureUserLimit : 100 ,
@@ -199,6 +199,9 @@ func TestEntitlements(t *testing.T) {
199
199
}),
200
200
Exp : time .Now ().AddDate (0 , 0 , 5 ),
201
201
})
202
+ require .NoError (t , err )
203
+
204
+ // Warning should be generated.
202
205
entitlements , err := license .Entitlements (context .Background (), db , 1 , 1 , coderdenttest .Keys , all )
203
206
require .NoError (t , err )
204
207
require .True (t , entitlements .HasLicense )
@@ -207,9 +210,9 @@ func TestEntitlements(t *testing.T) {
207
210
require .Len (t , entitlements .Warnings , 1 )
208
211
require .Contains (t , entitlements .Warnings , "Your license expires in 1 day." )
209
212
210
- // Insert the new, not-yet-valid license that starts before the expiring
213
+ // Insert the new, not-yet-valid license that starts BEFORE the expiring
211
214
// license expires.
212
- db .InsertLicense (context .Background (), database.InsertLicenseParams {
215
+ _ , err = db .InsertLicense (context .Background (), database.InsertLicenseParams {
213
216
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
214
217
Features : license.Features {
215
218
codersdk .FeatureUserLimit : 100 ,
@@ -223,6 +226,9 @@ func TestEntitlements(t *testing.T) {
223
226
}),
224
227
Exp : dbtime .Now ().AddDate (1 , 0 , 5 ),
225
228
})
229
+ require .NoError (t , err )
230
+
231
+ // Warning should be suppressed.
226
232
entitlements , err = license .Entitlements (context .Background (), db , 1 , 1 , coderdenttest .Keys , all )
227
233
require .NoError (t , err )
228
234
require .True (t , entitlements .HasLicense )
@@ -237,7 +243,7 @@ func TestEntitlements(t *testing.T) {
237
243
238
244
// Insert the expiring license
239
245
graceDate := dbtime .Now ().AddDate (0 , 0 , 1 )
240
- db .InsertLicense (context .Background (), database.InsertLicenseParams {
246
+ _ , err := db .InsertLicense (context .Background (), database.InsertLicenseParams {
241
247
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
242
248
Features : license.Features {
243
249
codersdk .FeatureUserLimit : 100 ,
@@ -250,6 +256,9 @@ func TestEntitlements(t *testing.T) {
250
256
}),
251
257
Exp : time .Now ().AddDate (0 , 0 , 5 ),
252
258
})
259
+ require .NoError (t , err )
260
+
261
+ // Should generate a warning.
253
262
entitlements , err := license .Entitlements (context .Background (), db , 1 , 1 , coderdenttest .Keys , all )
254
263
require .NoError (t , err )
255
264
require .True (t , entitlements .HasLicense )
@@ -258,9 +267,9 @@ func TestEntitlements(t *testing.T) {
258
267
require .Len (t , entitlements .Warnings , 1 )
259
268
require .Contains (t , entitlements .Warnings , "Your license expires in 1 day." )
260
269
261
- // Insert the new, not-yet-valid license that starts before the expiring
262
- // license expires.
263
- db .InsertLicense (context .Background (), database.InsertLicenseParams {
270
+ // Insert the new, not-yet-valid license that starts AFTER the expiring
271
+ // license expires (e.g. there's a gap)
272
+ _ , err = db .InsertLicense (context .Background (), database.InsertLicenseParams {
264
273
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
265
274
Features : license.Features {
266
275
codersdk .FeatureUserLimit : 100 ,
@@ -274,6 +283,9 @@ func TestEntitlements(t *testing.T) {
274
283
}),
275
284
Exp : dbtime .Now ().AddDate (1 , 0 , 5 ),
276
285
})
286
+ require .NoError (t , err )
287
+
288
+ // Warning should still be generated.
277
289
entitlements , err = license .Entitlements (context .Background (), db , 1 , 1 , coderdenttest .Keys , all )
278
290
require .NoError (t , err )
279
291
require .True (t , entitlements .HasLicense )
0 commit comments