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 $TEST_CONF &> /dev/null || return 1 if [ ! -f "$TEST_CONF" ]; then echo "Failed to pull config" return 1 fi $CLIENTBIN $TEST_BIN pull $TEST_CONF_DIR &> /dev/null || return 1 if [ ! -d "$TEST_CONF_DIR" ]; then echo "Failed to pull config dir" return 1 fi return 0 } # Test pulling of simple config by version pull_config_by_version() { echo "opt1=true" > $TEST_CONF $CLIENTBIN $TEST_BIN push $TEST_CONF &> /dev/null || return 1 rm $TEST_CONF $CLIENTBIN $TEST_BIN pull $TEST_CONF -v 1 &> /dev/null || return 1 if [ ! -f $TEST_CONF ]; then echo "Ver1 Failed to pull config" return 1 elif [ 0 = "$(grep -Fxq "false" $TEST_CONF; echo $?)" ]; then echo "File contents not consistent with v1" return 1 fi rm $TEST_CONF $CLIENTBIN $TEST_BIN pull $TEST_CONF -v 2 &> /dev/null || return 1 if [ ! -f $TEST_CONF ]; then echo "Ver2 Failed to pull config" return 1 elif [ 0 = "$(grep -Fxq "true" $TEST_CONF; echo $?)" ]; then echo "File contents not consistent with v2" return 1 fi return 0 } # Test pulling of simple config by version pull_config_by_tag() { echo "opt1=true" > $TEST_CONF $CLIENTBIN $TEST_BIN push $TEST_CONF -t "true" &> /dev/null || return 1 rm $TEST_CONF echo "opt1=false" > $TEST_CONF $CLIENTBIN $TEST_BIN push $TEST_CONF -t "false" &> /dev/null || return 1 rm $TEST_CONF $CLIENTBIN $TEST_BIN pull $TEST_CONF -t "true" &> /dev/null || return 1 if [ ! -f $TEST_CONF ]; then echo "Tag1 Failed to pull config" return 1 elif [ 0 = "$(grep -Fxq "true" $TEST_CONF; echo $?)" ]; then echo "File contents not consistent with tag true" return 1 fi rm $TEST_CONF $CLIENTBIN $TEST_BIN pull $TEST_CONF -t "false" &> /dev/null || return 1 if [ ! -f $TEST_CONF ]; then echo "Tag2 Failed to pull config" return 1 elif [ 0 = "$(grep -Fxq "false" $TEST_CONF; echo $?)" ]; then echo "File contents not consistent with tag false" return 1 fi return 0 } # 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