internal: fix the tests broken by hardening

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: If95a5258a393542564f68b3a1ebc7ff66a6a6964
This commit is contained in:
raf 2026-03-01 13:40:19 +03:00
commit da1fab4257
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
6 changed files with 17 additions and 17 deletions

View file

@ -74,8 +74,8 @@ func (h *IngestionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
// Apply sampling
if h.cfg.Site.Sampling < 1.0 {
// Apply sampling (0.0 or 1.0 = no sampling, < 1.0 = sample)
if h.cfg.Site.Sampling > 0.0 && h.cfg.Site.Sampling < 1.0 {
if h.rng.Float64() > h.cfg.Site.Sampling {
// Sampled out, return success but don't track
w.WriteHeader(http.StatusNoContent)

View file

@ -38,7 +38,7 @@ func TestIngestionHandler_Pageview(t *testing.T) {
pathNorm := normalize.NewPathNormalizer(cfg.Site.Path)
pathRegistry := aggregate.NewPathRegistry(cfg.Limits.MaxPaths)
refRegistry := normalize.NewReferrerRegistry(cfg.Limits.MaxSources)
metricsAgg := aggregate.NewMetricsAggregator(pathRegistry, cfg)
metricsAgg := aggregate.NewMetricsAggregator(pathRegistry, aggregate.NewCustomEventRegistry(100), cfg)
handler := NewIngestionHandler(cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
@ -80,7 +80,7 @@ func TestIngestionHandler_CustomEvent(t *testing.T) {
pathNorm := normalize.NewPathNormalizer(cfg.Site.Path)
pathRegistry := aggregate.NewPathRegistry(cfg.Limits.MaxPaths)
refRegistry := normalize.NewReferrerRegistry(cfg.Limits.MaxSources)
metricsAgg := aggregate.NewMetricsAggregator(pathRegistry, cfg)
metricsAgg := aggregate.NewMetricsAggregator(pathRegistry, aggregate.NewCustomEventRegistry(100), cfg)
handler := NewIngestionHandler(cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
@ -114,7 +114,7 @@ func TestIngestionHandler_WrongDomain(t *testing.T) {
pathNorm := normalize.NewPathNormalizer(cfg.Site.Path)
pathRegistry := aggregate.NewPathRegistry(cfg.Limits.MaxPaths)
refRegistry := normalize.NewReferrerRegistry(cfg.Limits.MaxSources)
metricsAgg := aggregate.NewMetricsAggregator(pathRegistry, cfg)
metricsAgg := aggregate.NewMetricsAggregator(pathRegistry, aggregate.NewCustomEventRegistry(100), cfg)
handler := NewIngestionHandler(cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
@ -144,7 +144,7 @@ func TestIngestionHandler_MethodNotAllowed(t *testing.T) {
pathNorm := normalize.NewPathNormalizer(cfg.Site.Path)
pathRegistry := aggregate.NewPathRegistry(cfg.Limits.MaxPaths)
refRegistry := normalize.NewReferrerRegistry(cfg.Limits.MaxSources)
metricsAgg := aggregate.NewMetricsAggregator(pathRegistry, cfg)
metricsAgg := aggregate.NewMetricsAggregator(pathRegistry, aggregate.NewCustomEventRegistry(100), cfg)
handler := NewIngestionHandler(cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
@ -171,7 +171,7 @@ func TestIngestionHandler_InvalidJSON(t *testing.T) {
pathNorm := normalize.NewPathNormalizer(cfg.Site.Path)
pathRegistry := aggregate.NewPathRegistry(cfg.Limits.MaxPaths)
refRegistry := normalize.NewReferrerRegistry(cfg.Limits.MaxSources)
metricsAgg := aggregate.NewMetricsAggregator(pathRegistry, cfg)
metricsAgg := aggregate.NewMetricsAggregator(pathRegistry, aggregate.NewCustomEventRegistry(100), cfg)
handler := NewIngestionHandler(cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)
@ -206,7 +206,7 @@ func TestIngestionHandler_DeviceClassification(t *testing.T) {
pathNorm := normalize.NewPathNormalizer(cfg.Site.Path)
pathRegistry := aggregate.NewPathRegistry(cfg.Limits.MaxPaths)
refRegistry := normalize.NewReferrerRegistry(cfg.Limits.MaxSources)
metricsAgg := aggregate.NewMetricsAggregator(pathRegistry, cfg)
metricsAgg := aggregate.NewMetricsAggregator(pathRegistry, aggregate.NewCustomEventRegistry(100), cfg)
handler := NewIngestionHandler(cfg, pathNorm, pathRegistry, refRegistry, metricsAgg)