(t *testing.T)
| 665 | } |
| 666 | |
| 667 | func TestManagedAgentLimit(t *testing.T) { |
| 668 | t.Parallel() |
| 669 | |
| 670 | ctx := testutil.Context(t, testutil.WaitLong) |
| 671 | |
| 672 | cli, owner := coderdenttest.New(t, &coderdenttest.Options{ |
| 673 | Options: &coderdtest.Options{ |
| 674 | IncludeProvisionerDaemon: true, |
| 675 | }, |
| 676 | LicenseOptions: (&coderdenttest.LicenseOptions{ |
| 677 | FeatureSet: codersdk.FeatureSetPremium, |
| 678 | // Make it expire in the distant future so it doesn't generate |
| 679 | // expiry warnings. |
| 680 | GraceAt: time.Now().Add(time.Hour * 24 * 60), |
| 681 | ExpiresAt: time.Now().Add(time.Hour * 24 * 90), |
| 682 | }).ManagedAgentLimit(1), |
| 683 | }) |
| 684 | |
| 685 | // Get entitlements to check that the license is a-ok. |
| 686 | sdkEntitlements, err := cli.Entitlements(ctx) //nolint:gocritic // we're not testing authz on the entitlements endpoint, so using owner is fine |
| 687 | require.NoError(t, err) |
| 688 | require.True(t, sdkEntitlements.HasLicense) |
| 689 | agentLimit := sdkEntitlements.Features[codersdk.FeatureManagedAgentLimit] |
| 690 | require.True(t, agentLimit.Enabled) |
| 691 | require.NotNil(t, agentLimit.Limit) |
| 692 | require.EqualValues(t, 1, *agentLimit.Limit) |
| 693 | require.Empty(t, sdkEntitlements.Errors) |
| 694 | |
| 695 | // Create a fake provision response that claims there are agents in the |
| 696 | // template and every built workspace. |
| 697 | // |
| 698 | // It's fine that the app ID is only used in a single successful workspace |
| 699 | // build. |
| 700 | appID := uuid.NewString() |
| 701 | echoRes := &echo.Responses{ |
| 702 | Parse: echo.ParseComplete, |
| 703 | ProvisionInit: echo.InitComplete, |
| 704 | ProvisionPlan: []*proto.Response{ |
| 705 | { |
| 706 | Type: &proto.Response_Plan{ |
| 707 | Plan: &proto.PlanComplete{ |
| 708 | Plan: []byte("{}"), |
| 709 | }, |
| 710 | }, |
| 711 | }, |
| 712 | }, |
| 713 | ProvisionApply: echo.ApplyComplete, |
| 714 | ProvisionGraph: []*proto.Response{{ |
| 715 | Type: &proto.Response_Graph{ |
| 716 | Graph: &proto.GraphComplete{ |
| 717 | Resources: []*proto.Resource{{ |
| 718 | Name: "example", |
| 719 | Type: "aws_instance", |
| 720 | Agents: []*proto.Agent{{ |
| 721 | Id: uuid.NewString(), |
| 722 | Name: "example", |
| 723 | Auth: &proto.Agent_Token{ |
| 724 | Token: uuid.NewString(), |
nothing calls this directly
no test coverage detected