forked from berty/weshnet
-
Notifications
You must be signed in to change notification settings - Fork 5
/
blackbox_test.go
180 lines (142 loc) · 3.7 KB
/
blackbox_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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package weshnet_test
import (
"context"
"fmt"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"berty.tech/weshnet/v2"
"berty.tech/weshnet/v2/pkg/protocoltypes"
"berty.tech/weshnet/v2/pkg/secretstore"
"berty.tech/weshnet/v2/pkg/testutil"
)
func TestTestingClient_impl(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
logger, cleanup := testutil.Logger(t)
defer cleanup()
secretStore, err := secretstore.NewInMemSecretStore(nil)
require.NoError(t, err)
client, cleanup := weshnet.TestingService(ctx, t, weshnet.Opts{
Logger: logger,
SecretStore: secretStore,
})
defer cleanup()
// test service
_, _ = client.ServiceGetConfiguration(ctx, &protocoltypes.ServiceGetConfiguration_Request{})
status := client.Status()
expected := weshnet.Status{}
assert.Equal(t, expected, status)
}
func ExampleNewInMemoryServiceClient_basic() {
// disable ressources manager for test
os.Setenv("LIBP2P_RCMGR", "false")
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
client, err := weshnet.NewInMemoryServiceClient()
if err != nil {
panic(err)
}
defer client.Close()
ret, err := client.ServiceGetConfiguration(ctx, &protocoltypes.ServiceGetConfiguration_Request{})
if err != nil {
panic(err)
}
for _, listener := range ret.Listeners {
if listener == "/p2p-circuit" {
fmt.Println(listener)
}
}
// Output:
// /p2p-circuit
}
func ExampleNewPersistentServiceClient_basic() {
// disable ressources manager for test
os.Setenv("LIBP2P_RCMGR", "false")
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// create a temporary path to host data of our persistent service
path, err := os.MkdirTemp("", "weshnet-test-persistent")
if err != nil {
panic(err)
}
defer os.RemoveAll(path)
var peerid string
// open once
{
client, err := weshnet.NewPersistentServiceClient(path)
if err != nil {
panic(err)
}
ret, err := client.ServiceGetConfiguration(ctx, &protocoltypes.ServiceGetConfiguration_Request{})
if err != nil {
panic(err)
}
peerid = ret.PeerId
if err := client.Close(); err != nil {
panic(err)
}
}
// open twice
{
client, err := weshnet.NewPersistentServiceClient(path)
if err != nil {
panic(err)
}
defer client.Close()
ret, err := client.ServiceGetConfiguration(ctx, &protocoltypes.ServiceGetConfiguration_Request{})
if err != nil {
panic(err)
}
if peerid != ret.PeerId {
panic("peerid should be identical")
}
}
// Output:
}
func ExampleNewServiceClient_basic() {
// disable ressources manager for test
os.Setenv("LIBP2P_RCMGR", "false")
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
client, err := weshnet.NewServiceClient(weshnet.Opts{})
if err != nil {
panic(err)
}
defer client.Close()
ret, err := client.ServiceGetConfiguration(ctx, &protocoltypes.ServiceGetConfiguration_Request{})
if err != nil {
panic(err)
}
for _, listener := range ret.Listeners {
if listener == "/p2p-circuit" {
fmt.Println(listener)
}
}
// Output:
// /p2p-circuit
}
func ExampleNewService_basic() {
// disable ressources manager for test
os.Setenv("LIBP2P_RCMGR", "false")
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
client, err := weshnet.NewService(weshnet.Opts{})
if err != nil {
panic(err)
}
defer client.Close()
ret, err := client.ServiceGetConfiguration(ctx, &protocoltypes.ServiceGetConfiguration_Request{})
if err != nil {
panic(err)
}
for _, listener := range ret.Listeners {
if listener == "/p2p-circuit" {
fmt.Println(listener)
}
}
// Output:
// /p2p-circuit
}
// FIXME: create examples that actually use groups and contacts