-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption_test.go
84 lines (75 loc) · 1.76 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
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
package parwork
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestWorkers(t *testing.T) {
assert := assert.New(t)
tests := []struct {
name string
count int
want int
wantError bool
}{
{"success with 1 worker", 1, 1, false},
{"fails with 0 worker", 0, 0, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p, err := New(generator, Workers(tt.count))
if tt.wantError {
assert.NotNil(err, "Worker error = %v, wantErr %v", err, tt.wantError)
} else {
assert.Equal(p.workers, tt.want, "workers = %v, want %v", p.workers, tt.want)
}
})
}
}
func TestQueue(t *testing.T) {
assert := assert.New(t)
tests := []struct {
name string
length int
want int
wantError bool
}{
{"success with 1 queue length", 1, 1, false},
{"fails with 0 queue length", 0, 0, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p, err := New(generator, Queue(tt.length))
if tt.wantError {
assert.NotNil(err, "Queue error = %v, wantErr %v", err, tt.wantError)
} else {
assert.NotEqual(p.workers, tt.want, "queue length = %v, want %v", p.workers, tt.want)
}
})
}
}
func TestReporter(t *testing.T) {
assert := assert.New(t)
tests := []struct {
name string
collector WorkCollector
wantError bool
}{
{"success", reporter, false},
{"fails with nil reporter", nil, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err := New(generator, Collector(tt.collector))
if tt.wantError {
assert.NotNil(err, "reporter error = %v, wantErr %v", err, tt.wantError)
} else {
assert.Nil(nil, "reporter is nil but wanted not nil")
}
})
}
}
func generator() Work {
return &testWork{}
}
func reporter(w Work) {
}