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

Function TestInMemoryAuditLog_LogEventAsync

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

Source from the content-addressed store, hash-verified

51}
52
53func TestInMemoryAuditLog_LogEventAsync(t *testing.T) {
54 auditLog := NewInMemoryAuditLog(nil)
55 defer func() { _ = auditLog.Close() }()
56
57 event := AuditEvent{
58 Type: AuditTypeUserLogin,
59 UserID: "user1",
60 Message: "User logged in",
61 }
62
63 err := auditLog.LogEventAsync(event)
64 if err != nil {
65 t.Fatalf("LogEventAsync failed: %v", err)
66 }
67
68 // 等待异步处理完成
69 time.Sleep(100 * time.Millisecond)
70
71 // 使用GetEventsByUser而不是直接访问events字段
72 events, err := auditLog.GetEventsByUser("user1", 10)
73 if err != nil {
74 t.Fatalf("GetEventsByUser failed: %v", err)
75 }
76
77 if len(events) == 0 {
78 t.Error("expected event to be logged asynchronously")
79 }
80}
81
82func TestInMemoryAuditLog_LogEvents(t *testing.T) {
83 auditLog := NewInMemoryAuditLog(nil)

Callers

nothing calls this directly

Calls 5

CloseMethod · 0.95
LogEventAsyncMethod · 0.95
GetEventsByUserMethod · 0.95
NewInMemoryAuditLogFunction · 0.85
ErrorMethod · 0.65

Tested by

no test coverage detected