From ba3a7d4a5556eccdd9e4cdd1e971df1f005bdf3a Mon Sep 17 00:00:00 2001 From: Peter Rabbitson Date: Sat, 14 Dec 2019 15:11:02 +0100 Subject: [PATCH 1/6] socat is not part of any default install, make tests conditional 54b1969c4b correctly switched from nc to socat, but did not account for it not being as widely available. Adjust tests that depend on it with the correct message. There are also a number of comments pertaining to nc - they were not adjusted. --- test/sharness/lib/test-lib.sh | 4 ++++ test/sharness/t0060-daemon.sh | 7 +------ test/sharness/t0061-daemon-opts.sh | 2 +- test/sharness/t0184-http-proxy-over-p2p.sh | 6 ++++++ test/sharness/t0235-cli-request.sh | 6 ++++++ test/sharness/t0236-cli-api-dns-resolve.sh | 5 +++++ test/sharness/t0301-docker-migrate.sh | 5 +++++ test/sharness/t0600-issues-and-regressions-online.sh | 2 +- 8 files changed, 29 insertions(+), 8 deletions(-) diff --git a/test/sharness/lib/test-lib.sh b/test/sharness/lib/test-lib.sh index b5c03ba48..4f3d92073 100644 --- a/test/sharness/lib/test-lib.sh +++ b/test/sharness/lib/test-lib.sh @@ -55,6 +55,10 @@ test "$TEST_EXPENSIVE" = 1 && test_set_prereq EXPENSIVE test "$TEST_NO_DOCKER" != 1 && type docker >/dev/null 2>&1 && test_set_prereq DOCKER test "$TEST_NO_PLUGIN" != 1 && test "$TEST_OS" = "LINUX" && test_set_prereq PLUGIN +# this may not be available, skip a few dependent tests +type socat >/dev/null 2>&1 && test_set_prereq SOCAT + + # Set a prereq as error messages are often different on Windows/Cygwin expr "$TEST_OS" : "CYGWIN_NT" >/dev/null || test_set_prereq STD_ERR_MSG diff --git a/test/sharness/t0060-daemon.sh b/test/sharness/t0060-daemon.sh index 67108f7cd..c51d7e6bb 100755 --- a/test/sharness/t0060-daemon.sh +++ b/test/sharness/t0060-daemon.sh @@ -124,13 +124,8 @@ test_expect_success "ipfs help output looks good" ' test_fsh cat help.txt ' -# netcat (nc) is needed for the following test -test_expect_success "socat is available" ' - type socat >/dev/null -' - # check transport is encrypted -test_expect_success "transport should be encrypted" ' +test_expect_success SOCAT "transport should be encrypted ( needs socat )" ' socat - tcp:localhost:$SWARM_PORT,connect-timeout=1 > swarmnc < ../t0060-data/mss-ls && grep -q "/secio" swarmnc && test_must_fail grep -q "/plaintext/1.0.0" swarmnc || diff --git a/test/sharness/t0061-daemon-opts.sh b/test/sharness/t0061-daemon-opts.sh index 227d4fa30..7d5cf7fe7 100755 --- a/test/sharness/t0061-daemon-opts.sh +++ b/test/sharness/t0061-daemon-opts.sh @@ -17,7 +17,7 @@ gwyaddr=$GWAY_ADDR apiaddr=$API_ADDR # Odd. this fails here, but the inverse works on t0060-daemon. -test_expect_success 'transport should be unencrypted' ' +test_expect_success SOCAT 'transport should be unencrypted ( needs socat )' ' socat - tcp:localhost:$SWARM_PORT,connect-timeout=1 > swarmnc < ../t0060-data/mss-ls && grep -q -v "/secio" swarmnc && grep -q "/plaintext" swarmnc || diff --git a/test/sharness/t0184-http-proxy-over-p2p.sh b/test/sharness/t0184-http-proxy-over-p2p.sh index d647273f0..9beda4fbc 100755 --- a/test/sharness/t0184-http-proxy-over-p2p.sh +++ b/test/sharness/t0184-http-proxy-over-p2p.sh @@ -3,6 +3,12 @@ test_description="Test http proxy over p2p" . lib/test-lib.sh + +if ! test_have_prereq SOCAT; then + skip_all="skipping '$test_description': socat is not available" + test_done +fi + WEB_SERVE_PORT=5099 IPFS_GATEWAY_PORT=5199 SENDER_GATEWAY="http://127.0.0.1:$IPFS_GATEWAY_PORT" diff --git a/test/sharness/t0235-cli-request.sh b/test/sharness/t0235-cli-request.sh index 24bccd4d5..3d50a2e62 100755 --- a/test/sharness/t0235-cli-request.sh +++ b/test/sharness/t0235-cli-request.sh @@ -8,6 +8,12 @@ test_description="test http requests made by cli" . lib/test-lib.sh +if ! test_have_prereq SOCAT; then + skip_all="skipping '$test_description': socat is not available" + test_done +fi + + test_init_ipfs test_expect_success "start nc" ' diff --git a/test/sharness/t0236-cli-api-dns-resolve.sh b/test/sharness/t0236-cli-api-dns-resolve.sh index 1beefed09..eddbc93da 100755 --- a/test/sharness/t0236-cli-api-dns-resolve.sh +++ b/test/sharness/t0236-cli-api-dns-resolve.sh @@ -8,6 +8,11 @@ test_description="test dns resolution of api endpoint by cli" . lib/test-lib.sh +if ! test_have_prereq SOCAT; then + skip_all="skipping '$test_description': socat is not available" + test_done +fi + test_init_ipfs test_expect_success "start nc" ' diff --git a/test/sharness/t0301-docker-migrate.sh b/test/sharness/t0301-docker-migrate.sh index 767769202..d5b2fda3b 100755 --- a/test/sharness/t0301-docker-migrate.sh +++ b/test/sharness/t0301-docker-migrate.sh @@ -15,6 +15,11 @@ if ! test_have_prereq DOCKER; then test_done fi +if ! test_have_prereq SOCAT; then + skip_all="skipping '$test_description': socat is not available" + test_done +fi + TEST_TRASH_DIR=$(pwd) TEST_SCRIPTS_DIR=$(dirname "$TEST_TRASH_DIR") TEST_TESTS_DIR=$(dirname "$TEST_SCRIPTS_DIR") diff --git a/test/sharness/t0600-issues-and-regressions-online.sh b/test/sharness/t0600-issues-and-regressions-online.sh index 1abf87170..8496a0f03 100755 --- a/test/sharness/t0600-issues-and-regressions-online.sh +++ b/test/sharness/t0600-issues-and-regressions-online.sh @@ -46,7 +46,7 @@ test_expect_success "pin add api looks right - #3753" ' test_cmp pinrm_out pinrm_exp ' -test_expect_success "no daemon crash on improper file argument - #4003" ' +test_expect_success SOCAT "no daemon crash on improper file argument - #4003 ( test needs socat )" ' FNC=$(echo $API_ADDR | awk -F: '\''{ printf "%s:%s", $1, $2 }'\'') && printf "POST /api/v0/add?pin=true HTTP/1.1\r\nHost: $API_ADDR\r\nContent-Type: multipart/form-data; boundary=Pyw9xQLtiLPE6XcI\r\nContent-Length: 22\r\n\r\n\r\n--Pyw9xQLtiLPE6XcI\r\n" | socat STDIO tcp-connect:$FNC | grep -m1 "500 Internal Server Error" ' From 153e52929ac37cd688ca9bab26fc9e6e429071db Mon Sep 17 00:00:00 2001 From: Peter Rabbitson Date: Sat, 14 Dec 2019 15:12:56 +0100 Subject: [PATCH 2/6] Make the docker check more specific Docker on a mac might be available, but may not be runnng. The way the original test was written is linux-specific anyway, so just hoist the check into the DOCKER declaration --- test/sharness/lib/test-lib.sh | 2 +- test/sharness/t0300-docker-image.sh | 4 ---- test/sharness/t0301-docker-migrate.sh | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/test/sharness/lib/test-lib.sh b/test/sharness/lib/test-lib.sh index 4f3d92073..659e8b98d 100644 --- a/test/sharness/lib/test-lib.sh +++ b/test/sharness/lib/test-lib.sh @@ -52,7 +52,7 @@ TEST_OS="$(uname -s | tr '[a-z]' '[A-Z]')" # grab + output options test "$TEST_NO_FUSE" != 1 && test_set_prereq FUSE test "$TEST_EXPENSIVE" = 1 && test_set_prereq EXPENSIVE -test "$TEST_NO_DOCKER" != 1 && type docker >/dev/null 2>&1 && test_set_prereq DOCKER +test "$TEST_NO_DOCKER" != 1 && type docker >/dev/null 2>&1 && groups | egrep "\bdocker\b" && test_set_prereq DOCKER test "$TEST_NO_PLUGIN" != 1 && test "$TEST_OS" = "LINUX" && test_set_prereq PLUGIN # this may not be available, skip a few dependent tests diff --git a/test/sharness/t0300-docker-image.sh b/test/sharness/t0300-docker-image.sh index 741f8885a..3d8f573f2 100755 --- a/test/sharness/t0300-docker-image.sh +++ b/test/sharness/t0300-docker-image.sh @@ -23,10 +23,6 @@ test_expect_success "'docker --version' output looks good" ' egrep "^Docker version" actual ' -test_expect_success "current user is in the 'docker' group" ' - groups | egrep "\bdocker\b" -' - TEST_TRASH_DIR=$(pwd) TEST_SCRIPTS_DIR=$(dirname "$TEST_TRASH_DIR") TEST_TESTS_DIR=$(dirname "$TEST_SCRIPTS_DIR") diff --git a/test/sharness/t0301-docker-migrate.sh b/test/sharness/t0301-docker-migrate.sh index d5b2fda3b..2ccc8bae2 100755 --- a/test/sharness/t0301-docker-migrate.sh +++ b/test/sharness/t0301-docker-migrate.sh @@ -10,7 +10,7 @@ test_description="Test docker image migration" # if in travis CI on OSX, docker is not available if ! test_have_prereq DOCKER; then - skip_all='skipping docker tests, docker not available' + skip_all='skipping '$test_description', docker not available' test_done fi From 8c6d8d5bd1dc7309e237a3023131822698ad831c Mon Sep 17 00:00:00 2001 From: Peter Rabbitson Date: Sat, 14 Dec 2019 15:14:55 +0100 Subject: [PATCH 3/6] Add GOIPFSTEST_SKIP_LOCAL_DEVTREE_DEPS_CHECK escape valve Set this to '1' if you are doing local dev and have redirects in go.mod --- test/sharness/t0010-basic-commands.sh | 3 ++- test/sharness/t0060-daemon.sh | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/sharness/t0010-basic-commands.sh b/test/sharness/t0010-basic-commands.sh index d483adfd7..b59f011f5 100755 --- a/test/sharness/t0010-basic-commands.sh +++ b/test/sharness/t0010-basic-commands.sh @@ -45,8 +45,9 @@ test_expect_success "ipfs version deps succeeds" ' ipfs version deps >deps.txt ' -test_expect_success "ipfs version deps output looks good" ' +test_expect_success "ipfs version deps output looks good ( set \$GOIPFSTEST_SKIP_LOCAL_DEVTREE_DEPS_CHECK to skip this test )" ' head -1 deps.txt | grep "go-ipfs@(devel)" && + [[ "$GOIPFSTEST_SKIP_LOCAL_DEVTREE_DEPS_CHECK" == "1" ]] || [[ $(tail -n +2 deps.txt | egrep -v -c "^[^ @]+@v[^ @]+( => [^ @]+@v[^ @]+)?$") -eq 0 ]] || test_fsh cat deps.txt ' diff --git a/test/sharness/t0060-daemon.sh b/test/sharness/t0060-daemon.sh index c51d7e6bb..7e7c658fb 100755 --- a/test/sharness/t0060-daemon.sh +++ b/test/sharness/t0060-daemon.sh @@ -108,8 +108,9 @@ test_expect_success "ipfs version deps succeeds" ' ipfs version deps >deps.txt ' -test_expect_success "ipfs version deps output looks good" ' +test_expect_success "ipfs version deps output looks good ( set \$GOIPFSTEST_SKIP_LOCAL_DEVTREE_DEPS_CHECK to skip this test )" ' head -1 deps.txt | grep "go-ipfs@(devel)" && + [[ "$GOIPFSTEST_SKIP_LOCAL_DEVTREE_DEPS_CHECK" == "1" ]] || [[ $(tail -n +2 deps.txt | egrep -v -c "^[^ @]+@v[^ @]+( => [^ @]+@v[^ @]+)?$") -eq 0 ]] || test_fsh cat deps.txt ' From 52476c026c4b641c06bab4a115f46965636e0109 Mon Sep 17 00:00:00 2001 From: Peter Rabbitson Date: Sat, 14 Dec 2019 15:24:48 +0100 Subject: [PATCH 4/6] Remove couple linux-isms: these are not valid on macos Some did actually prevent proper test shutdown --- test/sharness/t0080-repo.sh | 4 ++-- test/sharness/t0180-p2p.sh | 8 ++++---- test/sharness/t0280-plugin-git.sh | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/sharness/t0080-repo.sh b/test/sharness/t0080-repo.sh index 46254288e..3d228ea33 100755 --- a/test/sharness/t0080-repo.sh +++ b/test/sharness/t0080-repo.sh @@ -247,10 +247,10 @@ test_expect_success "'ipfs repo stat --human' succeeds" ' test_expect_success "repo stats --human came out correct" ' grep "RepoPath" repo-stats-human && - grep -P "RepoSize:\s*([0-9]*[.])?[0-9]+\s+?(B|kB|MB|GB|TB|PB|EB)" repo-stats-human && + grep -E "RepoSize:\s*([0-9]*[.])?[0-9]+\s+?(B|kB|MB|GB|TB|PB|EB)" repo-stats-human && grep "NumObjects" repo-stats-human && grep "Version" repo-stats-human && - grep -P "StorageMax:\s*([0-9]*[.])?[0-9]+\s+?(B|kB|MB|GB|TB|PB|EB)" repo-stats-human || + grep -E "StorageMax:\s*([0-9]*[.])?[0-9]+\s+?(B|kB|MB|GB|TB|PB|EB)" repo-stats-human || test_fsh cat repo-stats-human ' diff --git a/test/sharness/t0180-p2p.sh b/test/sharness/t0180-p2p.sh index 0aa9d8c42..236f2ac9f 100755 --- a/test/sharness/t0180-p2p.sh +++ b/test/sharness/t0180-p2p.sh @@ -22,10 +22,10 @@ test_expect_success 'peer ids' ' ' check_test_ports() { test_expect_success "test ports are closed" ' - (! (netstat -lnp | grep "LISTEN" | grep ":10101 ")) && - (! (netstat -lnp | grep "LISTEN" | grep ":10102 "))&& - (! (netstat -lnp | grep "LISTEN" | grep ":10103 ")) && - (! (netstat -lnp | grep "LISTEN" | grep ":10104 ")) + (! (netstat -aln | grep "LISTEN" | grep -E "[.:]10101 ")) && + (! (netstat -aln | grep "LISTEN" | grep -E "[.:]10102 ")) && + (! (netstat -aln | grep "LISTEN" | grep -E "[.:]10103 ")) && + (! (netstat -aln | grep "LISTEN" | grep -E "[.:]10104 ")) ' } check_test_ports diff --git a/test/sharness/t0280-plugin-git.sh b/test/sharness/t0280-plugin-git.sh index f5948fbb6..e7bc06427 100755 --- a/test/sharness/t0280-plugin-git.sh +++ b/test/sharness/t0280-plugin-git.sh @@ -21,7 +21,7 @@ test_dag_git() { ' test_expect_success "successfully get added objects" ' - cat hashes | xargs -i ipfs dag get -- {} > /dev/null + cat hashes | xargs -I {} ipfs dag get -- {} > /dev/null ' test_expect_success "path traversals work" ' From 4200bf453be4ade2a527108399ae2f13dc7ac903 Mon Sep 17 00:00:00 2001 From: Peter Rabbitson Date: Sat, 14 Dec 2019 15:27:30 +0100 Subject: [PATCH 5/6] At some point the directory name changed to testbeds Without reflecting this in the tests we do not actually shut down correctly during cleanup --- test/sharness/t0121-bootstrap-iptb.sh | 10 +++++----- test/sharness/t0130-multinode.sh | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/sharness/t0121-bootstrap-iptb.sh b/test/sharness/t0121-bootstrap-iptb.sh index 8de23a216..16dcbdb2f 100755 --- a/test/sharness/t0121-bootstrap-iptb.sh +++ b/test/sharness/t0121-bootstrap-iptb.sh @@ -38,11 +38,11 @@ betterwait() { } test_expect_success "bring down iptb nodes" ' - PID0=$(cat "$IPTB_ROOT/benches/default/0/daemon.pid") && - PID1=$(cat "$IPTB_ROOT/benches/default/1/daemon.pid") && - PID2=$(cat "$IPTB_ROOT/benches/default/2/daemon.pid") && - PID3=$(cat "$IPTB_ROOT/benches/default/3/daemon.pid") && - PID4=$(cat "$IPTB_ROOT/benches/default/4/daemon.pid") && + PID0=$(cat "$IPTB_ROOT/testbeds/default/0/daemon.pid") && + PID1=$(cat "$IPTB_ROOT/testbeds/default/1/daemon.pid") && + PID2=$(cat "$IPTB_ROOT/testbeds/default/2/daemon.pid") && + PID3=$(cat "$IPTB_ROOT/testbeds/default/3/daemon.pid") && + PID4=$(cat "$IPTB_ROOT/testbeds/default/4/daemon.pid") && iptb stop && # TODO: add --wait flag to iptb stop betterwait $PID0 betterwait $PID1 diff --git a/test/sharness/t0130-multinode.sh b/test/sharness/t0130-multinode.sh index 1c732db7a..e0a27b666 100755 --- a/test/sharness/t0130-multinode.sh +++ b/test/sharness/t0130-multinode.sh @@ -80,7 +80,7 @@ run_advanced_test() { test_expect_success "shut down nodes" ' iptb stop && iptb_wait_stop || - test_fsh tail -n +1 .iptb/benches/default/*/daemon.std* + test_fsh tail -n +1 .iptb/testbeds/default/*/daemon.std* ' } From 36dcf8eac5fd867ccc7044c5660fe1d8660442c9 Mon Sep 17 00:00:00 2001 From: Peter Rabbitson Date: Sat, 14 Dec 2019 18:58:41 +0100 Subject: [PATCH 6/6] Add two more missed cleanup clauses --- test/sharness/t0095-refs.sh | 2 ++ test/sharness/t0181-private-network.sh | 2 ++ 2 files changed, 4 insertions(+) diff --git a/test/sharness/t0095-refs.sh b/test/sharness/t0095-refs.sh index d363d043f..99dc361c7 100755 --- a/test/sharness/t0095-refs.sh +++ b/test/sharness/t0095-refs.sh @@ -182,4 +182,6 @@ test_refs_output '' 'cat' test_refs_output '--cid-base=base32' 'ipfs cid base32' +test_kill_ipfs_daemon + test_done diff --git a/test/sharness/t0181-private-network.sh b/test/sharness/t0181-private-network.sh index d2230aa1b..dfb4be203 100755 --- a/test/sharness/t0181-private-network.sh +++ b/test/sharness/t0181-private-network.sh @@ -132,4 +132,6 @@ test_expect_success "stop testbed" ' iptb stop ' +test_kill_ipfs_daemon + test_done