-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption_test.go
58 lines (44 loc) · 1.54 KB
/
option_test.go
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
package captchasolve
import (
"testing"
captchatoolsgo "github.com/Matthew17-21/Captcha-Tools/captchatools-go"
"github.com/stretchr/testify/assert"
)
func (m *mockHarvester) Harvest() string { return "mock-token" }
func (m *mockHarvester) GetBalance() (float32, error) { return 0, nil }
func (m *mockHarvester) GetToken(additional ...*captchatoolsgo.AdditionalData) (*captchatoolsgo.CaptchaAnswer, error) {
return nil, nil
} // Function to get a captcha token
func TestWithMaxCapacity(t *testing.T) {
cfg := &config{}
option := WithMaxCapacity(10)
option(cfg)
assert.Equal(t, 10, cfg.maxCapacity, "maxCapacity should be set to 10")
}
func TestWithHarvester(t *testing.T) {
cfg := &config{}
mockHarvester := &mockHarvester{}
option := WithHarvester(mockHarvester)
option(cfg)
assert.Contains(t, cfg.harvesters, mockHarvester, "harvester should be added to the harvesters slice")
}
func TestWithMaxGoroutines(t *testing.T) {
cfg := &config{}
t.Run("valid max goroutines", func(t *testing.T) {
option := WithMaxGoroutines(5)
option(cfg)
assert.Equal(t, 5, cfg.maxCapacity, "maxCapacity should be set to 5")
})
t.Run("invalid max goroutines", func(t *testing.T) {
option := WithMaxGoroutines(0)
option(cfg)
assert.Equal(t, 1, cfg.maxCapacity, "maxCapacity should be set to 1 when an invalid value is passed")
})
}
func TestWithLogger(t *testing.T) {
cfg := &config{}
mockLogger := &mockLogger{}
option := WithLogger(mockLogger)
option(cfg)
assert.Equal(t, mockLogger, cfg.logger, "logger should be set to the provided mockLogger")
}