forked from manuelmauro/algonaut
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-harness.sh
executable file
·123 lines (105 loc) · 3.78 KB
/
test-harness.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env bash
set -euo pipefail
# test-harness.sh setup/start cucumber test environment.
#
# Configuration is managed with environment variables, the ones you
# are most likely to reconfigured are stored in 'test.env'.
#
# Variables:
# SDK_TESTING_URL - URL to algorand-sdk-testing, useful for forks.
# SDK_TESTING_BRANCH - branch to checkout, useful for new tests.
# SDK_TESTING_HARNESS - local directory that the algorand-sdk-testing repo is cloned into.
# VERBOSE_HARNESS - more output while the script runs.
# INSTALL_ONLY - installs feature files only, useful for unit tests.
#
# WARNING: If set to 1, new features will be LOST when downloading the test harness.
# REGARDLESS: modified features are ALWAYS overwritten.
# REMOVE_LOCAL_FEATURES - delete all local cucumber feature files before downloading these from github.
#
# WARNING: Be careful when turning on the next variable.
# In that case you'll need to provide all variables expected by `algorand-sdk-testing`'s `.env`
# OVERWRITE_TESTING_ENVIRONMENT=0
SHUTDOWN=0
if [ $# -ne 0 ]; then
if [ $# -ne 1 ]; then
echo "this script accepts a single argument, which must be 'up' or 'down'."
exit 1
fi
case $1 in
'up')
;; # default.
'down')
SHUTDOWN=1
;;
*)
echo "unknown parameter '$1'."
echo "this script accepts a single argument, which must be 'up' or 'down'."
exit 1
;;
esac
fi
START=$(date "+%s")
THIS=$(basename "$0")
ENV_FILE="test.env"
TEST_DIR="tests"
set -a
source "$ENV_FILE"
set +a
rootdir=$(dirname "$0")
pushd "$rootdir"
echo "$THIS: VERBOSE_HARNESS=$VERBOSE_HARNESS"
## Reset test harness
if [ -d "$SDK_TESTING_HARNESS" ]; then
pushd "$SDK_TESTING_HARNESS"
./scripts/down.sh
popd
rm -rf "$SDK_TESTING_HARNESS"
if [[ $SHUTDOWN == 1 ]]; then
echo "$THIS: network shutdown complete."
exit 0
fi
else
echo "$THIS: directory $SDK_TESTING_HARNESS does not exist - NOOP"
fi
if [[ $SHUTDOWN == 1 ]]; then
echo "$THIS: unable to shutdown network."
exit 1
fi
git clone --depth 1 --single-branch --branch "$SDK_TESTING_BRANCH" "$SDK_TESTING_URL" "$SDK_TESTING_HARNESS"
echo "$THIS: OVERWRITE_TESTING_ENVIRONMENT=$OVERWRITE_TESTING_ENVIRONMENT"
if [[ $OVERWRITE_TESTING_ENVIRONMENT == 1 ]]; then
echo "$THIS: OVERWRITE replaced $SDK_TESTING_HARNESS/.env with $ENV_FILE:"
cp "$ENV_FILE" "$SDK_TESTING_HARNESS"/.env
fi
echo "$THIS: REMOVE_LOCAL_FEATURES=$REMOVE_LOCAL_FEATURES"
## Copy feature files into the project resources
if [[ $REMOVE_LOCAL_FEATURES == 1 ]]; then
echo "$THIS: OVERWRITE wipes clean $TEST_DIR/features"
if [[ $VERBOSE_HARNESS == 1 ]]; then
( tree $TEST_DIR/features && echo "$THIS: see the previous for files deleted" ) || true
fi
rm -rf $TEST_DIR/features
fi
mkdir -p $TEST_DIR/features
cp -r "$SDK_TESTING_HARNESS"/features/* $TEST_DIR/features
if [[ $VERBOSE_HARNESS == 1 ]]; then
( tree $TEST_DIR/features && echo "$THIS: see the previous for files copied over" ) || true
fi
echo "$THIS: seconds it took to get to end of cloning and copying: $(($(date "+%s") - START))s"
if [[ $INSTALL_ONLY == 1 ]]; then
echo "$THIS: configured to install feature files only. Not starting test harness environment."
exit 0
fi
## Start test harness environment
pushd "$SDK_TESTING_HARNESS"
[[ "$VERBOSE_HARNESS" = 1 ]] && V_FLAG="-v" || V_FLAG=""
echo "$THIS: standing up harnness with command [./up.sh $V_FLAG]"
./scripts/up.sh "$V_FLAG"
popd
echo "$THIS: seconds it took to finish testing sdk's up.sh: $(($(date "+%s") - START))s"
echo ""
echo "--------------------------------------------------------------------------------"
echo "|"
echo "| To run sandbox commands, cd into $SDK_TESTING_HARNESS/.sandbox "
echo "|"
echo "--------------------------------------------------------------------------------"