fix(p2p): add test for issue #5523
;wq Signed-off-by: Overbool <overbool.xu@gmail.com> License: MIT Signed-off-by: Overbool <overbool.xu@gmail.com>
Overbool committed
Sep 28, 2018 at 08:20 UTC
717c0c83a1c409280dc93a9da5634814528dadaa
2 files changed
+21
-3
core/commands/p2p.go
+1
-1
@@ -273,7 +273,7 @@ func checkPort(target ma.Multiaddr) error {
273
}
274
275
if port == 0 {
276
- return fmt.Errorf("port can't be 0")
276
+ return fmt.Errorf("port can not be 0")
277
}
278
279
return nil
test/sharness/t0180-p2p.sh
+20
-2
@@ -6,7 +6,7 @@ test_description="Test experimental p2p commands"
6
7
# start iptb + wait for peering
8
test_expect_success 'init iptb' '
9
- iptb init -n 2 --bootstrap=none --port=0
9
+ iptb init -n 3 --bootstrap=none --port=0
10
'
11
12
test_expect_success 'generate test data' '
@@ -14,7 +14,7 @@ test_expect_success 'generate test data' '
14
echo "012345" > test1.bin
15
'
16
17
-startup_cluster 2
17
+startup_cluster 3
18
19
test_expect_success 'peer ids' '
20
PEERID_0=$(iptb get id 0) &&
@@ -37,6 +37,7 @@ test_expect_success 'fail without config option being enabled' '
37
test_expect_success "enable filestore config setting" '
38
ipfsi 0 config --json Experimental.Libp2pStreamMounting true
39
ipfsi 1 config --json Experimental.Libp2pStreamMounting true
40
+ ipfsi 2 config --json Experimental.Libp2pStreamMounting true
41
'
42
43
test_expect_success 'start p2p listener' '
@@ -147,6 +148,23 @@ test_expect_success 'C->S Close local listener' '
148
149
check_test_ports
150
151
+# Checking port
152
+
153
+test_expect_success "cannot accept 0 port in 'ipfs p2p listen'" '
154
+ test_must_fail ipfsi 2 p2p listen /x/p2p-test/0 /ip4/127.0.0.1/tcp/0
155
+'
156
+
157
+test_expect_success "'ipfs p2p forward' accept 0 port" '
158
+ ipfsi 2 p2p forward /x/p2p-test/0 /ip4/127.0.0.1/tcp/0 /ipfs/$PEERID_0
159
+'
160
+
161
+test_expect_success "'ipfs p2p ls' output looks good" '
162
+ echo "true" > forward_0_expected &&
163
+ ipfsi 2 p2p ls | awk '\''{print $2}'\'' | sed "s/.*\///" | awk -F: '\''{if($1>0)print"true"}'\'' > forward_0_actual &&
164
+ ipfsi 2 p2p close -p /x/p2p-test/0 &&
165
+ test_cmp forward_0_expected forward_0_actual
166
+'
167
+
168
# Listing streams
169
170
test_expect_success "'ipfs p2p ls' succeeds" '