-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathbootstrap_test.go
159 lines (151 loc) · 2.77 KB
/
bootstrap_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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package routinghelpers
import (
"context"
"errors"
"testing"
"github.com/hashicorp/errwrap"
"github.com/libp2p/go-libp2p/core/routing"
)
type bootstrapRouter struct {
Null
bs func() error
}
func (bs *bootstrapRouter) Bootstrap(ctx context.Context) error {
return bs.bs()
}
func TestBootstrap(t *testing.T) {
t.Parallel()
pings := make([]bool, 6)
d := Parallel{
Routers: []routing.Routing{
Tiered{
Routers: []routing.Routing{
&bootstrapRouter{
bs: func() error {
pings[0] = true
return nil
},
},
},
},
Tiered{
Routers: []routing.Routing{
&bootstrapRouter{
bs: func() error {
pings[1] = true
return nil
},
},
&bootstrapRouter{
bs: func() error {
pings[2] = true
return nil
},
},
},
},
&Compose{
ValueStore: &LimitedValueStore{
ValueStore: &bootstrapRouter{
bs: func() error {
pings[3] = true
return nil
},
},
Namespaces: []string{"allow1", "allow2", "notsupported", "error"},
},
},
&Compose{
ValueStore: &LimitedValueStore{
ValueStore: &dummyValueStore{},
},
},
Null{},
&Compose{},
&Compose{
ContentRouting: &bootstrapRouter{
bs: func() error {
pings[4] = true
return nil
},
},
PeerRouting: &bootstrapRouter{
bs: func() error {
pings[5] = true
return nil
},
},
},
},
}
ctx := context.Background()
if err := d.Bootstrap(ctx); err != nil {
t.Fatal(err)
}
for i, p := range pings {
if !p {
t.Errorf("pings %d not seen", i)
}
}
}
func TestBootstrapErr(t *testing.T) {
t.Parallel()
d := Parallel{
Routers: []routing.Routing{
Tiered{
Routers: []routing.Routing{
&bootstrapRouter{
bs: func() error {
return errors.New("err1")
},
},
},
},
Tiered{
Routers: []routing.Routing{
&bootstrapRouter{
bs: func() error {
return nil
},
},
&bootstrapRouter{
bs: func() error {
return nil
},
},
},
},
&Compose{
ValueStore: &LimitedValueStore{
ValueStore: &bootstrapRouter{
bs: func() error {
return errors.New("err2")
},
},
Namespaces: []string{"allow1", "allow2", "notsupported", "error"},
},
},
&Compose{
ValueStore: &bootstrapRouter{
bs: func() error {
return errors.New("err3")
},
},
ContentRouting: &bootstrapRouter{
bs: func() error {
return errors.New("err4")
},
},
},
Null{},
},
}
ctx := context.Background()
err := d.Bootstrap(ctx)
t.Log(err)
for _, s := range []string{"err1", "err2", "err3", "err4"} {
if !errwrap.Contains(err, s) {
t.Errorf("expecting error to contain '%s'", s)
}
}
}