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

Function TestTemplateInsightsWithTemplateAdminACL

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

Source from the content-addressed store, hash-verified

19)
20
21func TestTemplateInsightsWithTemplateAdminACL(t *testing.T) {
22 t.Parallel()
23
24 y, m, d := time.Now().UTC().Date()
25 today := time.Date(y, m, d, 0, 0, 0, 0, time.UTC)
26
27 type test struct {
28 interval codersdk.InsightsReportInterval
29 }
30
31 tests := []test{
32 {codersdk.InsightsReportIntervalDay},
33 {""},
34 }
35
36 for _, tt := range tests {
37 t.Run(fmt.Sprintf("with interval=%q", tt.interval), func(t *testing.T) {
38 t.Parallel()
39
40 client, admin := coderdenttest.New(t, &coderdenttest.Options{LicenseOptions: &coderdenttest.LicenseOptions{
41 Features: license.Features{
42 codersdk.FeatureTemplateRBAC: 1,
43 },
44 }})
45 templateAdminClient, _ := coderdtest.CreateAnotherUser(t, client, admin.OrganizationID, rbac.RoleTemplateAdmin())
46
47 version := coderdtest.CreateTemplateVersion(t, client, admin.OrganizationID, nil)
48 template := coderdtest.CreateTemplate(t, client, admin.OrganizationID, version.ID)
49
50 regular, regularUser := coderdtest.CreateAnotherUser(t, client, admin.OrganizationID)
51
52 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
53 defer cancel()
54
55 err := templateAdminClient.UpdateTemplateACL(ctx, template.ID, codersdk.UpdateTemplateACL{
56 UserPerms: map[string]codersdk.TemplateRole{
57 regularUser.ID.String(): codersdk.TemplateRoleAdmin,
58 },
59 })
60 require.NoError(t, err)
61
62 _, err = regular.TemplateInsights(ctx, codersdk.TemplateInsightsRequest{
63 StartTime: today.AddDate(0, 0, -1),
64 EndTime: today,
65 TemplateIDs: []uuid.UUID{template.ID},
66 })
67 require.NoError(t, err)
68 })
69 }
70}
71
72func TestTemplateInsightsWithRole(t *testing.T) {
73 t.Parallel()

Callers

nothing calls this directly

Calls 9

NewFunction · 0.92
CreateAnotherUserFunction · 0.92
RoleTemplateAdminFunction · 0.92
CreateTemplateVersionFunction · 0.92
CreateTemplateFunction · 0.92
UpdateTemplateACLMethod · 0.80
TemplateInsightsMethod · 0.80
RunMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected