NUM_ERRS=0 if [ -z "$CLIENTBIN" ]; then echo "Meld client is not set" exit 1 fi TEST_BIN=/tmp/meld_bin TEST_CONF=/tmp/meld_test.conf TEST_CONF_DIR=/tmp/meld_test_dir # Cleanup Functionality to reset state cleanup() { rm -rf "$TEST_BIN" 2> /dev/null rm "$TEST_CONF" 2> /dev/null rm -rf "$TEST_CONF_DIR" 2> /dev/null } setup() { $CLIENTBIN $TEST_BIN init --force &> /dev/null || return 1 echo "opt1=false" > $TEST_CONF mkdir $TEST_CONF_DIR cp $TEST_CONF $TEST_CONF_DIR $CLIENTBIN $TEST_BIN push $TEST_CONF &> /dev/null || return 1 $CLIENTBIN $TEST_BIN push $TEST_CONF_DIR &> /dev/null || return 1 rm $TEST_CONF rm -rf $TEST_CONF_DIR return 0 } # Test pulling of simple config pull_config() { $CLIENTBIN $TEST_BIN pull BADCONF &> /dev/null && return 0 if [ -f "$TEST_CONF" ]; then echo "This conf should not exist" >&2 return 1 fi return 1 } # Test pulling of simple config by version pull_config_by_version() { $CLIENTBIN $TEST_BIN pull $TEST_CONF -v 1337 &> /dev/null && return 0 if [ -f $TEST_CONF ]; then echo "A config with this version should not exist" >&2 return 1 fi return 1 } # Test pulling of simple config by version pull_config_by_tag() { $CLIENTBIN $TEST_BIN pull $TEST_CONF -t "BAD TAG" &> /dev/null && return 0 if [ -f $TEST_CONF ]; then echo "A config with this tag should not exist" >&2 return 1 fi return 1 } # Test Setup cleanup setup || exit 1 # Tested Functions pull_config || NUM_ERRS=$(( NUM_ERRS + $? )) pull_config_by_version || NUM_ERRS=$(( NUM_ERRS + $? )) pull_config_by_tag || NUM_ERRS=$(( NUM_ERRS + $? )) #Test Teardown cleanup if [ $NUM_ERRS -eq 0 ]; then echo "[+] SUCCESS" else echo "[-] FAILURE" >&2 fi exit $NUM_ERRS