(t *testing.T)
| 298 | } |
| 299 | |
| 300 | func TestEntitlements_Prebuilds(t *testing.T) { |
| 301 | t.Parallel() |
| 302 | |
| 303 | cases := []struct { |
| 304 | name string |
| 305 | featureEnabled bool |
| 306 | expectedEnabled bool |
| 307 | }{ |
| 308 | { |
| 309 | name: "Feature enabled", |
| 310 | featureEnabled: true, |
| 311 | expectedEnabled: true, |
| 312 | }, |
| 313 | { |
| 314 | name: "Feature disabled", |
| 315 | featureEnabled: false, |
| 316 | expectedEnabled: false, |
| 317 | }, |
| 318 | } |
| 319 | |
| 320 | for _, tc := range cases { |
| 321 | t.Run(tc.name, func(t *testing.T) { |
| 322 | t.Parallel() |
| 323 | |
| 324 | var prebuildsEntitled int64 |
| 325 | if tc.featureEnabled { |
| 326 | prebuildsEntitled = 1 |
| 327 | } |
| 328 | |
| 329 | _, _, api, _ := coderdenttest.NewWithAPI(t, &coderdenttest.Options{ |
| 330 | Options: &coderdtest.Options{ |
| 331 | DeploymentValues: coderdtest.DeploymentValues(t), |
| 332 | }, |
| 333 | |
| 334 | EntitlementsUpdateInterval: time.Second, |
| 335 | LicenseOptions: &coderdenttest.LicenseOptions{ |
| 336 | Features: license.Features{ |
| 337 | codersdk.FeatureWorkspacePrebuilds: prebuildsEntitled, |
| 338 | }, |
| 339 | }, |
| 340 | }) |
| 341 | |
| 342 | // The entitlements will need to refresh before the reconciler is set. |
| 343 | require.Eventually(t, func() bool { |
| 344 | return api.AGPL.PrebuildsReconciler.Load() != nil |
| 345 | }, testutil.WaitSuperLong, testutil.IntervalFast) |
| 346 | |
| 347 | reconciler := api.AGPL.PrebuildsReconciler.Load() |
| 348 | claimer := api.AGPL.PrebuildsClaimer.Load() |
| 349 | require.NotNil(t, reconciler) |
| 350 | require.NotNil(t, claimer) |
| 351 | |
| 352 | if tc.expectedEnabled { |
| 353 | require.IsType(t, &prebuilds.StoreReconciler{}, *reconciler) |
| 354 | require.IsType(t, &prebuilds.EnterpriseClaimer{}, *claimer) |
| 355 | } else { |
| 356 | require.Equal(t, &agplprebuilds.DefaultReconciler, reconciler) |
| 357 | require.Equal(t, &agplprebuilds.DefaultClaimer, claimer) |
nothing calls this directly
no test coverage detected