test_anastasis_reducer_initialize_state.sh (1569B)
1 #!/bin/bash 2 # This file is in the public domain. 3 4 set -eu 5 6 # Exit, with status code "skip" (no 'real' failure) 7 function exit_skip() { 8 echo " SKIP: $1" 9 exit 77 10 } 11 12 # Exit, with error message (hard failure) 13 function exit_fail() { 14 echo " FAIL: $1" 15 exit 1 16 } 17 18 # Cleanup to run whenever we exit 19 function cleanup() 20 { 21 for n in `jobs -p` 22 do 23 kill $n 2> /dev/null || true 24 done 25 rm -f $SFILE $TFILE 26 wait 27 } 28 29 # Install cleanup handler (except for kill -9) 30 SFILE=`mktemp test_reducer_stateXXXXXX` 31 TFILE=`mktemp test_reducer_stateXXXXXX` 32 33 trap cleanup EXIT 34 35 # Check we can actually run 36 echo -n "Testing for jq ..." 37 jq -h > /dev/null || exit_skip "jq required" 38 echo " FOUND" 39 echo -n "Testing for anastasis-reducer ..." 40 anastasis-reducer -h > /dev/null || exit_skip "anastasis-reducer required" 41 echo " FOUND" 42 echo -n "Test initialization of a backup state ..." 43 anastasis-reducer -b $SFILE 44 45 STATE=`jq -r -e .backup_state < $SFILE` 46 if test "$STATE" != "CONTINENT_SELECTING" 47 then 48 exit_fail "Expected initial state to be CONTINENT_SELECTING, got $STATE" 49 fi 50 jq -e .continents[0] < $SFILE > /dev/null || exit_fail "Expected initial state to include continents" 51 52 echo " OK" 53 54 echo -n "Test initialization of a recovery state ..." 55 anastasis-reducer -r $TFILE 56 57 STATE=`jq -r -e .recovery_state < $TFILE` 58 if test "$STATE" != "CONTINENT_SELECTING" 59 then 60 exit_fail "Expected initial state to be CONTINENT_SELECTING, got $STATE" 61 fi 62 jq -e .continents[0] < $TFILE > /dev/null || exit_fail "Expected initial state to include continents" 63 echo " OK" 64 65 exit 0