MCPcopy Create free account
hub / github.com/coder/coder / TestEnterpriseListTemplates

Function TestEnterpriseListTemplates

enterprise/cli/templatelist_test.go:20–67  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18)
19
20func TestEnterpriseListTemplates(t *testing.T) {
21 t.Parallel()
22
23 t.Run("MultiOrg", func(t *testing.T) {
24 t.Parallel()
25
26 client, owner := coderdenttest.New(t, &coderdenttest.Options{
27 Options: &coderdtest.Options{
28 IncludeProvisionerDaemon: true,
29 },
30 LicenseOptions: &coderdenttest.LicenseOptions{
31 Features: license.Features{
32 codersdk.FeatureMultipleOrganizations: 1,
33 codersdk.FeatureExternalProvisionerDaemons: 1,
34 },
35 },
36 })
37
38 // Template in the first organization
39 firstVersion := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, nil)
40 _ = coderdtest.AwaitTemplateVersionJobCompleted(t, client, firstVersion.ID)
41 _ = coderdtest.CreateTemplate(t, client, owner.OrganizationID, firstVersion.ID)
42
43 secondOrg := coderdenttest.CreateOrganization(t, client, coderdenttest.CreateOrganizationOptions{
44 IncludeProvisionerDaemon: true,
45 })
46 secondVersion := coderdtest.CreateTemplateVersion(t, client, secondOrg.ID, nil)
47 _ = coderdtest.CreateTemplate(t, client, secondOrg.ID, secondVersion.ID)
48
49 // Create a site wide template admin
50 templateAdmin, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.RoleTemplateAdmin())
51
52 inv, root := clitest.New(t, "templates", "list", "--output=json")
53 clitest.SetupConfig(t, templateAdmin, root)
54
55 ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitLong)
56 defer cancelFunc()
57
58 out := bytes.NewBuffer(nil)
59 inv.Stdout = out
60 err := inv.WithContext(ctx).Run()
61 require.NoError(t, err)
62
63 var templates []codersdk.Template
64 require.NoError(t, json.Unmarshal(out.Bytes(), &templates))
65 require.Len(t, templates, 2)
66 })
67}

Callers

nothing calls this directly

Calls 14

NewFunction · 0.92
CreateTemplateVersionFunction · 0.92
CreateTemplateFunction · 0.92
CreateOrganizationFunction · 0.92
CreateAnotherUserFunction · 0.92
RoleTemplateAdminFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
WithContextMethod · 0.80
RunMethod · 0.65
UnmarshalMethod · 0.45

Tested by

no test coverage detected