#!/bin/bash # Runs a test with the assumption that it will return a zero result code run_test() { set +e "$@" > "$TEST_OUT" 2>&1 RESULT=$? cat "$TEST_OUT" set -e return "$RESULT" } # Runs a test with the assumption that it will return a non-zero result code run_fail_test() { if "$@" > "$TEST_OUT" 2>&1 ; then cat "$TEST_OUT" return 1 fi cat "$TEST_OUT" return 0 } # This resets the spacetime config for a new test run reset_config() { SPACETIME_CONFIG_FILE="$(mktemp)" export SPACETIME_CONFIG_FILE cp "$RESET_SPACETIME_CONFIG" "$SPACETIME_CONFIG_FILE" } # This deletes the project from the previous test run reset_project() { PROJECT_PATH="$(mktemp -d)" rmdir "$PROJECT_PATH" cp -rp "$RESET_PROJECT_PATH" "$PROJECT_PATH" export PROJECT_PATH } # This cleans up the temporary project directory after a test clear_project() { rm -rf "$PROJECT_PATH" } # This cleans up the temporary config file after a test clear_config() { rm -f "$SPACETIME_CONFIG_FILE" } random_string() { if [[ "$OSTYPE" == "darwin"* ]]; then echo $RANDOM | md5 -q | head -c 20 else echo $RANDOM | md5sum | head -c 20 fi } spacetime_publish() { RETURN_DIR=$PWD cd "$SPACETIME_DIR" set +e run_test spacetime publish "$@" RESULT_CODE=$? cd "$RETURN_DIR" || exit 1 set -e return "$RESULT_CODE" } fsed() { if [[ "$OSTYPE" == "darwin"* ]]; then sed -i.sed_bak "$@" rm -f rm *.sed_bak else sed -i "$@" fi } restart_docker() { docker-compose stop node docker-compose start node sleep 10 } # vim: noexpandtab tabstop=4 shiftwidth=4