Skip to content

Commit

Permalink
sharness: try handling nc requests a different way...
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
  • Loading branch information
Stebalien committed Nov 30, 2018
1 parent 84c5af3 commit d39d20b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 35 deletions.
37 changes: 18 additions & 19 deletions test/sharness/t0235-cli-request.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,30 @@ test_description="test http requests made by cli"
test_init_ipfs

test_expect_success "start nc" '
rm -f nc_out nc_status nc_in && mkfifo nc_in nc_status
nc -v -l 127.0.0.1 5005 < nc_in > nc_out 2>nc_status &
rm -f nc_outp nc_inp nc_statusp && mkfifo nc_inp nc_outp nc_statusp
nc -v -l 127.0.0.1 5005 <nc_inp >nc_outp 2>nc_statusp &
NCPID=$!
exec 6>nc_inp 7<nc_outp
# Needed to "prime" nc
echo -n "" > nc_in &&
# Wait for it to start
head -1 nc_status
head -1 <nc_statusp
'

test_expect_success "can make http request against nc server" '
cat >nc_in <<EOF
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 1
.
EOF
head -1 nc_status & # consume "connected message"
ipfs cat /ipfs/Qmabcdef --api /ip4/127.0.0.1/tcp/5005
'
ipfs cat /ipfs/Qmabcdef --api /ip4/127.0.0.1/tcp/5005 &
IPFSPID=$!
head -1 <nc_statusp
# handle request
echo "HTTP/1.1 200 OK" >&6 &&
echo "Content-Type: text/plain" >&6 &&
echo "Content-Length: 0" >&6 &&
echo "" >&6 &&
sed -n "0,/^$/p" <&7 > nc_out &&
exec 6<&- # Keep connection open till *after* we have the full request.
test_expect_success "wait for nc to exit" '
wait $NCPID
# Wait for IPFS and netcat
wait $IPFSPID $NCPID
'

test_expect_success "output does not contain multipart info" '
Expand Down
36 changes: 20 additions & 16 deletions test/sharness/t0236-cli-api-dns-resolve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,35 @@ test_description="test dns resolution of api endpoint by cli"
test_init_ipfs

test_expect_success "start nc" '
rm -f nc_out nc_status nc_in && mkfifo nc_in nc_status
nc -v -l 127.0.0.1 5006 < nc_in > nc_out 2>nc_status &
rm -f nc_outp nc_inp nc_statusp && mkfifo nc_inp nc_outp nc_statusp
nc -v -l 127.0.0.1 5005 <nc_inp >nc_outp 2>nc_statusp &
NCPID=$!
exec 6>nc_inp 7<nc_outp
# Needed to "prime" nc
echo -n "" > nc_in &&
# Wait for it to start
head -1 nc_status
head -1 <nc_statusp
'

test_expect_success "can make http request against dns resolved nc server" '
cat >nc_in <<EOF
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 1
.
EOF
head -1 nc_status & # consume "connected message"
ipfs cat /ipfs/Qmabcdef --api /dns4/localhost/tcp/5006
ipfs cat /ipfs/Qmabcdef --api /dns4/localhost/tcp/5006 &
IPFSPID=$!
head -1 <nc_statusp
# handle request
echo "HTTP/1.1 200 OK" >&6 &&
echo "Content-Type: text/plain" >&6 &&
echo "Content-Length: 0" >&6 &&
echo "" >&6 &&
sed -n "0,/^$/p" <&7 > nc_out &&
exec 6<&- # Keep connection open till *after* we have the full request.
# Wait for IPFS and netcat
wait $IPFSPID $NCPID
'

test_expect_success "wait for nc to exit" '
wait $NCPID
cat nc_out
'

test_expect_success "request was received by local nc server" '
Expand Down

0 comments on commit d39d20b

Please sign in to comment.