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

Function TestDynamicParametersOwnerGroups

enterprise/coderd/parameters_test.go:21–117  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19)
20
21func TestDynamicParametersOwnerGroups(t *testing.T) {
22 t.Parallel()
23
24 ownerClient, owner := coderdenttest.New(t,
25 &coderdenttest.Options{
26 LicenseOptions: &coderdenttest.LicenseOptions{
27 Features: license.Features{
28 codersdk.FeatureTemplateRBAC: 1,
29 },
30 },
31 Options: &coderdtest.Options{IncludeProvisionerDaemon: true},
32 },
33 )
34 templateAdmin, templateAdminUser := coderdtest.CreateAnotherUser(t, ownerClient, owner.OrganizationID, rbac.ScopedRoleOrgTemplateAdmin(owner.OrganizationID))
35 _, noGroupUser := coderdtest.CreateAnotherUser(t, ownerClient, owner.OrganizationID)
36
37 // Create the group to be asserted
38 // Make the group name something after "Everyone" when sorted alphabetically.
39 // The test wants to check that `Everyone` is the default, which is the first alphabetical group in the test.
40 group := coderdtest.CreateGroup(t, ownerClient, owner.OrganizationID, "zebra", templateAdminUser)
41
42 dynamicParametersTerraformSource, err := os.ReadFile("testdata/parameters/groups/main.tf")
43 require.NoError(t, err)
44 dynamicParametersTerraformPlan, err := os.ReadFile("testdata/parameters/groups/plan.json")
45 require.NoError(t, err)
46
47 files := echo.WithExtraFiles(map[string][]byte{
48 "main.tf": dynamicParametersTerraformSource,
49 })
50 files.ProvisionPlan = []*proto.Response{{
51 Type: &proto.Response_Plan{
52 Plan: &proto.PlanComplete{
53 Plan: dynamicParametersTerraformPlan,
54 },
55 },
56 }}
57
58 version := coderdtest.CreateTemplateVersion(t, templateAdmin, owner.OrganizationID, files)
59 coderdtest.AwaitTemplateVersionJobCompleted(t, templateAdmin, version.ID)
60 _ = coderdtest.CreateTemplate(t, templateAdmin, owner.OrganizationID, version.ID)
61
62 ctx := testutil.Context(t, testutil.WaitShort)
63
64 // First check with a no group admin user, that they do not see the extra group
65 // Use the admin client, as the user might not have access to the template.
66 // Also checking that the admin can see the form for the other user.
67 noGroupStream, err := templateAdmin.TemplateVersionDynamicParameters(ctx, noGroupUser.ID.String(), version.ID)
68 require.NoError(t, err)
69 defer noGroupStream.Close(websocket.StatusGoingAway)
70 noGroupPreviews := noGroupStream.Chan()
71 noGroupPreview := testutil.RequireReceive(ctx, t, noGroupPreviews)
72 require.Equal(t, -1, noGroupPreview.ID)
73 require.Empty(t, noGroupPreview.Diagnostics)
74 require.Equal(t, "group", noGroupPreview.Parameters[0].Name)
75 require.Equal(t, database.EveryoneGroup, noGroupPreview.Parameters[0].Value.Value)
76 require.Equal(t, 1, len(noGroupPreview.Parameters[0].Options)) // Only 1 group
77 noGroupStream.Close(websocket.StatusGoingAway)
78

Callers

nothing calls this directly

Calls 15

NewFunction · 0.92
CreateAnotherUserFunction · 0.92
CreateGroupFunction · 0.92
WithExtraFilesFunction · 0.92
CreateTemplateVersionFunction · 0.92
CreateTemplateFunction · 0.92
ContextFunction · 0.92
RequireReceiveFunction · 0.92
SynchronousStreamFunction · 0.92

Tested by

no test coverage detected