Skip to content

Commit 81fe738

Browse files
committed
fix error checks in tests
1 parent 15b637d commit 81fe738

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

enterprise/coderd/license/license_test.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func TestEntitlements(t *testing.T) {
186186

187187
// Insert the expiring license
188188
graceDate := dbtime.Now().AddDate(0, 0, 1)
189-
db.InsertLicense(context.Background(), database.InsertLicenseParams{
189+
_, err := db.InsertLicense(context.Background(), database.InsertLicenseParams{
190190
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
191191
Features: license.Features{
192192
codersdk.FeatureUserLimit: 100,
@@ -199,6 +199,9 @@ func TestEntitlements(t *testing.T) {
199199
}),
200200
Exp: time.Now().AddDate(0, 0, 5),
201201
})
202+
require.NoError(t, err)
203+
204+
// Warning should be generated.
202205
entitlements, err := license.Entitlements(context.Background(), db, 1, 1, coderdenttest.Keys, all)
203206
require.NoError(t, err)
204207
require.True(t, entitlements.HasLicense)
@@ -207,9 +210,9 @@ func TestEntitlements(t *testing.T) {
207210
require.Len(t, entitlements.Warnings, 1)
208211
require.Contains(t, entitlements.Warnings, "Your license expires in 1 day.")
209212

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
211214
// license expires.
212-
db.InsertLicense(context.Background(), database.InsertLicenseParams{
215+
_, err = db.InsertLicense(context.Background(), database.InsertLicenseParams{
213216
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
214217
Features: license.Features{
215218
codersdk.FeatureUserLimit: 100,
@@ -223,6 +226,9 @@ func TestEntitlements(t *testing.T) {
223226
}),
224227
Exp: dbtime.Now().AddDate(1, 0, 5),
225228
})
229+
require.NoError(t, err)
230+
231+
// Warning should be suppressed.
226232
entitlements, err = license.Entitlements(context.Background(), db, 1, 1, coderdenttest.Keys, all)
227233
require.NoError(t, err)
228234
require.True(t, entitlements.HasLicense)
@@ -237,7 +243,7 @@ func TestEntitlements(t *testing.T) {
237243

238244
// Insert the expiring license
239245
graceDate := dbtime.Now().AddDate(0, 0, 1)
240-
db.InsertLicense(context.Background(), database.InsertLicenseParams{
246+
_, err := db.InsertLicense(context.Background(), database.InsertLicenseParams{
241247
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
242248
Features: license.Features{
243249
codersdk.FeatureUserLimit: 100,
@@ -250,6 +256,9 @@ func TestEntitlements(t *testing.T) {
250256
}),
251257
Exp: time.Now().AddDate(0, 0, 5),
252258
})
259+
require.NoError(t, err)
260+
261+
// Should generate a warning.
253262
entitlements, err := license.Entitlements(context.Background(), db, 1, 1, coderdenttest.Keys, all)
254263
require.NoError(t, err)
255264
require.True(t, entitlements.HasLicense)
@@ -258,9 +267,9 @@ func TestEntitlements(t *testing.T) {
258267
require.Len(t, entitlements.Warnings, 1)
259268
require.Contains(t, entitlements.Warnings, "Your license expires in 1 day.")
260269

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{
264273
JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
265274
Features: license.Features{
266275
codersdk.FeatureUserLimit: 100,
@@ -274,6 +283,9 @@ func TestEntitlements(t *testing.T) {
274283
}),
275284
Exp: dbtime.Now().AddDate(1, 0, 5),
276285
})
286+
require.NoError(t, err)
287+
288+
// Warning should still be generated.
277289
entitlements, err = license.Entitlements(context.Background(), db, 1, 1, coderdenttest.Keys, all)
278290
require.NoError(t, err)
279291
require.True(t, entitlements.HasLicense)

0 commit comments

Comments
 (0)