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

Function TestEnterpriseAuditLogs

enterprise/coderd/audit_test.go:15–105  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestEnterpriseAuditLogs(t *testing.T) {
16 t.Parallel()
17
18 t.Run("IncludeOrganization", func(t *testing.T) {
19 t.Parallel()
20
21 ctx := context.Background()
22 client, user := coderdenttest.New(t, &coderdenttest.Options{
23 LicenseOptions: &coderdenttest.LicenseOptions{
24 Features: license.Features{
25 codersdk.FeatureMultipleOrganizations: 1,
26 },
27 },
28 })
29
30 //nolint:gocritic // only owners can create organizations
31 o, err := client.CreateOrganization(ctx, codersdk.CreateOrganizationRequest{
32 Name: "new-org",
33 DisplayName: "New organization",
34 Description: "A new organization to love and cherish until the test is over.",
35 Icon: "/emojis/1f48f-1f3ff.png",
36 })
37 require.NoError(t, err)
38
39 err = client.CreateTestAuditLog(ctx, codersdk.CreateTestAuditLogRequest{
40 OrganizationID: o.ID,
41 ResourceID: user.UserID,
42 })
43 require.NoError(t, err)
44
45 alogs, err := client.AuditLogs(ctx, codersdk.AuditLogsRequest{
46 Pagination: codersdk.Pagination{
47 Limit: 1,
48 },
49 })
50 require.NoError(t, err)
51 require.Equal(t, int64(1), alogs.Count)
52 require.Len(t, alogs.AuditLogs, 1)
53
54 // Make sure the organization is fully populated.
55 require.Equal(t, &codersdk.MinimalOrganization{
56 ID: o.ID,
57 Name: o.Name,
58 DisplayName: o.DisplayName,
59 Icon: o.Icon,
60 }, alogs.AuditLogs[0].Organization)
61
62 // OrganizationID is deprecated, but make sure it is set.
63 require.Equal(t, o.ID, alogs.AuditLogs[0].OrganizationID)
64
65 // Delete the org and try again, should be mostly empty.
66 err = client.DeleteOrganization(ctx, o.ID.String())
67 require.NoError(t, err)
68
69 alogs, err = client.AuditLogs(ctx, codersdk.AuditLogsRequest{
70 Pagination: codersdk.Pagination{
71 Limit: 1,
72 },

Callers

nothing calls this directly

Calls 9

NewFunction · 0.92
CreateOrganizationMethod · 0.80
CreateTestAuditLogMethod · 0.80
RunMethod · 0.65
AuditLogsMethod · 0.45
EqualMethod · 0.45
LenMethod · 0.45
DeleteOrganizationMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected