(t *testing.T)
| 139 | } |
| 140 | |
| 141 | func TestInMemoryAuditLog_GetEventsByUser(t *testing.T) { |
| 142 | auditLog := NewInMemoryAuditLog(nil) |
| 143 | defer func() { _ = auditLog.Close() }() |
| 144 | |
| 145 | // 添加多个用户的事件 |
| 146 | _ = auditLog.LogEvent(AuditEvent{Type: AuditTypeUserLogin, UserID: "user1", Message: "Login 1"}) |
| 147 | _ = auditLog.LogEvent(AuditEvent{Type: AuditTypeUserLogout, UserID: "user2", Message: "Logout 1"}) |
| 148 | _ = auditLog.LogEvent(AuditEvent{Type: AuditTypeUserLogin, UserID: "user1", Message: "Login 2"}) |
| 149 | |
| 150 | // 获取user1的事件 |
| 151 | events, err := auditLog.GetEventsByUser("user1", 10) |
| 152 | if err != nil { |
| 153 | t.Fatalf("GetEventsByUser failed: %v", err) |
| 154 | } |
| 155 | |
| 156 | if len(events) != 2 { |
| 157 | t.Errorf("expected 2 events for user1, got %d", len(events)) |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | func TestInMemoryAuditLog_GetEventsByType(t *testing.T) { |
| 162 | auditLog := NewInMemoryAuditLog(nil) |
nothing calls this directly
no test coverage detected