forked from benmanns/goworker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queues_flag_test.go
117 lines (112 loc) · 2.02 KB
/
queues_flag_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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package goworker
import (
"errors"
"fmt"
"testing"
)
var queuesFlagSetTests = []struct {
v string
expected queuesFlag
err error
}{
{
"",
nil,
errors.New("you must specify at least one queue"),
},
{
"high",
queuesFlag([]string{"high"}),
nil,
},
{
"high,low",
queuesFlag([]string{"high", "low"}),
nil,
},
{
"high=2,low=1",
queuesFlag([]string{"high", "high", "low"}),
nil,
},
{
"high=2,low",
queuesFlag([]string{"high", "high", "low"}),
nil,
},
{
"low=1,high=2",
queuesFlag([]string{"low", "high", "high"}),
nil,
},
{
"low=,high=2",
nil,
errors.New("the weight must be a numeric value"),
},
{
"low=a,high=2",
nil,
errors.New("the weight must be a numeric value"),
},
{
"low=",
nil,
errors.New("the weight must be a numeric value"),
},
{
"low=a",
nil,
errors.New("the weight must be a numeric value"),
},
{
"high=2,,,=1",
queuesFlag([]string{"high", "high"}),
nil,
},
{
",,,",
nil,
errors.New("you must specify at least one queue"),
},
{
"=1",
nil,
errors.New("you must specify at least one queue"),
},
}
func TestQueuesFlagSet(t *testing.T) {
for _, tt := range queuesFlagSetTests {
actual := new(queuesFlag)
err := actual.Set(tt.v)
if fmt.Sprint(actual) != fmt.Sprint(tt.expected) {
t.Errorf("QueuesFlag: set to %s expected %v, actual %v", tt.v, tt.expected, actual)
}
if (err != nil && tt.err == nil) ||
(err == nil && tt.err != nil) ||
(err != nil && tt.err != nil && err.Error() != tt.err.Error()) {
t.Errorf("QueuesFlag: set to %s expected err %v, actual err %v", tt.v, tt.err, err)
}
}
}
var queuesFlagStringTests = []struct {
q queuesFlag
expected string
}{
{
queuesFlag([]string{"high"}),
"[high]",
},
{
queuesFlag([]string{"high", "low"}),
"[high low]",
},
}
func TestQueuesFlagString(t *testing.T) {
for _, tt := range queuesFlagStringTests {
actual := tt.q.String()
if actual != tt.expected {
t.Errorf("QueuesFlag(%#v): expected %s, actual %s", tt.q, tt.expected, actual)
}
}
}