-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
75 lines (61 loc) · 1.2 KB
/
config_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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package easyworker
import (
"fmt"
"testing"
)
func add(a int, b int) int {
return a + b
}
func addWithPanic(a int, b int) int {
if a%3 == 0 {
panic("panic from user func")
}
return a + b
}
func sum(a ...int) int {
sum := 0
for _, i := range a {
sum += i
}
return sum
}
func defaultConfig(fun any) Config {
config, _ := NewConfig(fun, 1, 0, 0)
return config
}
func strId(a int, suffix string) string {
if a%3 == 0 {
panic("panic from user func")
}
return fmt.Sprintf("%d_%s", a, suffix)
}
func TestIsNotFunc(t *testing.T) {
_, err := NewConfig("fun", 1, 0, 0)
if err == nil {
t.Error("missed check function, ", err)
}
}
func TestIncorrectNumWorker(t *testing.T) {
_, err := NewConfig(add, 0, 0, 0)
if err == nil {
t.Error("incorrect number of worker is passed, ", err)
}
}
func TestIncorrectNumRetry(t *testing.T) {
_, err := NewConfig(add, 1, -1, 0)
if err == nil {
t.Error("incorrect number of retry is passed, ", err)
}
}
func TestIncorrectRetryTime(t *testing.T) {
_, err := NewConfig(add, 1, 1, -1)
if err == nil {
t.Error("incorrect retry time is passed, ", err)
}
}
func TestPrintLog(t *testing.T) {
EnableLog(true)
if !printLog {
t.Error("Enable Log failed.")
}
}