MCPcopy Create free account
hub / github.com/astercloud/aster / TestInMemoryAuditLog_GetEventsByUser

Function TestInMemoryAuditLog_GetEventsByUser

pkg/security/audit_test.go:141–159  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

139}
140
141func TestInMemoryAuditLog_GetEventsByUser(t *testing.T) {
142 auditLog := NewInMemoryAuditLog(nil)
143 defer func() { _ = auditLog.Close() }()
144
145 // 添加多个用户的事件
146 _ = auditLog.LogEvent(AuditEvent{Type: AuditTypeUserLogin, UserID: "user1", Message: "Login 1"})
147 _ = auditLog.LogEvent(AuditEvent{Type: AuditTypeUserLogout, UserID: "user2", Message: "Logout 1"})
148 _ = auditLog.LogEvent(AuditEvent{Type: AuditTypeUserLogin, UserID: "user1", Message: "Login 2"})
149
150 // 获取user1的事件
151 events, err := auditLog.GetEventsByUser("user1", 10)
152 if err != nil {
153 t.Fatalf("GetEventsByUser failed: %v", err)
154 }
155
156 if len(events) != 2 {
157 t.Errorf("expected 2 events for user1, got %d", len(events))
158 }
159}
160
161func TestInMemoryAuditLog_GetEventsByType(t *testing.T) {
162 auditLog := NewInMemoryAuditLog(nil)

Callers

nothing calls this directly

Calls 4

CloseMethod · 0.95
LogEventMethod · 0.95
GetEventsByUserMethod · 0.95
NewInMemoryAuditLogFunction · 0.85

Tested by

no test coverage detected