forked from projectdiscovery/nuclei
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogress_test.go
More file actions
85 lines (68 loc) · 1.77 KB
/
Copy pathprogress_test.go
File metadata and controls
85 lines (68 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package progress
import (
"testing"
"time"
"github.com/projectdiscovery/clistats"
"github.com/stretchr/testify/require"
)
func TestStatsTickerInit_registersPeriodicStatsOnly_whenIntervalIsPositive(t *testing.T) {
tests := []struct {
name string
tickDuration time.Duration
wantPeriodicStats bool
}{
{
name: "interval is disabled",
tickDuration: -1,
wantPeriodicStats: false,
},
{
name: "interval is positive",
tickDuration: time.Second,
wantPeriodicStats: true,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
// Given
stats := &statsClientSpy{}
ticker := &StatsTicker{
active: true,
stats: stats,
tickDuration: test.tickDuration,
}
// When
ticker.Init(1, 1, 1)
// Then
require.True(t, stats.started)
require.Equal(t, test.wantPeriodicStats, stats.periodicStatsRequested)
})
}
}
type statsClientSpy struct {
periodicStatsRequested bool
started bool
}
func (s *statsClientSpy) Start() error {
s.started = true
return nil
}
func (s *statsClientSpy) Stop() error {
return nil
}
func (s *statsClientSpy) AddCounter(string, uint64) {}
func (s *statsClientSpy) GetCounter(string) (uint64, bool) {
return 0, false
}
func (s *statsClientSpy) IncrementCounter(string, int) {}
func (s *statsClientSpy) AddStatic(string, interface{}) {}
func (s *statsClientSpy) GetStatic(string) (interface{}, bool) {
return nil, false
}
func (s *statsClientSpy) AddDynamic(string, clistats.DynamicCallback) {}
func (s *statsClientSpy) GetDynamic(string) (clistats.DynamicCallback, bool) {
return nil, false
}
func (s *statsClientSpy) GetStatResponse(time.Duration, func(string, error) error) {
s.periodicStatsRequested = true
}