(t *testing.T)
| 22 | } |
| 23 | |
| 24 | func 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 | |
| 53 | func TestInMemoryAuditLog_LogEventAsync(t *testing.T) { |
| 54 | auditLog := NewInMemoryAuditLog(nil) |
nothing calls this directly
no test coverage detected