(t *testing.T)
| 80 | } |
| 81 | |
| 82 | func 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 | |
| 107 | func TestInMemoryAuditLog_GetEvent(t *testing.T) { |
| 108 | auditLog := NewInMemoryAuditLog(nil) |
nothing calls this directly
no test coverage detected