(t *testing.T)
| 65 | } |
| 66 | |
| 67 | func TestEntitlements(t *testing.T) { |
| 68 | t.Parallel() |
| 69 | t.Run("NoLicense", func(t *testing.T) { |
| 70 | t.Parallel() |
| 71 | adminClient, _, api, adminUser := coderdenttest.NewWithAPI(t, &coderdenttest.Options{ |
| 72 | DontAddLicense: true, |
| 73 | }) |
| 74 | anotherClient, _ := coderdtest.CreateAnotherUser(t, adminClient, adminUser.OrganizationID) |
| 75 | res, err := anotherClient.Entitlements(context.Background()) |
| 76 | require.NoError(t, err) |
| 77 | require.False(t, res.HasLicense) |
| 78 | require.Empty(t, res.Warnings) |
| 79 | |
| 80 | // Ensure the entitlements are the same reference |
| 81 | require.Equal(t, fmt.Sprintf("%p", api.Entitlements), fmt.Sprintf("%p", api.AGPL.Entitlements)) |
| 82 | }) |
| 83 | t.Run("FullLicense", func(t *testing.T) { |
| 84 | t.Parallel() |
| 85 | adminClient, _ := coderdenttest.New(t, &coderdenttest.Options{ |
| 86 | AuditLogging: true, |
| 87 | DontAddLicense: true, |
| 88 | }) |
| 89 | // Enable all features |
| 90 | features := make(license.Features) |
| 91 | for _, feature := range codersdk.FeatureNames { |
| 92 | features[feature] = 1 |
| 93 | } |
| 94 | features[codersdk.FeatureUserLimit] = 100 |
| 95 | coderdenttest.AddLicense(t, adminClient, coderdenttest.LicenseOptions{ |
| 96 | Features: features, |
| 97 | Addons: []codersdk.Addon{codersdk.AddonAIGovernance}, |
| 98 | GraceAt: time.Now().Add(59 * 24 * time.Hour), |
| 99 | }) |
| 100 | res, err := adminClient.Entitlements(context.Background()) //nolint:gocritic // adding another user would put us over user limit |
| 101 | require.NoError(t, err) |
| 102 | assert.True(t, res.HasLicense) |
| 103 | ul := res.Features[codersdk.FeatureUserLimit] |
| 104 | assert.Equal(t, codersdk.EntitlementEntitled, ul.Entitlement) |
| 105 | if assert.NotNil(t, ul.Limit) { |
| 106 | assert.Equal(t, int64(100), *ul.Limit) |
| 107 | } |
| 108 | if assert.NotNil(t, ul.Actual) { |
| 109 | assert.Equal(t, int64(1), *ul.Actual) |
| 110 | } |
| 111 | assert.True(t, ul.Enabled) |
| 112 | al := res.Features[codersdk.FeatureAuditLog] |
| 113 | assert.Equal(t, codersdk.EntitlementEntitled, al.Entitlement) |
| 114 | assert.True(t, al.Enabled) |
| 115 | assert.Nil(t, al.Limit) |
| 116 | assert.Nil(t, al.Actual) |
| 117 | assert.Empty(t, res.Warnings) |
| 118 | }) |
| 119 | |
| 120 | // TestEntitlements/MultiplePrebuildsLicenseUpdates verifies that uploading |
| 121 | // multiple licenses with prebuilds enabled doesn't cause a panic from |
| 122 | // duplicate Prometheus metric registration. This was a bug where the new |
| 123 | // reconciler's metrics were registered before the old reconciler was stopped. |
| 124 | t.Run("MultiplePrebuildsLicenseUpdates", func(t *testing.T) { |
nothing calls this directly
no test coverage detected