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

Function TestTemplates

enterprise/coderd/templates_test.go:35–870  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

33)
34
35func TestTemplates(t *testing.T) {
36 t.Parallel()
37
38 logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Leveled(slog.LevelDebug)
39
40 t.Run("Deprecated", func(t *testing.T) {
41 t.Parallel()
42
43 notifyEnq := &notificationstest.FakeEnqueuer{}
44 owner, user := coderdenttest.New(t, &coderdenttest.Options{
45 Options: &coderdtest.Options{
46 IncludeProvisionerDaemon: true,
47 NotificationsEnqueuer: notifyEnq,
48 },
49 LicenseOptions: &coderdenttest.LicenseOptions{
50 Features: license.Features{
51 codersdk.FeatureAccessControl: 1,
52 },
53 },
54 })
55 client, secondUser := coderdtest.CreateAnotherUser(t, owner, user.OrganizationID, rbac.RoleTemplateAdmin())
56 otherClient, otherUser := coderdtest.CreateAnotherUser(t, owner, user.OrganizationID, rbac.RoleTemplateAdmin())
57
58 version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
59 template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
60 coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
61
62 _ = coderdtest.CreateWorkspace(t, owner, template.ID)
63 _ = coderdtest.CreateWorkspace(t, client, template.ID)
64
65 // Create another template for testing that users of another template do not
66 // get a notification.
67 secondVersion := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
68 secondTemplate := coderdtest.CreateTemplate(t, client, user.OrganizationID, secondVersion.ID)
69 coderdtest.AwaitTemplateVersionJobCompleted(t, client, secondVersion.ID)
70
71 _ = coderdtest.CreateWorkspace(t, otherClient, secondTemplate.ID)
72
73 ctx := testutil.Context(t, testutil.WaitLong)
74
75 updated, err := client.UpdateTemplateMeta(ctx, template.ID, codersdk.UpdateTemplateMeta{
76 DeprecationMessage: ptr.Ref("Stop using this template"),
77 })
78 require.NoError(t, err)
79 assert.Greater(t, updated.UpdatedAt, template.UpdatedAt)
80 // AGPL cannot deprecate, expect no change
81 assert.True(t, updated.Deprecated)
82 assert.NotEmpty(t, updated.DeprecationMessage)
83
84 notifs := []*notificationstest.FakeNotification{}
85 for _, notif := range notifyEnq.Sent() {
86 if notif.TemplateID == notifications.TemplateTemplateDeprecated {
87 notifs = append(notifs, notif)
88 }
89 }
90 require.Equal(t, 2, len(notifs))
91
92 expectedSentTo := []string{user.UserID.String(), secondUser.ID.String()}

Callers

nothing calls this directly

Calls 15

SentMethod · 0.95
NewFunction · 0.92
CreateAnotherUserFunction · 0.92
RoleTemplateAdminFunction · 0.92
CreateTemplateVersionFunction · 0.92
CreateTemplateFunction · 0.92
CreateWorkspaceFunction · 0.92
ContextFunction · 0.92
RefFunction · 0.92
DeploymentValuesFunction · 0.92

Tested by

no test coverage detected