@cryptotaxi247 / kubo / commits / 597d68416

Adds arbitrary port support to t0060-daemon.sh.

Removes all of the hardcoded ports and defaults to non-standard API, Gateway, and Swarm ports. License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io>

Stephen Whitmore committed Feb 18, 2016 at 15:30 UTC 597d684160bcf42dab910d9d22c8f4bfc5a1af65
1 file changed +22 -25
test/sharness/t0060-daemon.sh
+22 -25
@@ -8,29 +8,39 @@ test_description="Test daemon command"
8
9 . lib/test-lib.sh
10
11 -gwyport=8080
12 -apiport=5001
11 +gwyport=8082
12 +apiport=5002
13 +swarmport=4003
14 +
15 +API_ADDR="/ip4/0.0.0.0/tcp/$apiport"
16 +GATEWAY_ADDR="/ip4/0.0.0.0/tcp/$gwyport"
17
18 # TODO: randomize ports here once we add --config to ipfs daemon
19
16 -# this needs to be in a different test than "ipfs daemon --init" below
20 +# this needs to be in a different test than "ipfs daemon" below
21 test_expect_success "setup IPFS_PATH" '
22 IPFS_PATH="$(pwd)/.ipfs" &&
23 export IPFS_PATH
24 '
25
26 +test_expect_success 'ipfs init & config' '
27 + ipfs init &&
28 + ipfs config Addresses.Gateway $GATEWAY_ADDR &&
29 + ipfs config Addresses.API $API_ADDR &&
30 + ipfs config --json=true Addresses.Swarm "[\"/ip4/0.0.0.0/tcp/4003\"]"
31 +'
32 +
33 # NOTE: this should remove bootstrap peers (needs a flag)
34 # TODO(cryptix):
35 # - we won't see daemon startup failure because we put the daemon in the background - fix: fork with exit code after api listen
25 -# - also default ports: might clash with local clients. Failure in that case isn't clear as well because pollEndpoint just uses the already running node
26 -test_expect_success "ipfs daemon --init launches" '
27 - ipfs daemon --init >actual_daemon 2>daemon_err &
36 +test_expect_success "ipfs daemon launches" '
37 + ipfs daemon >actual_daemon 2>daemon_err &
38 '
39
40 # this is like "'ipfs daemon' is ready" in test_launch_ipfs_daemon(), see test-lib.sh
41 test_expect_success "initialization ended" '
42 IPFS_PID=$! &&
33 - pollEndpoint -ep=/version -v -tout=1s -tries=60 2>poll_apierr > poll_apiout ||
43 + pollEndpoint -host='$API_ADDR' -ep=/version -v -tout=1s -tries=60 2>poll_apierr > poll_apiout ||
44 test_fsh cat actual_daemon || test_fsh cat daemon_err || test_fsh cat poll_apierr || test_fsh cat poll_apiout
45 '
46
@@ -57,25 +67,12 @@ test_expect_success "ipfs gateway works with the correct allowed origin port" '
67 curl -s -X GET -H "Origin:http://localhost:$gwyport" -I "http://localhost:$gwyport/api/v0/version"
68 '
69
60 -# This is like t0020-init.sh "ipfs init output looks good"
61 -#
62 -# Unfortunately the line:
63 -#
64 -# API server listening on /ip4/127.0.0.1/tcp/5001
65 -#
66 -# sometimes doesn't show up, so we cannot use test_expect_success yet.
67 -#
70 test_expect_success "ipfs daemon output looks good" '
71 STARTFILE="ipfs cat /ipfs/$HASH_WELCOME_DOCS/readme" &&
72 echo "Initializing daemon..." >expected_daemon &&
71 - echo "initializing ipfs node at $IPFS_PATH" >>expected_daemon &&
72 - echo "generating 2048-bit RSA keypair...done" >>expected_daemon &&
73 - echo "peer identity: $PEERID" >>expected_daemon &&
74 - echo "to get started, enter:" >>expected_daemon &&
75 - printf "\\n\\t$STARTFILE\\n\\n" >>expected_daemon &&
73 sed "s/^/Swarm listening on /" local_addrs >>expected_daemon &&
77 - echo "API server listening on /ip4/127.0.0.1/tcp/5001" >>expected_daemon &&
78 - echo "Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080" >>expected_daemon &&
74 + echo "API server listening on '$API_ADDR'" >>expected_daemon &&
75 + echo "Gateway (readonly) server listening on '$GATEWAY_ADDR'" >>expected_daemon &&
76 echo "Daemon is ready" >>expected_daemon &&
77 test_cmp expected_daemon actual_daemon
78 '
@@ -116,14 +113,14 @@ test_expect_success "nc is available" '
113
114 # check transport is encrypted
115 test_expect_success "transport should be encrypted" '
119 - nc -w 5 localhost 4001 >swarmnc &&
116 + nc -w 5 localhost '$swarmport' >swarmnc &&
117 grep -q "AES-256,AES-128" swarmnc &&
118 test_must_fail grep -q "/multistream/1.0.0" swarmnc ||
119 test_fsh cat swarmnc
120 '
121
122 test_expect_success "output from streaming commands works" '
126 - test_expect_code 28 curl -m 2 http://localhost:5001/api/v0/stats/bw\?poll=true > statsout
123 + test_expect_code 28 curl -m 2 http://localhost:'$apiport'/api/v0/stats/bw\?poll=true > statsout
124 '
125
126 test_expect_success "output looks good" '
@@ -145,7 +142,7 @@ test_expect_success "'ipfs daemon' can be killed" '
142
143 test_expect_success "'ipfs daemon' should be able to run with a pipe attached to stdin (issue #861)" '
144 yes | ipfs daemon --init >stdin_daemon_out 2>stdin_daemon_err &
148 - pollEndpoint -ep=/version -v -tout=1s -tries=10 >stdin_poll_apiout 2>stdin_poll_apierr &&
145 + pollEndpoint -host='$API_ADDR' -ep=/version -v -tout=1s -tries=10 >stdin_poll_apiout 2>stdin_poll_apierr &&
146 test_kill_repeat_10_sec $! ||
147 test_fsh cat stdin_daemon_out || test_fsh cat stdin_daemon_err || test_fsh cat stdin_poll_apiout || test_fsh cat stdin_poll_apierr
148 '