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

Function TestInMemoryAuditLog_LogEvent

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

Source from the content-addressed store, hash-verified

22}
23
24func TestInMemoryAuditLog_LogEvent(t *testing.T) {
25 auditLog := NewInMemoryAuditLog(nil)
26 defer func() { _ = auditLog.Close() }()
27
28 event := AuditEvent{
29 Type: AuditTypeUserLogin,
30 UserID: "user1",
31 Message: "User logged in",
32 Timestamp: time.Now(),
33 }
34
35 err := auditLog.LogEvent(event)
36 if err != nil {
37 t.Fatalf("LogEvent failed: %v", err)
38 }
39
40 // 使用GetStatus而不是直接访问events字段
41 status := auditLog.GetStatus()
42 if status.TotalEvents != 1 {
43 t.Errorf("expected 1 event, got %d", status.TotalEvents)
44 }
45
46 // 使用GetEventsByUser验证用户ID
47 events, _ := auditLog.GetEventsByUser("user1", 10)
48 if len(events) > 0 && events[0].UserID != "user1" {
49 t.Errorf("expected UserID 'user1', got '%s'", events[0].UserID)
50 }
51}
52
53func TestInMemoryAuditLog_LogEventAsync(t *testing.T) {
54 auditLog := NewInMemoryAuditLog(nil)

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected