@cryptotaxi247 / kubo / commits / 63a9ed202

make t0060 use port zero

License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Jeromy committed Mar 2, 2016 at 15:00 UTC 63a9ed202c971f5bd5075bccd633eb0eedc31699
2 files changed +30 -38
test/sharness/lib/test-lib.sh
+19 -13
@@ -181,25 +181,15 @@ test_wait_for_file() {
181 done
182 }
183
184 -test_launch_ipfs_daemon() {
185 -
186 - args="$@"
187 -
188 - test_expect_success "'ipfs daemon' succeeds" '
189 - ipfs daemon $args >actual_daemon 2>daemon_err &
190 - '
191 -
192 - # wait for api file to show up
193 - test_expect_success "api file shows up" '
194 - test_wait_for_file 20 100ms "$IPFS_PATH/api"
195 - '
184 +test_set_address_vars() {
185 + daemon_output="$1"
186
187 test_expect_success "set up address variables" '
188 API_MADDR=$(cat "$IPFS_PATH/api") &&
189 API_ADDR=$(convert_tcp_maddr $API_MADDR) &&
190 API_PORT=$(port_from_maddr $API_MADDR) &&
191
202 - GWAY_MADDR=$(sed -n "s/^Gateway (.*) server listening on //p" actual_daemon) &&
192 + GWAY_MADDR=$(sed -n "s/^Gateway (.*) server listening on //p" "$daemon_output") &&
193 GWAY_ADDR=$(convert_tcp_maddr $GWAY_MADDR) &&
194 GWAY_PORT=$(port_from_maddr $GWAY_MADDR)
195 '
@@ -210,6 +200,22 @@ test_launch_ipfs_daemon() {
200 SWARM_MADDR=$(grep "127.0.0.1" addrs_out) &&
201 SWARM_PORT=$(port_from_maddr $SWARM_MADDR)
202 '
203 +}
204 +
205 +test_launch_ipfs_daemon() {
206 +
207 + args="$@"
208 +
209 + test_expect_success "'ipfs daemon' succeeds" '
210 + ipfs daemon $args >actual_daemon 2>daemon_err &
211 + '
212 +
213 + # wait for api file to show up
214 + test_expect_success "api file shows up" '
215 + test_wait_for_file 20 100ms "$IPFS_PATH/api"
216 + '
217 +
218 + test_set_address_vars actual_daemon
219
220 # we say the daemon is ready when the API server is ready.
221 test_expect_success "'ipfs daemon' is ready" '
test/sharness/t0060-daemon.sh
+11 -25
@@ -8,27 +8,8 @@ test_description="Test daemon command"
8
9 . lib/test-lib.sh
10
11 -gwyport=8082
12 -apiport=5002
13 -swarmport=4003
14 -
15 -# TODO: randomize ports here once we add --config to ipfs daemon
16 -
17 -# this needs to be in a different test than "ipfs daemon" below
18 -test_expect_success "setup IPFS_PATH" '
19 - IPFS_PATH="$(pwd)/.ipfs" &&
20 - export IPFS_PATH
21 -'
22 -
23 -api_maddr="/ip4/0.0.0.0/tcp/$apiport"
24 -gway_maddr="/ip4/0.0.0.0/tcp/$gwyport"
25 -test_expect_success 'ipfs init & config' '
26 - ipfs init &&
27 - ipfs config Addresses.Gateway $gway_maddr &&
28 - ipfs config Addresses.API $api_maddr &&
29 - ipfs config --json=true Addresses.Swarm "[\"/ip4/0.0.0.0/tcp/4003\"]"
30 -'
11
12 +test_init_ipfs
13 test_launch_ipfs_daemon
14
15 # this errors if we didn't --init $IPFS_PATH correctly
@@ -47,11 +28,11 @@ test_expect_success "ipfs peer id looks good" '
28 # this is for checking SetAllowedOrigins race condition for the api and gateway
29 # See https://github.com/ipfs/go-ipfs/pull/1966
30 test_expect_success "ipfs API works with the correct allowed origin port" '
50 - curl -s -X GET -H "Origin:http://localhost:$apiport" -I "http://localhost:$apiport/api/v0/version"
31 + curl -s -X GET -H "Origin:http://localhost:$API_PORT" -I "http://$API_ADDR/api/v0/version"
32 '
33
34 test_expect_success "ipfs gateway works with the correct allowed origin port" '
54 - curl -s -X GET -H "Origin:http://localhost:$gwyport" -I "http://localhost:$gwyport/api/v0/version"
35 + curl -s -X GET -H "Origin:http://localhost:$GWAY_PORT" -I "http://$GWAY_ADDR/api/v0/version"
36 '
37
38 test_expect_success "ipfs daemon output looks good" '
@@ -100,14 +81,14 @@ test_expect_success "nc is available" '
81
82 # check transport is encrypted
83 test_expect_success "transport should be encrypted" '
103 - nc -w 5 localhost '$swarmport' >swarmnc &&
84 + nc -w 5 localhost $SWARM_PORT >swarmnc &&
85 grep -q "AES-256,AES-128" swarmnc &&
86 test_must_fail grep -q "/multistream/1.0.0" swarmnc ||
87 test_fsh cat swarmnc
88 '
89
90 test_expect_success "output from streaming commands works" '
110 - test_expect_code 28 curl -m 2 http://localhost:'$apiport'/api/v0/stats/bw\?poll=true > statsout
91 + test_expect_code 28 curl -m 2 http://localhost:$API_PORT/api/v0/stats/bw\?poll=true > statsout
92 '
93
94 test_expect_success "output looks good" '
@@ -128,7 +109,12 @@ test_expect_success "'ipfs daemon' can be killed" '
109 '
110
111 test_expect_success "'ipfs daemon' should be able to run with a pipe attached to stdin (issue #861)" '
131 - yes | ipfs daemon --init >stdin_daemon_out 2>stdin_daemon_err &
112 + yes | ipfs daemon >stdin_daemon_out 2>stdin_daemon_err &
113 + test_wait_for_file 20 100ms "$IPFS_PATH/api" &&
114 + test_set_address_vars stdin_daemon_out
115 +'
116 +
117 +test_expect_success "daemon with pipe eventually becomes live" '
118 pollEndpoint -host='$API_MADDR' -ep=/version -v -tout=1s -tries=10 >stdin_poll_apiout 2>stdin_poll_apierr &&
119 test_kill_repeat_10_sec $! ||
120 test_fsh cat stdin_daemon_out || test_fsh cat stdin_daemon_err || test_fsh cat stdin_poll_apiout || test_fsh cat stdin_poll_apierr