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