From 3418ee5435efca8d770ab07faf66d471dfb76d8d Mon Sep 17 00:00:00 2001 From: jmjatlanta Date: Wed, 27 Sep 2017 07:40:55 -0500 Subject: [PATCH] more test scripts --- test/scripts/test_2.sh | 14 ++++--------- test/scripts/test_3.sh | 39 ++++++++++++++++++++++++++++++++++++ test/scripts/test_helpers.sh | 23 +++++++++++++++++++++ 3 files changed, 66 insertions(+), 10 deletions(-) create mode 100755 test/scripts/test_3.sh diff --git a/test/scripts/test_2.sh b/test/scripts/test_2.sh index a1d4e6b..cdd4033 100755 --- a/test/scripts/test_2.sh +++ b/test/scripts/test_2.sh @@ -4,17 +4,8 @@ source ./test_helpers.sh IPFS="../../main/ipfs --config /tmp/ipfs_1" -function check_failure() { - FUNC=$1; - RESULT=$2; - if [ $RESULT -eq 0 ]; then - echo ""; - else - echo "Failure in $FUNC. The return value was $RESULT"; - fi -} - function pre { + post eval "$IPFS" init; check_failure "pre" $? } @@ -27,7 +18,10 @@ function post { function body { create_hello_world; eval "$IPFS" add hello.txt + check_failure "add hello.txt" $? + eval "$IPFS" cat QmYAXgX8ARiriupMQsbGXtKdDyGzWry1YV3sycKw1qqmgH + check_failure "cat hello.txt" $? } diff --git a/test/scripts/test_3.sh b/test/scripts/test_3.sh new file mode 100755 index 0000000..283ea48 --- /dev/null +++ b/test/scripts/test_3.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +#### +# Attempt to start a deamon and have an api client do a object get +# +#### + +source ./test_helpers.sh + +IPFS="../../main/ipfs --config /tmp/ipfs_1" + +function pre { + post + eval "$IPFS" init; + check_failure "pre" $? +} + +function post { + rm -Rf /tmp/ipfs_1; + rm hello.txt; +} + +function body { + create_hello_world; + eval "$IPFS" add hello.txt + check_failure "add hello.txt" $? + + #start the daemon + eval "../../main/ipfs --config /tmp/ipfs_1 daemon &" + daemon_id=$! + sleep 5 + + eval "$IPFS" cat QmYAXgX8ARiriupMQsbGXtKdDyGzWry1YV3sycKw1qqmgH + check_failure "cat hello.txt" $? + + kill -9 $daemon_id +} + + diff --git a/test/scripts/test_helpers.sh b/test/scripts/test_helpers.sh index 51ed721..1fc699f 100644 --- a/test/scripts/test_helpers.sh +++ b/test/scripts/test_helpers.sh @@ -1,3 +1,26 @@ +#!/bin/bash + +##### +# Functions to help with test scripts +##### + +#### +# Create a text file "hello.txt" that contains "Hello, World!" +#### function create_hello_world { echo 'Hello, World!' > hello.txt } + +#### +# Checks the return code and displays message if return code is not 0 +# Param $1 name of function +# Param $2 return code +#### +function check_failure() { + FUNC=$1; + RESULT=$2; + if [ $RESULT -ne 0 ]; then + echo "***Failure*** in $FUNC. The return value was $RESULT"; + fi +} +