-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions_test.go
52 lines (40 loc) · 1.17 KB
/
options_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
package rediswatcher
import "testing"
func TestOptions(t *testing.T) {
o := WatcherOptions{
Channel: "ch1",
Password: "pa1",
Protocol: "pr1",
Username: "user1",
}
// test single option
o.optionBuilder(Channel("ch2"))
if o.Channel != "ch2" {
t.Errorf("Channel should be 'ch2', received '%s' instead", o.Channel)
}
if o.Username != "user1" {
t.Errorf("Username should be 'user1', received '%s' instead", o.Username)
}
if o.Password != "pa1" {
t.Errorf("Password should be 'pa1', received '%s' instead", o.Password)
}
// test multiple options
o.optionBuilder(Channel("ch3"), Password("pa3"), Protocol("pr3"), Username("user3"))
if o.Channel != "ch3" {
t.Errorf("Channel should be 'ch3', received '%s' instead", o.Channel)
}
if o.Password != "pa3" {
t.Errorf("Password should be 'pa3', received '%s' instead", o.Password)
}
if o.Protocol != "pr3" {
t.Errorf("Protocol should be 'pr3', received '%s' instead", o.Password)
}
if o.Username != "user3" {
t.Errorf("Username should be 'user3', received '%s' instead", o.Username)
}
}
func (o *WatcherOptions) optionBuilder(setters ...WatcherOption) {
for _, setter := range setters {
setter(o)
}
}