Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/output/stats/stats_test.go
2070 views
1
package stats
2
3
import (
4
"testing"
5
)
6
7
func TestTrackErrorKind(t *testing.T) {
8
tracker := NewTracker()
9
10
// Test single increment
11
tracker.TrackErrorKind("timeout")
12
if count, _ := tracker.errorCodes.Get("timeout"); count == nil || count.Load() != 1 {
13
t.Errorf("expected error kind timeout count to be 1, got %v", count)
14
}
15
16
// Test multiple increments
17
tracker.TrackErrorKind("timeout")
18
if count, _ := tracker.errorCodes.Get("timeout"); count == nil || count.Load() != 2 {
19
t.Errorf("expected error kind timeout count to be 2, got %v", count)
20
}
21
22
// Test different error kind
23
tracker.TrackErrorKind("connection-refused")
24
if count, _ := tracker.errorCodes.Get("connection-refused"); count == nil || count.Load() != 1 {
25
t.Errorf("expected error kind connection-refused count to be 1, got %v", count)
26
}
27
}
28
29
func TestTrackWaf_Detect(t *testing.T) {
30
tracker := NewTracker()
31
32
tracker.TrackWAFDetected("Attention Required! | Cloudflare")
33
if count, _ := tracker.wafDetected.Get("cloudflare"); count == nil || count.Load() != 1 {
34
t.Errorf("expected waf detected count to be 1, got %v", count)
35
}
36
}
37
38