-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathclient_test.go
56 lines (50 loc) · 1001 Bytes
/
client_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
package main
import (
"testing"
"time"
)
func TestReconnect(t *testing.T) {
type args struct {
sock string
retryDelay func([]error) time.Duration
prevErrors []error
hasFailed func([]error) bool
}
type testCase struct {
setup func()
input args
expect func([]error) bool
teardown func()
}
cases := []testCase{
{
setup: func() {
// create UNIX domain socket
},
input: args{
sock: "/tmp/enoent",
retryDelay: func(errors []error) time.Duration {
return 1 * time.Second
},
prevErrors: []error{},
hasFailed: func(errors []error) bool {
if len(errors) < 20 {
return false
}
return true
},
},
expect: func([]error) bool {
return true
},
teardown: func() {
},
},
}
for _, c := range cases {
_, got := tryConnect("unix", c.input.sock, c.input.retryDelay, c.input.prevErrors, c.input.hasFailed)
if !c.expect(got) {
panic("got something different than we expected")
}
}
}