(t *testing.T)
| 51 | } |
| 52 | |
| 53 | func 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 | |
| 82 | func TestInMemoryAuditLog_LogEvents(t *testing.T) { |
| 83 | auditLog := NewInMemoryAuditLog(nil) |
nothing calls this directly
no test coverage detected