MCPcopy Index your code
hub / github.com/coder/coder / TestPublisherLicenseSelection

Function TestPublisherLicenseSelection

enterprise/coderd/usage/publisher_test.go:428–561  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

426}
427
428func TestPublisherLicenseSelection(t *testing.T) {
429 t.Parallel()
430 ctx := testutil.Context(t, testutil.WaitLong)
431 log := slogtest.Make(t, nil)
432 ctrl := gomock.NewController(t)
433 db := dbmock.NewMockStore(ctrl)
434 clock := quartz.NewMock(t)
435 now := time.Now()
436
437 // Configure the deployment manually.
438 deploymentID := uuid.New()
439 db.EXPECT().GetDeploymentID(gomock.Any()).Return(deploymentID.String(), nil).Times(1)
440
441 // Insert multiple licenses:
442 // 1. PublishUsageData false, type=salesforce, iat 30m ago (ineligible, publish not enabled)
443 // 2. PublishUsageData true, type=trial, iat 1h ago (ineligible, not salesforce)
444 // 3. PublishUsageData true, type=salesforce, iat 30m ago, exp 10m ago (ineligible, expired)
445 // 4. PublishUsageData true, type=salesforce, iat 1h ago (eligible)
446 // 5. PublishUsageData true, type=salesforce, iat 30m ago (eligible, and newer!)
447 badLicense1 := coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
448 PublishUsageData: false,
449 IssuedAt: now.Add(-30 * time.Minute),
450 })
451 badLicense2 := coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
452 PublishUsageData: true,
453 IssuedAt: now.Add(-1 * time.Hour),
454 AccountType: "trial",
455 })
456 badLicense3 := coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
457 PublishUsageData: true,
458 IssuedAt: now.Add(-30 * time.Minute),
459 ExpiresAt: now.Add(-10 * time.Minute),
460 })
461 badLicense4 := coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
462 PublishUsageData: true,
463 IssuedAt: now.Add(-1 * time.Hour),
464 })
465 expectedLicense := coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
466 PublishUsageData: true,
467 IssuedAt: now.Add(-30 * time.Minute),
468 })
469 // GetUnexpiredLicenses is not supposed to return expired licenses, but for
470 // the purposes of this test we're going to do it anyway.
471 db.EXPECT().GetUnexpiredLicenses(gomock.Any()).Return([]database.License{
472 {
473 ID: 1,
474 JWT: badLicense1,
475 Exp: now.Add(48 * time.Hour), // fake times, the JWT should be checked
476 UUID: uuid.New(),
477 UploadedAt: now,
478 },
479 {
480 ID: 2,
481 JWT: badLicense2,
482 Exp: now.Add(48 * time.Hour),
483 UUID: uuid.New(),
484 UploadedAt: now,
485 },

Callers

nothing calls this directly

Calls 15

EXPECTMethod · 0.95
ContextFunction · 0.92
NewMockStoreFunction · 0.92
GenerateLicenseFunction · 0.92
NewTallymanPublisherFunction · 0.92
PublisherWithClockFunction · 0.92
PublisherWithIngestURLFunction · 0.92
RequireSendFunction · 0.92
RequireReceiveFunction · 0.92
fakeServerFunction · 0.85
tallymanHandlerFunction · 0.85
tallymanAcceptAllHandlerFunction · 0.85

Tested by

no test coverage detected