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

Function TestAuditLogs

coderd/audit_test.go:25–227  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23)
24
25func TestAuditLogs(t *testing.T) {
26 t.Parallel()
27
28 t.Run("OK", func(t *testing.T) {
29 t.Parallel()
30
31 ctx := context.Background()
32 client := coderdtest.New(t, nil)
33 user := coderdtest.CreateFirstUser(t, client)
34
35 err := client.CreateTestAuditLog(ctx, codersdk.CreateTestAuditLogRequest{
36 ResourceID: user.UserID,
37 OrganizationID: user.OrganizationID,
38 })
39 require.NoError(t, err)
40
41 alogs, err := client.AuditLogs(ctx, codersdk.AuditLogsRequest{
42 Pagination: codersdk.Pagination{
43 Limit: 1,
44 },
45 })
46 require.NoError(t, err)
47
48 require.Equal(t, int64(1), alogs.Count)
49 require.Len(t, alogs.AuditLogs, 1)
50 })
51
52 t.Run("IncludeUser", func(t *testing.T) {
53 t.Parallel()
54
55 ctx := context.Background()
56 client := coderdtest.New(t, nil)
57 user := coderdtest.CreateFirstUser(t, client)
58 client2, user2 := coderdtest.CreateAnotherUser(t, client, user.OrganizationID, rbac.RoleOwner())
59
60 err := client2.CreateTestAuditLog(ctx, codersdk.CreateTestAuditLogRequest{
61 ResourceID: user2.ID,
62 OrganizationID: user.OrganizationID,
63 })
64 require.NoError(t, err)
65
66 alogs, err := client.AuditLogs(ctx, codersdk.AuditLogsRequest{
67 Pagination: codersdk.Pagination{
68 Limit: 1,
69 },
70 })
71 require.NoError(t, err)
72 require.Equal(t, int64(1), alogs.Count)
73 require.Len(t, alogs.AuditLogs, 1)
74
75 // Make sure the returned user is fully populated.
76 foundUser, err := client.User(ctx, user2.ID.String())
77 foundUser.OrganizationIDs = []uuid.UUID{} // Not included.
78 require.NoError(t, err)
79 require.Equal(t, foundUser, *alogs.AuditLogs[0].User)
80
81 // Delete the user and try again. This is a soft delete so nothing should
82 // change. If users are hard deleted we should get nil, but there is no way

Callers

nothing calls this directly

Calls 15

NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
RoleOwnerFunction · 0.92
CreateTemplateVersionFunction · 0.92
CreateTemplateFunction · 0.92
CreateWorkspaceFunction · 0.92
BuildReasonTypeAlias · 0.92
ScopedRoleOrgAdminFunction · 0.92
CreateTestAuditLogMethod · 0.80

Tested by

no test coverage detected