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

Function TestInMemoryAuditLog_LogEvents

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

Source from the content-addressed store, hash-verified

80}
81
82func TestInMemoryAuditLog_LogEvents(t *testing.T) {
83 auditLog := NewInMemoryAuditLog(nil)
84 defer func() { _ = auditLog.Close() }()
85
86 events := []AuditEvent{
87 {Type: AuditTypeUserLogin, UserID: "user1", Message: "Login 1"},
88 {Type: AuditTypeUserLogout, UserID: "user2", Message: "Logout 1"},
89 {Type: AuditTypeUserLogin, UserID: "user3", Message: "Login 2"},
90 }
91
92 err := auditLog.LogEvents(events)
93 if err != nil {
94 t.Fatalf("LogEvents failed: %v", err)
95 }
96
97 // 等待异步处理完成
98 time.Sleep(200 * time.Millisecond)
99
100 // 使用GetStatus而不是直接访问events字段
101 status := auditLog.GetStatus()
102 if status.TotalEvents != 3 {
103 t.Errorf("expected 3 events, got %d", status.TotalEvents)
104 }
105}
106
107func TestInMemoryAuditLog_GetEvent(t *testing.T) {
108 auditLog := NewInMemoryAuditLog(nil)

Callers

nothing calls this directly

Calls 4

CloseMethod · 0.95
LogEventsMethod · 0.95
GetStatusMethod · 0.95
NewInMemoryAuditLogFunction · 0.85

Tested by

no test coverage detected