@cryptotaxi247 / kubo / commits / 83369b571

setup and teardown nodes only once

We don't need to do this for every test and our tests are slow enough. License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>

Steven Allen committed Oct 25, 2018 at 08:17 UTC 83369b5716bad42f2875d09ebe5fc48ba20c7568
1 file changed +23 -40
test/sharness/t0184-http-proxy-over-p2p.sh
+23 -40
@@ -34,34 +34,6 @@ function serve_http_once() {
34 REMOTE_SERVER_PID=$!
35 }
36
37 -function setup_sender_and_receiver_ipfs() {
38 - iptb init -n 2 -p 0 -f --bootstrap=none &&
39 -
40 - # Configure features
41 -
42 - ipfsi 0 config --json Experimental.Libp2pStreamMounting true &&
43 - ipfsi 1 config --json Experimental.Libp2pStreamMounting true &&
44 - ipfsi 0 config --json Experimental.P2pHttpProxy true &&
45 -
46 - # Start
47 -
48 - iptb start &&
49 - iptb connect 0 1 &&
50 -
51 - # Setup the p2p listener
52 -
53 - ipfsi 1 p2p listen --allow-custom-protocol test /ip4/127.0.0.1/tcp/$WEB_SERVE_PORT &&
54 -
55 - # Setup Environment
56 -
57 - RECEIVER_ID="$(iptb get id 1)" &&
58 - SENDER_URL="$(sed 's|^/ip[46]/\([^/]*\)/tcp/\([0-9]*\)$|http://\1:\2/proxy/http|' < "$(iptb get path 0)/api")"
59 -}
60 -
61 -function teardown_sender_and_receiver() {
62 - iptb stop
63 -}
64 -
37 function teardown_remote_server() {
38 kill -9 $REMOTE_SERVER_PID > /dev/null 2>&1
39 sleep 5
@@ -151,47 +123,58 @@ function curl_send_multipart_form_request() {
123 return 0
124 }
125
126 +test_expect_success 'configure nodes' '
127 + iptb init -n 2 -p 0 -f --bootstrap=none &&
128 + ipfsi 0 config --json Experimental.Libp2pStreamMounting true &&
129 + ipfsi 1 config --json Experimental.Libp2pStreamMounting true &&
130 + ipfsi 0 config --json Experimental.P2pHttpProxy true
131 +'
132 +
133 +test_expect_success 'start and connect nodes' '
134 + iptb start && iptb connect 0 1
135 +'
136 +
137 +test_expect_success 'setup p2p listener on the receiver' '
138 + ipfsi 1 p2p listen --allow-custom-protocol test /ip4/127.0.0.1/tcp/$WEB_SERVE_PORT
139 +'
140 +
141 +test_expect_success 'setup environment variables' '
142 + RECEIVER_ID="$(iptb get id 1)" &&
143 + SENDER_URL="$(sed "s|^/ip[46]/\([^/]*\)/tcp/\([0-9]*\)\$|http://\\1:\\2/proxy/http|" < "$(iptb get path 0)/api")"
144 +'
145 +
146 test_expect_success 'handle proxy http request propogates error response from remote' '
147 serve_http_once "SORRY GUYS, I LOST IT" "404 Not Found" &&
156 - setup_sender_and_receiver_ipfs &&
148 curl_send_proxy_request_and_check_response 404 "SORRY GUYS, I LOST IT"
149 '
159 -teardown_sender_and_receiver
150 teardown_remote_server
151
152 test_expect_success 'handle proxy http request sends bad-gateway when remote server not available ' '
163 - setup_sender_and_receiver_ipfs &&
153 curl_send_proxy_request_and_check_response 502 ""
154 '
166 -teardown_sender_and_receiver
155
156 test_expect_success 'handle proxy http request ' '
157 serve_http_once "THE WOODS ARE LOVELY DARK AND DEEP" &&
170 - setup_sender_and_receiver_ipfs &&
158 curl_send_proxy_request_and_check_response 200 "THE WOODS ARE LOVELY DARK AND DEEP"
159 '
173 -teardown_sender_and_receiver
160 teardown_remote_server
161
162 test_expect_success 'handle proxy http request invalid request' '
177 - setup_sender_and_receiver_ipfs &&
163 curl_check_response_code 400 DERPDERPDERP
164 '
180 -teardown_sender_and_receiver
165
166 test_expect_success 'handle proxy http request unknown proxy peer ' '
183 - setup_sender_and_receiver_ipfs &&
167 curl_check_response_code 502 unknown_peer/test/index.txt
168 '
186 -teardown_sender_and_receiver
169
170 test_expect_success 'handle multipart/form-data http request' '
171 serve_http_once "OK" &&
190 - setup_sender_and_receiver_ipfs &&
172 curl_send_multipart_form_request
173 '
193 -teardown_sender_and_receiver
174 teardown_remote_server
175
176 +test_expect_success 'stop nodes' '
177 + iptb stop
178 +'
179
180 test_done