diff --git a/AdvAir.sh b/AdvAir.sh index a0692472..fb79a6c5 100755 --- a/AdvAir.sh +++ b/AdvAir.sh @@ -45,8 +45,10 @@ zoneSpecified=false fanSpecified=false argSTART=4 logErrors=true +debugSpecified=false noSensors=true fanSpeed=false +sameAsCached=false fspeed="low" # By default selfTest is off @@ -69,7 +71,8 @@ lightSpecified=false thingSpecified=false #Temporary files - the subdirectory full path will be defined later -tmpSubDir="/tmp" +if [ -z "${TMPDIR}" ]; then TMPDIR="/tmp"; fi +tmpSubDir="${TMPDIR}" QUERY_AIRCON_LOG_FILE="queryCachedAirCon_calls.log" QUERY_IDBYNAME_LOG_FILE="queryIdByName.log" MY_AIRDATA_FILE="myAirData.txt" @@ -118,6 +121,36 @@ function logError() } > "$fileName" } +function logQueryAirConDiagnostic() +{ + if [ "$debugSpecified" != true ]; then + return + fi + local str="$1" + echo "$str" >> "$QUERY_AIRCON_LOG_FILE" + + # Delete the log if it is > 15 MB + fSize=$(find "$QUERY_AIRCON_LOG_FILE" -ls | awk '{print $7}') + if [ "$fSize" -gt 15728640 ];then + rm "$QUERY_AIRCON_LOG_FILE" + fi +} + +function logQueryIdByNameDiagnostic() +{ + if [ "$debugSpecified" != true ]; then + return + fi + local str="$1" + echo "$str" >> "$QUERY_IDBYNAME_LOG_FILE" + + # Delete the log if it is > 15 MB + fSize=$(find "$QUERY_IDBYNAME_LOG_FILE" -ls | awk '{print $7}') + if [ "$fSize" -gt 15728640 ];then + rm "$QUERY_IDBYNAME_LOG_FILE" + fi +} + function getFileStatDt() { local fileName="$1" @@ -147,15 +180,12 @@ function queryCachedAirCon() local forceFetch="$3" local iteration="$4" local queryType + local myAirData_cached="{}" local lockFile="${MY_AIRDATA_FILE}.lock" local dateFile="${MY_AIRDATA_FILE}.date" - local tempFile="${MY_AIRDATA_FILE}.temp" t0=$(date '+%s') - t1=$((t0 + RANDOM)) - - local tempFile1="${tempFile}_$t1" # The dateFile is only valid if there is an MY_AIRDATA_FILE local useFileCache=false @@ -174,14 +204,13 @@ function queryCachedAirCon() dtlf=$(( t0 - tlf )) if [ "$dtlf" -ge 60 ]; then # earlier curl has timed out, recover and try again rm "$lockFile" - rm -f "${tempFile}_"* rc=99 - echo "queryCachedAirCon_calls_earlier_CMD4_timed_out $tf $t0 $dt $useFileCache rc=$rc itr=$iteration $io $device $characteristic $url" >> "$QUERY_AIRCON_LOG_FILE" + logQueryAirConDiagnostic "queryCachedAirCon_calls_earlier_CMD4_timed_out $tf $t0 $dt $useFileCache rc=$rc itr=$iteration $io $device $characteristic $url" return fi fi fi - echo "queryCachedAirCon_calls $tf $t0 $dt $useFileCache itr=$iteration $io $device $characteristic $url" >> "$QUERY_AIRCON_LOG_FILE" + logQueryAirConDiagnostic "queryCachedAirCon_calls $tf $t0 $dt $useFileCache itr=$iteration $io $device $characteristic $url" if [ "$forceFetch" = true ] || [ "$useFileCache" = false ]; then doFetch=true @@ -202,7 +231,7 @@ function queryCachedAirCon() # earlier CMD4 has timed out (CMD4 timeout:60000) - this rarely happen (<0.1% of the time) # flag it and copy the existing cached file and move on. May not have enough time to retry rc=98 - echo "queryCachedAirCon_copy_earlier_CMD4_timed_out $t0 $t2 $dt $useFileCache rc=$rc itr=$iteration $io $device $characteristic $url" >> "$QUERY_AIRCON_LOG_FILE" + logQueryAirConDiagnostic "queryCachedAirCon_copy_earlier_CMD4_timed_out $t0 $t2 $dt $useFileCache rc=$rc itr=$iteration $io $device $characteristic $url" # To test the logic, issue this comment if [ "$selfTest" = "TEST_ON" ]; then @@ -213,7 +242,7 @@ function queryCachedAirCon() done myAirData=$( cat "$MY_AIRDATA_FILE" ) rc=$? - echo "queryCachedAirCon_copy $t0 $t2 $dt $useFileCache rc=$rc itr=$iteration $io $device $characteristic $url" >> "$QUERY_AIRCON_LOG_FILE" + logQueryAirConDiagnostic "queryCachedAirCon_copy $t0 $t2 $dt $useFileCache rc=$rc itr=$iteration $io $device $characteristic $url" # To test the logic, issue this comment if [ "$selfTest" = "TEST_ON" ]; then @@ -223,29 +252,27 @@ function queryCachedAirCon() elif [ "$doFetch" = true ]; then echo "$t0" > "$lockFile" queryType="curl" - #Need to output the curl result to a file directly to ensure a compact json file - curl -o "$tempFile1" -s -g "$url" + myAirData=$( curl -s -g "$url") rc=$? if [ "$rc" = "0" ]; then - myAirData=$(cat "$tempFile1") #Need to parse to ensure the json file is not empty parseMyAirDataWithJq ".aircons.$ac.info" if [ "$rc" = "0" ]; then t2=$(date '+%s') echo "$t2" > "$dateFile" # overwrite $dateFile - mv "$tempFile1" "$MY_AIRDATA_FILE" # overwrite $MY_AIRDATA_FILE + #if $myAirData is not the same as the cached file, overwrite it with the new $myAirData + if [ -f "$MY_AIRDATA_FILE" ]; then isMyAirDataSameAsCached; fi + if [ $sameAsCached = false ]; then echo "$myAirData" > "$MY_AIRDATA_FILE"; fi dt=$((t2 - t0)) # time-taken for curl command to complete - echo "queryCachedAirCon_curl $t0 $t2 $dt $useFileCache rc=$rc itr=$iteration $io $device $characteristic $url" >> "$QUERY_AIRCON_LOG_FILE" + logQueryAirConDiagnostic "queryCachedAirCon_curl $t0 $t2 $dt $useFileCache rc=$rc itr=$iteration $io $device $characteristic $url" else # just in case unset myAirData - rm "$tempFile1" fi else - echo "queryCachedAirCon_curl_failed $t0 $t2 $dt $useFileCache rc=$rc itr=$iteration $io $device $characteristic $url" >> "$QUERY_AIRCON_LOG_FILE" + logQueryAirConDiagnostic "queryCachedAirCon_curl_failed $t0 $t2 $dt $useFileCache rc=$rc itr=$iteration $io $device $characteristic $url" fi rm "$lockFile" - rm -f "$tempFile1" elif [ "$doFetch" = false ]; then queryType="cache" @@ -253,12 +280,6 @@ function queryCachedAirCon() rc=$? fi - # Delete the log if it is > 15 MB - fSize=$(find "$QUERY_AIRCON_LOG_FILE" -ls | awk '{print $7}') - if [ "$fSize" -gt 15728640 ];then - rm "$QUERY_AIRCON_LOG_FILE" - fi - if [ "$rc" != "0" ]; then if [ "$exitOnFail" = "1" ]; then logError "getValue_${queryType} failed" "$rc" "" "" "$url" @@ -267,6 +288,36 @@ function queryCachedAirCon() fi } +function isMyAirDataSameAsCached() +{ + local aircons + local lights + local things + local myAirData_cached + local aircons_cached + local lights_cached + local things_cached + + myAirData_cached=$(cat "$MY_AIRDATA_FILE") + + if [ "$myAirData" = "$myAirData_cached" ]; then + sameAsCached=true + return + fi + # For aircon system with temperature sensors, "rssi" and "measuredTemp" are changing all the time + # do not need to compare "rssi" but if "measuredTemp" is changed, cached file will be updated + # compare only the aircons, lights and things - all the rest does not matter + aircons=$(echo "$myAirData"|jq -ec ".aircons[]"|sed s/rssi\":[0-9]*/rssi\":0/g) + lights=$(echo "$myAirData"|jq -ec ".myLights.lights[]") + things=$(echo "$myAirData"|jq -ec ".myThings.things[]") + + aircons_cached=$(echo "$myAirData_cached"|jq -ec ".aircons[]"|sed s/rssi\":[0-9]*/rssi\":0/g) + lights_cached=$(echo "$myAirData_cached"|jq -ec ".myLights.lights[]") + things_cached=$(echo "$myAirData_cached"|jq -ec ".myThings.things[]") + + if [[ "$aircons" = "$aircons_cached" && "$lights" = "$lights_cached" && "$things" = "$things_cached" ]]; then sameAsCached=true; fi +} + function setAirConUsingIteration() { local url="$1" @@ -293,7 +344,7 @@ function setAirConUsingIteration() t3=$(date '+%s') curl --fail -s -g "$url" rc=$? - echo "setAirCon_curl $t3 rc=$rc itr=$i $io $device $characteristic $value $url" >> "$QUERY_AIRCON_LOG_FILE" + logQueryAirConDiagnostic "setAirCon_curl $t3 rc=$rc itr=$i $io $device $characteristic $value $url" if [ "$rc" == "0" ]; then # update $MY_AIRDATA_FILE directly instead of fetching a new copy from AdvantageAir controller after a set command @@ -375,25 +426,21 @@ function updateMyAirDataCachedFileWithJq() local url="$1" local jqPath="$2" - - t4=$(($(date '+%s') + RANDOM)) - local tempFile2="${MY_AIRDATA_FILE}.temp_$t4" + local updatedMyAirData # - jq -ec "$jqPath" "$MY_AIRDATA_FILE" > "$tempFile2" + updatedMyAirData=$(jq -ec "$jqPath" "$MY_AIRDATA_FILE") rc=$? if [ "$rc" == "0" ]; then - mv "$tempFile2" "$MY_AIRDATA_FILE" - echo "setAirCon_setJson $t3 rc=$rc $io $device $characteristic $jqPath" >> "$QUERY_AIRCON_LOG_FILE" + echo "$updatedMyAirData" > "$MY_AIRDATA_FILE" + logQueryAirConDiagnostic "setAirCon_setJson $t3 rc=$rc $io $device $characteristic $jqPath" if [ "$selfTest" = "TEST_ON" ]; then # For Testing, you can compare whats sent echo "Setting json: $jqPath" fi else logError "setAirCon_setJson jq failed" "$rc" "$jqPath" "" "$url" - echo "setAirCon_setJson_failed $t3 rc=$rc $io $device $characteristic $jqPath" >> "$QUERY_AIRCON_LOG_FILE" + logQueryAirConDiagnostic "setAirCon_setJson_failed $t3 rc=$rc $io $device $characteristic $jqPath" fi - # just in case - rm -f "$tempFile2" } function parseMyAirDataWithJq() @@ -411,7 +458,7 @@ function parseMyAirDataWithJq() if [ "$rc" != "0" ]; then if [ "$exitOnFail" = "1" ]; then logError "jq failed" "$rc" "$jqResult" "" "$jqPath" - echo "parseMyAirDataWithJq_failed rc=$rc jqResult=$jqResult $io $device $characteristic $jqPath" >> "$QUERY_AIRCON_LOG_FILE" + logQueryAirConDiagnostic "parseMyAirDataWithJq_failed rc=$rc jqResult=$jqResult $io $device $characteristic $jqPath" exit $rc fi fi @@ -523,16 +570,11 @@ function queryIdByName() # for diagnostic purpuses t4=$(date '+%s') - echo "queryIdByName_jq $t4 rc=$rc $io path=$path $characteristic id=${ids} name=$name" >> "$QUERY_IDBYNAME_LOG_FILE" - # Delete the log if it is > 15 MB - fSize=$(find "$QUERY_IDBYNAME_LOG_FILE" -ls | awk '{print $7}') - if [ "$fSize" -gt 15728640 ];then - rm "$QUERY_IDBYNAME_LOG_FILE" - fi + logQueryIdByNameDiagnostic "queryIdByName_jq $t4 rc=$rc $io path=$path $characteristic id=${ids} name=$name" if [ "$rc" != "0" ]; then logError "queryIdByName_jq failed" "$rc" "${ids}" "${path}" "$name" - echo "queryIdByName_jq_failed $t4 rc=$rc $io path=$path $characteristic id=${ids} name=$name" >> "$QUERY_IDBYNAME_LOG_FILE" + logQueryIdByNameDiagnostic "queryIdByName_jq_failed $t4 rc=$rc $io path=$path $characteristic id=${ids} name=$name" exit $rc fi @@ -664,10 +706,16 @@ if [ $argEND -ge $argSTART ]; then # # See if the option is in the format of an IP # - if expr "$v" : '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$' >/dev/null; then - IP="$v" + if expr "$v" : '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*[-a-z]*$' >/dev/null; then + IP=$(echo "$v"|cut -d"-" -f1) + debug=$(echo "$v"|cut -d"-" -f2) + if [ "$debug" = "debug" ]; then debugSpecified=true; fi + if [ "$selfTest" = "TEST_ON" ]; then - echo "Using IP: $v" + echo "Using IP: $IP" + if [ "$debugSpecified" = true ]; then + echo "Diagnostic log is turned on" + fi fi optionUnderstood=true fi @@ -681,7 +729,7 @@ fi # Create a temporary sub-directory "${tmpSubDir}" to store the temporary files subDir=$( echo "$IP"|cut -d"." -f4 ) -tmpSubDir=$( printf "/tmp/AA-%03d" "$subDir" ) +tmpSubDir=$( printf "${TMPDIR}/AA-%03d" "$subDir" ) if [ ! -d "${tmpSubDir}/" ]; then mkdir "${tmpSubDir}/"; fi # Redefine temporary files with full path diff --git a/test/AirConServer.bats b/test/AirConServer.bats index e0afcccf..13479b60 100644 --- a/test/AirConServer.bats +++ b/test/AirConServer.bats @@ -10,25 +10,25 @@ teardown() } before() { - rm -f "/tmp/AA-001/AirConServer.out"* + rm -f "${TMPDIR}/AA-001/AirConServer.out"* } eraseAirConServerDataFile() { - rm -f "/tmp/AA-001/AirConServerData.json"* + rm -f "${TMPDIR}/AA-001/AirConServerData.json"* } beforeEach() { - rm -f "/tmp/AA-001/myAirData.txt"* - rm -f "/tmp/AA-001/myAirConstants.txt"* - if [ ! -d "/tmp/AA-001" ]; then mkdir "/tmp/AA-001"; fi + _common_beforeEach + rm -f "${TMPDIR}/AA-001/myAirData.txt"* + rm -f "${TMPDIR}/AA-001/myAirConstants.txt"* } @test "StartServer Test /reInit" { beforeEach # Issue the reInit - run curl -s -g "http://localhost:2025/reInit" + run curl -s -g "http://localhost:$PORT/reInit" assert_equal "$status" 0 assert_equal "${#lines[@]}" 0 } @@ -36,7 +36,7 @@ beforeEach() @test "StartServer Test ?load" { beforeEach echo "Doing curl" - run curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + run curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" assert_equal "$status" 0 assert_equal "${#lines[@]}" 0 echo "done StartServer testCASE" @@ -45,11 +45,11 @@ beforeEach() @test "StartServer Test /getSystemData fails appropriately when nothing is loaded" { beforeEach # Issue the reInit - run curl -s -g "http://localhost:2025/reInit" + run curl -s -g "http://localhost:$PORT/reInit" assert_equal "$status" 0 assert_equal "${#lines[@]}" 0 # Get the systemData after the reInit - run curl -s -g "http://localhost:2025/getSystemData" + run curl -s -g "http://localhost:$PORT/getSystemData" assert_equal "$status" 0 assert_equal "${lines[0]}" "404 No File Loaded" } @@ -57,7 +57,7 @@ beforeEach() @test "StartServer Test ?failureCount fails appropriately" { beforeEach # run an old, now illegal command - run curl -s -g "http://localhost:2025?failureCount=4" + run curl -s -g "http://localhost:$PORT?failureCount=4" assert_equal "$status" 0 assert_equal "${lines[0]}" "SERVER: UNKNOWN query: failureCount" echo "done failureCount testCASE" @@ -66,11 +66,11 @@ beforeEach() @test "StartServer Test /dumpstack, no entries" { beforeEach # clear the stack - run curl -s -g "http://localhost:2025/reInit" + run curl -s -g "http://localhost:$PORT/reInit" assert_equal "$status" 0 assert_equal "${#lines[@]}" 0 # dump the stack - run curl -s -g "http://localhost:2025/dumpStack" + run curl -s -g "http://localhost:$PORT/dumpStack" assert_equal "$status" 0 assert_equal "${#lines[@]}" 0 } @@ -78,15 +78,15 @@ beforeEach() @test "StartServer Test /dumpstack, 1 entry, no repeat" { beforeEach # clear the stack - run curl -s -g "http://localhost:2025/reInit" + run curl -s -g "http://localhost:$PORT/reInit" assert_equal "$status" 0 assert_equal "${#lines[@]}" 0 # load stack with 1 entry no repeats - run curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + run curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" assert_equal "$status" 0 assert_equal "${#lines[@]}" 0 # dump the stack - run curl -s -g "http://localhost:2025/dumpStack" + run curl -s -g "http://localhost:$PORT/dumpStack" assert_equal "$status" 0 assert_equal "${#lines[@]}" 1 assert_equal "${lines[0]}" "repeat: 0 filename: testData/basicPassingSystemData.txt" @@ -95,15 +95,15 @@ beforeEach() @test "StartServer Test /dumpstack, 1 entry, repeat=5" { beforeEach # clear the stack - run curl -s -g "http://localhost:2025/reInit" + run curl -s -g "http://localhost:$PORT/reInit" assert_equal "$status" 0 assert_equal "${#lines[@]}" 0 # load stack repeat of 5 - run curl -s -g "http://localhost:2025?repeat=5&load=testData/basicPassingSystemData.txt" + run curl -s -g "http://localhost:$PORT?repeat=5&load=testData/basicPassingSystemData.txt" assert_equal "$status" 0 assert_equal "${#lines[@]}" 0 # dump the stack - run curl -s -g "http://localhost:2025/dumpStack" + run curl -s -g "http://localhost:$PORT/dumpStack" assert_equal "$status" 0 assert_equal "${#lines[@]}" 1 assert_equal "${lines[0]}" "repeat: 5 filename: testData/basicPassingSystemData.txt" @@ -112,19 +112,19 @@ beforeEach() @test "StartServer Test /dumpstack, 2 entry, repeat=3 & 5" { beforeEach # clear the stack - run curl -s -g "http://localhost:2025/reInit" + run curl -s -g "http://localhost:$PORT/reInit" assert_equal "$status" 0 assert_equal "${#lines[@]}" 0 # load stack repeat of 3 - run curl -s -g "http://localhost:2025?repeat=3&load=testData/basicPassingSystemData.txt" + run curl -s -g "http://localhost:$PORT?repeat=3&load=testData/basicPassingSystemData.txt" assert_equal "$status" 0 assert_equal "${#lines[@]}" 0 # load stack repeat of 3 - run curl -s -g "http://localhost:2025?repeat=5&load=testData/failedAirConRetrieveSystemData.txt" + run curl -s -g "http://localhost:$PORT?repeat=5&load=testData/failedAirConRetrieveSystemData.txt" assert_equal "$status" 0 assert_equal "${#lines[@]}" 0 # dump the stack - run curl -s -g "http://localhost:2025/dumpStack" + run curl -s -g "http://localhost:$PORT/dumpStack" assert_equal "$status" 0 assert_equal "${#lines[@]}" 2 assert_equal "${lines[0]}" "repeat: 3 filename: testData/basicPassingSystemData.txt" @@ -134,33 +134,33 @@ beforeEach() @test "StartServer Test /getSystemData, 1 entry, more requests than repeat, dumping stack" { beforeEach # clear the stack - run curl -s -g "http://localhost:2025/reInit" + run curl -s -g "http://localhost:$PORT/reInit" assert_equal "$status" 0 assert_equal "${#lines[@]}" 0 # load stack repeat of 3 - run curl -s -g "http://localhost:2025?repeat=2&load=testData/basicPassingSystemData.txt" + run curl -s -g "http://localhost:$PORT?repeat=2&load=testData/basicPassingSystemData.txt" assert_equal "$status" 0 assert_equal "${#lines[@]}" 0 # getSystemData 1 - run curl -s -g "http://localhost:2025/getSystemData" + run curl -s -g "http://localhost:$PORT/getSystemData" assert_equal "$status" 0 assert_equal "${#lines[@]}" 368 r1=${#lines[@]} assert_equal "${#r1}" 3 # getSystemData 2 - run curl -s -g "http://localhost:2025/getSystemData" + run curl -s -g "http://localhost:$PORT/getSystemData" assert_equal "$status" 0 assert_equal "${#lines[@]}" 368 r2=${#lines[@]} assert_equal "$r1" "$r2" # getSystemData 3 - run curl -s -g "http://localhost:2025/getSystemData" + run curl -s -g "http://localhost:$PORT/getSystemData" assert_equal "$status" 0 assert_equal "${#lines[@]}" 368 r3=${#lines[@]} assert_equal "$r1" "$r3" # dump the stack - run curl -s -g "http://localhost:2025/dumpStack" + run curl -s -g "http://localhost:$PORT/dumpStack" assert_equal "$status" 0 assert_equal "${#lines[@]}" 1 assert_equal "${lines[0]}" "repeat: -1 filename: testData/basicPassingSystemData.txt" @@ -169,64 +169,64 @@ beforeEach() @test "StartServer Test /getSystemData, 2 entry repeat=1 & 2, more requests than repeat, dumping stack" { beforeEach # clear the stack - run curl -s -g "http://localhost:2025/reInit" + run curl -s -g "http://localhost:$PORT/reInit" assert_equal "$status" 0 assert_equal "${#lines[@]}" 0 # load stack repeat of 1 - run curl -s -g "http://localhost:2025?repeat=1&load=testData/basicPassingSystemData.txt" + run curl -s -g "http://localhost:$PORT?repeat=1&load=testData/basicPassingSystemData.txt" assert_equal "$status" 0 assert_equal "${#lines[@]}" 0 # load stack repeat of 2 Different data - run curl -s -g "http://localhost:2025?repeat=2&load=testData/failedAirConRetrieveSystemData.txt" + run curl -s -g "http://localhost:$PORT?repeat=2&load=testData/failedAirConRetrieveSystemData.txt" assert_equal "$status" 0 assert_equal "${#lines[@]}" 0 # dump the stack - run curl -s -g "http://localhost:2025/dumpStack" + run curl -s -g "http://localhost:$PORT/dumpStack" assert_equal "$status" 0 assert_equal "${#lines[@]}" 2 assert_equal "${lines[0]}" "repeat: 1 filename: testData/basicPassingSystemData.txt" assert_equal "${lines[1]}" "repeat: 2 filename: testData/failedAirConRetrieveSystemData.txt" # getSystemData 1 - run curl -s -g "http://localhost:2025/getSystemData" + run curl -s -g "http://localhost:$PORT/getSystemData" assert_equal "$status" 0 assert_equal "${#lines[@]}" 368 r1=${#lines[@]} assert_equal "${r1}" 368 # dump the stack - run curl -s -g "http://localhost:2025/dumpStack" + run curl -s -g "http://localhost:$PORT/dumpStack" assert_equal "$status" 0 assert_equal "${#lines[@]}" 1 assert_equal "${lines[0]}" "repeat: 2 filename: testData/failedAirConRetrieveSystemData.txt" # getSystemData 2 (Should be new data ) - run curl -s -g "http://localhost:2025/getSystemData" + run curl -s -g "http://localhost:$PORT/getSystemData" assert_equal "$status" 0 assert_equal "${#lines[@]}" 237 r2=${#lines[@]} assert_equal "${r2}" 237 # dump the stack - run curl -s -g "http://localhost:2025/dumpStack" + run curl -s -g "http://localhost:$PORT/dumpStack" assert_equal "$status" 0 assert_equal "${#lines[@]}" 1 assert_equal "${lines[0]}" "repeat: 1 filename: testData/failedAirConRetrieveSystemData.txt" # getSystemData 3 - run curl -s -g "http://localhost:2025/getSystemData" + run curl -s -g "http://localhost:$PORT/getSystemData" assert_equal "$status" 0 assert_equal "${#lines[@]}" 237 r3=${#lines[@]} assert_equal "${r3}" 237 # dump the stack - run curl -s -g "http://localhost:2025/dumpStack" + run curl -s -g "http://localhost:$PORT/dumpStack" assert_equal "$status" 0 assert_equal "${#lines[@]}" 1 assert_equal "${lines[0]}" "repeat: 0 filename: testData/failedAirConRetrieveSystemData.txt" # getSystemData 4 - run curl -s -g "http://localhost:2025/getSystemData" + run curl -s -g "http://localhost:$PORT/getSystemData" assert_equal "$status" 0 assert_equal "${#lines[@]}" 237 r4=${#lines[@]} assert_equal "$r3" "$r4" # dump the stack - run curl -s -g "http://localhost:2025/dumpStack" + run curl -s -g "http://localhost:$PORT/dumpStack" assert_equal "$status" 0 assert_equal "${#lines[@]}" 1 assert_equal "${lines[0]}" "repeat: -1 filename: testData/failedAirConRetrieveSystemData.txt" @@ -236,20 +236,20 @@ beforeEach() beforeEach eraseAirConServerDataFile # clear the stack - run curl -s -g "http://localhost:2025/reInit" + run curl -s -g "http://localhost:$PORT/reInit" assert_equal "$status" 0 assert_equal "${#lines[@]}" 0 # load stack repeat of 1 - run curl -s -g "http://localhost:2025?repeat=1&load=testData/basicPassingSystemData.txt" + run curl -s -g "http://localhost:$PORT?repeat=1&load=testData/basicPassingSystemData.txt" assert_equal "$status" 0 assert_equal "${#lines[@]}" 0 # setAircon state = open - run curl -s -g "http://localhost:2025?save" + run curl -s -g "http://localhost:$PORT?save" assert_equal "$status" 0 # assert_equal "${#lines[@]}" 1 # getSystemData - The size should still be the same - # Save creates the /tmp/AA-001/AirConSererData.json file - run diff testData/basicPassingSystemData.txt /tmp/AA-001/AirConServerData.json + # Save creates the ${TMPDIR}/AA-001/AirConSererData.json file + run diff testData/basicPassingSystemData.txt "${TMPDIR}"/AA-001/AirConServerData.json assert_equal "$status" 0 #assert_equal "${#lines[@]}" 1 } @@ -257,42 +257,42 @@ beforeEach() @test "StartServer Test Load/Set/Read new data" { beforeEach # clear the stack - run curl -s -g "http://localhost:2025/reInit" + run curl -s -g "http://localhost:$PORT/reInit" assert_equal "$status" 0 assert_equal "${#lines[@]}" 0 # load stack repeat of 1 - run curl -s -g "http://localhost:2025?repeat=1&load=testData/basicPassingSystemData.txt" + run curl -s -g "http://localhost:$PORT?repeat=1&load=testData/basicPassingSystemData.txt" assert_equal "$status" 0 assert_equal "${#lines[@]}" 0 # AdvAir.sh TargetTemperature 9 # ".aircons.$ac.info.setTemp" - run curl -s -g "http://localhost:2025/setAircon?json={ac1:{info:{setTemp:9}}}" + run curl -s -g "http://localhost:$PORT/setAircon?json={ac1:{info:{setTemp:9}}}" assert_equal "$status" 0 assert_equal "${#lines[@]}" 0 # getSystemData # Check the Temp change - run curl -s -g "http://localhost:2025/getSystemData" -o /tmp/AA-001/out + run curl -s -g "http://localhost:$PORT/getSystemData" -o "${TMPDIR}"/AA-001/out assert_equal "$status" 0 assert_equal "${#lines[@]}" 0 - jqResult=$( jq -e ".aircons.ac1.info.setTemp" < /tmp/AA-001/out ) + jqResult=$( jq -e ".aircons.ac1.info.setTemp" < "${TMPDIR}"/AA-001/out ) echo "jqResult=$jqResult" assert_equal "$jqResult" "9" # setAircon Temp = 22 - run curl -s -g "http://localhost:2025/setAircon?json={ac1:{info:{setTemp:22}}}" + run curl -s -g "http://localhost:$PORT/setAircon?json={ac1:{info:{setTemp:22}}}" assert_equal "$status" 0 # Check the Temp change - run $( curl -s -g "http://localhost:2025/getSystemData" -o /tmp/AA-001/out ) + run $( curl -s -g "http://localhost:$PORT/getSystemData" -o "${TMPDIR}"/AA-001/out ) assert_equal "$status" 0 - jqResult=$( jq -e ".aircons.ac1.info.setTemp" < /tmp/AA-001/out ) + jqResult=$( jq -e ".aircons.ac1.info.setTemp" < "${TMPDIR}"/AA-001/out ) assert_equal "$jqResult" "22" } @test "StartServer Test Load/Set/Read new data using AdvAir.sh" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" run ../AdvAir.sh Set Blah TargetHeatingCoolingState 1 127.0.0.1 TEST_ON assert_equal "$status" 0 # AdvAir.sh does a get first diff --git a/test/AirConServer.js b/test/AirConServer.js index 5f288dc9..1941385c 100644 --- a/test/AirConServer.js +++ b/test/AirConServer.js @@ -6,8 +6,9 @@ var url = require('url'); const { Command } = require( "commander" ); const program = new Command; -// Setting up PORT +// Setting up PORT and TMPDIR var port_g = process.env.PORT || 2025; +var TMPDIR = process.env.TMPDIR || "/tmp" var debug_g = true; var exists_fan = true; @@ -128,7 +129,7 @@ const requestListener = function (req, res) // Example URL parsing - // var adr = 'http://localhost:2025/default.htm?year=2017&month=february'; + // var adr = 'http://localhost:$PORT/default.htm?year=2017&month=february'; var q = url.parse(req.url, true); let ended = true; @@ -148,14 +149,14 @@ const requestListener = function (req, res) // The last record is used continiously. // // Examples - // curl -s -g 'http://localhost:2025?load=testData/dataPassOn1/getSystemData.txt0' - // curl -s -g 'http://localhost:2025?repeat=5?load=testData/dataPassOn1/getSystemData.txt0' - // curl -s -g 'http://localhost:2025/getDystemData' - // curl -s -g 'http://localhost:2025/shutdown' - // curl -s -g 'http://localhost:2025/quit' - // curl -s -g 'http://localhost:2025/reInit' - // curl -s -g 'http://localhost:2025?debug=1' - // curl -s -g 'http://localhost:2025?dumpStack' + // curl -s -g 'http://localhost:$PORT?load=testData/dataPassOn1/getSystemData.txt0' + // curl -s -g 'http://localhost:$PORT?repeat=5?load=testData/dataPassOn1/getSystemData.txt0' + // curl -s -g 'http://localhost:$PORT/getDystemData' + // curl -s -g 'http://localhost:$PORT/shutdown' + // curl -s -g 'http://localhost:$PORT/quit' + // curl -s -g 'http://localhost:$PORT/reInit' + // curl -s -g 'http://localhost:$PORT?debug=1' + // curl -s -g 'http://localhost:$PORT?dumpStack' // // Note: "repeat" must come first, otherwise 0 is used. // @@ -321,7 +322,7 @@ const requestListener = function (req, res) return res.end(); } let record = stack_g[0]; - fs.writeFileSync( "/tmp/AA-001/AirConServerData.json", record.getSystemData); + fs.writeFileSync( `${TMPDIR}/AA-001/AirConServerData.json`, record.getSystemData); log( `SERVER: end\n` ); return res.end(); @@ -761,8 +762,8 @@ async function startServer( port, handler, callback ) // node ./AirConServer.js // In Second Terminal // cd test -// curl -s -g 'http://localhost:2025/?load=testData/dataPassOn1/getSystemData.txt0' -// curl -s -g 'http://localhost:2025/?loadFail=testData/dataFailOn5/getSystemData.txt4?loadFailureCound=4' +// curl -s -g 'http://localhost:$PORT/?load=testData/dataPassOn1/getSystemData.txt0' +// curl -s -g 'http://localhost:$PORT/?loadFail=testData/dataFailOn5/getSystemData.txt4?loadFailureCound=4' // ../AdvAir.sh Get Blah Brightness z01 127.0.0.1 TEST_ON // diff --git a/test/BigAirConSystem.bats b/test/BigAirConSystem.bats index e6e05fc8..c3f6d553 100644 --- a/test/BigAirConSystem.bats +++ b/test/BigAirConSystem.bats @@ -10,14 +10,14 @@ teardown() } before() { - rm -f "/tmp/AA-001/AirConServer.out" + rm -f "${TMPDIR}/AA-001/AirConServer.out" } beforeEach() { - rm -f "/tmp/AA-001/myAirData.txt"* - rm -f "/tmp/AA-001/myAirConstants.txt"* - if [ ! -d "/tmp/AA-001" ]; then mkdir "/tmp/AA-001"; fi + _common_beforeEach + rm -f "${TMPDIR}/AA-001/myAirData.txt"* + rm -f "${TMPDIR}/AA-001/myAirConstants.txt"* } bigSystem1() @@ -32,15 +32,15 @@ bigSystem1() # and the earlier "curl" completed within 6 seconds t0=$(date '+%s') - t1=$((t0 - $curlRunTime + 6)) + t1=$((t0 - curlRunTime + 6)) t2=$((t0 - 122)) # $MY_AIRDTA_FILE = 122 seconds old - echo "$t1" > "/tmp/AA-001/myAirData.txt.lock" - echo "$t2" > "/tmp/AA-001/myAirData.txt.date" - cp "testData/basicPassingSystemData.txt" "/tmp/AA-001/myAirData.txt" + echo "$t1" > "${TMPDIR}/AA-001/myAirData.txt.lock" + echo "$t2" > "${TMPDIR}/AA-001/myAirData.txt.date" + cp "testData/basicPassingSystemData.txt" "${TMPDIR}/AA-001/myAirData.txt" sleep 6 - rm -f "/tmp/AA-001/myAirData.txt.lock" + rm -f "${TMPDIR}/AA-001/myAirData.txt.lock" } bigSystem2() @@ -55,12 +55,12 @@ bigSystem2() # and the earlier "curl" has taken more than 60 seconds and CMD4 timed out t0=$(date '+%s') - t1=$((t0 - $curlRunTime )) + t1=$((t0 - curlRunTime )) t2=$((t0 - 122)) # $MY_AIRDTA_FILE = 122 seconds old - echo "$t1" > "/tmp/AA-001/myAirData.txt.lock" - echo "$t2" > "/tmp/AA-001/myAirData.txt.date" - cp "testData/basicPassingSystemData.txt" "/tmp/AA-001/myAirData.txt" + echo "$t1" > "${TMPDIR}/AA-001/myAirData.txt.lock" + echo "$t2" > "${TMPDIR}/AA-001/myAirData.txt.date" + cp "testData/basicPassingSystemData.txt" "${TMPDIR}/AA-001/myAirData.txt" } bigSystem3() @@ -75,23 +75,21 @@ bigSystem3() # and the earlier "curl" has taken more than 60 seconds and CMD4 timed out t0=$(date '+%s') - t1=$((t0 - $curlRunTime)) + t1=$((t0 - curlRunTime)) t2=$((t0 - 185)) # $MY_AIRDTA_FILE > 180 seconds old - t3=$((t0 + RANDOM)) - echo "$t1" > "/tmp/AA-001/myAirData.txt.lock" - echo "$t2" > "/tmp/AA-001/myAirData.txt.date" - cp "testData/basicPassingSystemData.txt" "/tmp/AA-001/myAirData.txt" - cp "/tmp/AA-001/myAirData.txt" "/tmp/AA-001/myAirData.txt.temp_$t3" + echo "$t1" > "${TMPDIR}/AA-001/myAirData.txt.lock" + echo "$t2" > "${TMPDIR}/AA-001/myAirData.txt.date" + cp "testData/basicPassingSystemData.txt" "${TMPDIR}/AA-001/myAirData.txt" } # test for the situation where the $lockFile is detected and erlier curl completed within 6 seconds @test "AdvAir Test Big AirCon System 1 - \$MY_AIRDATA_FILE =122s old and \$lockFile detected and earlier getSystemData completed within 6 seconds " { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" bigSystem1 & run ../AdvAir.sh Get Fan On TEST_ON 127.0.0.1 assert_equal "$status" 0 @@ -112,9 +110,9 @@ bigSystem3() @test "AdvAir Test Big AirCon System 2 - \$MY_AIRDATA_FILE =122s old and \$lockFile detected and earlier getSystemData timed out" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" bigSystem2 & run ../AdvAir.sh Get Fan On TEST_ON 127.0.0.1 assert_equal "$status" 0 @@ -138,9 +136,9 @@ bigSystem3() @test "AdvAir Test Big AirCon System 3 - \$MY_AIRDATA_FILE >180s old and \$lockFile detected and earlier getSystemData timed out, recover and retry" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" bigSystem3 & run ../AdvAir.sh Get Fan On TEST_ON 127.0.0.1 assert_equal "$status" 0 diff --git a/test/GetAc2CurrentTemperature.bats b/test/GetAc2CurrentTemperature.bats index 077a1b99..fa7e1737 100644 --- a/test/GetAc2CurrentTemperature.bats +++ b/test/GetAc2CurrentTemperature.bats @@ -10,22 +10,22 @@ teardown() } before() { - rm -f "/tmp/AA-001/AirConServer.out" + rm -f "${TMPDIR}/AA-001/AirConServer.out" } beforeEach() { - rm -f "/tmp/AA-001/myAirData.txt"* - rm -f "/tmp/AA-001/myAirConstants.txt"* - if [ ! -d "/tmp/AA-001" ]; then mkdir "/tmp/AA-001"; fi + _common_beforeEach + rm -f "${TMPDIR}/AA-001/myAirData.txt"* + rm -f "${TMPDIR}/AA-001/myAirConstants.txt"* } @test "AdvAir Test Get CurrentTemperature - ac2" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemDataAc2.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemDataAc2.txt" # Bats "run" gobbles up all the stdout. Remove for debugging run ../AdvAir.sh Get Blah CurrentTemperature TEST_ON 127.0.0.1 z01 ac2 assert_equal "$status" 0 @@ -44,9 +44,9 @@ beforeEach() @test "AdvAir Test Get CurrentTemperature z01 - ac2" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemDataAc2.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemDataAc2.txt" # Bats "run" gobbles up all the stdout. Remove for debugging run ../AdvAir.sh Get Blah CurrentTemperature TEST_ON 127.0.0.1 z01 ac2 assert_equal "$status" 0 @@ -65,9 +65,9 @@ beforeEach() @test "AdvAir Test Get CurrentTemperature z03 - ac2" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemDataAc2.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemDataAc2.txt" # Bats "run" gobbles up all the stdout. Remove for debugging run ../AdvAir.sh Get Blah CurrentTemperature TEST_ON 127.0.0.1 z03 ac2 assert_equal "$status" "0" @@ -83,14 +83,14 @@ beforeEach() assert_equal "${#lines[@]}" 8 } -@test "AdvAir Test Get CurrentTemperature with NoSensor Data (creating new myAirConstants - ac2" { +@test "AdvAir Test Get CurrentTemperature with NoSensor Data (creating new myAirConstants - ac2)" { # The old scripts return 0 because it does not realize noSensors before beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/oneZonePassingSystemDataAc2.txt" + curl -s -g "http://localhost:$PORT?load=testData/oneZonePassingSystemDataAc2.txt" # Bats "run" gobbles up all the stdout. Remove for debugging run ../AdvAir.sh Get Blah CurrentTemperature TEST_ON 127.0.0.1 ac2 assert_equal "$status" "0" @@ -112,12 +112,12 @@ beforeEach() assert_equal "${#lines[@]}" 13 } -@test "AdvAir Test Get CurrentTemperature with NoSensor Data (with cached myAirConstants - ac2" { +@test "AdvAir Test Get CurrentTemperature with NoSensor Data (with cached myAirConstants - ac2)" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/oneZonePassingSystemDataAc2.txt" + curl -s -g "http://localhost:$PORT?load=testData/oneZonePassingSystemDataAc2.txt" # Bats "run" gobbles up all the stdout. Remove for debugging run ../AdvAir.sh Get Blah CurrentTemperature TEST_ON 127.0.0.1 ac2 assert_equal "$status" 0 diff --git a/test/GetAirConConstants.bats b/test/GetAirConConstants.bats index 9eb409da..8c8b6776 100644 --- a/test/GetAirConConstants.bats +++ b/test/GetAirConConstants.bats @@ -10,22 +10,22 @@ teardown() } before() { - rm -f "/tmp/AA-001/AirConServer.out" + rm -f "${TMPDIR}/AA-001/AirConServer.out" } beforeEach() { - rm -f "/tmp/AA-001/myAirData.txt"* - rm -f "/tmp/AA-001/myAirConstants.txt"* - if [ ! -d "/tmp/AA-001" ]; then mkdir "/tmp/AA-001"; fi + _common_beforeEach + rm -f "${TMPDIR}/AA-001/myAirData.txt"* + rm -f "${TMPDIR}/AA-001/myAirConstants.txt"* } @test "AdvAir Test Get CurrentTemperature MyAirConstants" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" # Bats "run" gobbles up all the stdout. Remove for debugging run ../AdvAir.sh Get Blah CurrentTemperature TEST_ON 127.0.0.1 z01 assert_equal "$status" 0 @@ -46,9 +46,9 @@ beforeEach() before beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/oneZonePassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/oneZonePassingSystemData.txt" # Bats "run" gobbles up all the stdout. Remove for debugging run ../AdvAir.sh Get Blah CurrentTemperature TEST_ON 127.0.0.1 assert_equal "$status" "0" @@ -68,7 +68,7 @@ beforeEach() assert_equal "${lines[12]}" "21" # No more lines than expected assert_equal "${#lines[@]}" 13 - myAirConstants=$( cat "/tmp/AA-001/myAirConstants.txt.ac1" ) + myAirConstants=$( cat "${TMPDIR}/AA-001/myAirConstants.txt.ac1" ) noSensors=$( echo "$myAirConstants" | awk '{print $1}' ) cZone=$( echo "$myAirConstants" | awk '{print $2}' ) nZones=$( echo "$myAirConstants" | awk '{print $3}' ) @@ -82,9 +82,9 @@ beforeEach() @test "AdvAir Test Read Cached MyAirConstants with NoSensor Data" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/oneZonePassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/oneZonePassingSystemData.txt" # Bats "run" gobbles up all the stdout. Remove for debugging run ../AdvAir.sh Get Blah CurrentTemperature TEST_ON 127.0.0.1 assert_equal "$status" 0 @@ -112,7 +112,7 @@ beforeEach() assert_equal "${lines[3]}" "21" # No more lines than expected assert_equal "${#lines[@]}" 4 - myAirConstants=$( cat "/tmp/AA-001/myAirConstants.txt.ac1" ) + myAirConstants=$( cat "${TMPDIR}/AA-001/myAirConstants.txt.ac1" ) noSensors=$( echo "$myAirConstants" | awk '{print $1}' ) cZone=$( echo "$myAirConstants" | awk '{print $2}' ) nZones=$( echo "$myAirConstants" | awk '{print $3}' ) @@ -127,9 +127,9 @@ beforeEach() before beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" # Bats "run" gobbles up all the stdout. Remove for debugging run ../AdvAir.sh Get Blah CurrentTemperature TEST_ON 127.0.0.1 assert_equal "$status" "0" @@ -144,7 +144,7 @@ beforeEach() assert_equal "${lines[7]}" "25.4" # No more lines than expected assert_equal "${#lines[@]}" 8 - myAirConstants=$( cat "/tmp/AA-001/myAirConstants.txt.ac1" ) + myAirConstants=$( cat "${TMPDIR}/AA-001/myAirConstants.txt.ac1" ) noSensors=$( echo "$myAirConstants" | awk '{print $1}' ) cZone=$( echo "$myAirConstants" | awk '{print $2}' ) nZones=$( echo "$myAirConstants" | awk '{print $3}' ) @@ -158,9 +158,9 @@ beforeEach() @test "AdvAir Test Read Cached MyAirConstants with Sensor Data" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" # Bats "run" gobbles up all the stdout. Remove for debugging run ../AdvAir.sh Get Blah CurrentTemperature TEST_ON 127.0.0.1 assert_equal "$status" 0 @@ -183,7 +183,7 @@ beforeEach() assert_equal "${lines[3]}" "25.4" # No more lines than expected assert_equal "${#lines[@]}" 4 - myAirConstants=$( cat "/tmp/AA-001/myAirConstants.txt.ac1" ) + myAirConstants=$( cat "${TMPDIR}/AA-001/myAirConstants.txt.ac1" ) noSensors=$( echo "$myAirConstants" | awk '{print $1}' ) cZone=$( echo "$myAirConstants" | awk '{print $2}' ) nZones=$( echo "$myAirConstants" | awk '{print $3}' ) diff --git a/test/GetBrightness.bats b/test/GetBrightness.bats index 533522fa..70dbe354 100644 --- a/test/GetBrightness.bats +++ b/test/GetBrightness.bats @@ -22,23 +22,23 @@ teardown() } before() { - rm -f "/tmp/AA-001/AirConServer.out" + rm -f "${TMPDIR}/AA-001/AirConServer.out" } beforeEach() { - rm -f "/tmp/AA-001/myAirData.txt"* - rm -f "/tmp/AA-001/myAirConstants.txt"* - if [ ! -d "/tmp/AA-001" ]; then mkdir "/tmp/AA-001"; fi + _common_beforeEach + rm -f "${TMPDIR}/AA-001/myAirData.txt"* + rm -f "${TMPDIR}/AA-001/myAirConstants.txt"* } @test "AdvAir Test Get Brightness z01" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" run ../AdvAir.sh Get Blah Brightness z01 127.0.0.1 TEST_ON assert_equal "$status" 0 assert_equal "${lines[0]}" "Try 0" @@ -55,9 +55,9 @@ beforeEach() @test "AdvAir Test Get Brightness z03" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" run ../AdvAir.sh Get Blah Brightness z03 127.0.0.1 TEST_ON assert_equal "$status" 0 assert_equal "${lines[0]}" "Try 0" @@ -74,9 +74,9 @@ beforeEach() @test "AdvAir Test Get Brightness light:Study Patio" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/myPlaceFull.txt" + curl -s -g "http://localhost:$PORT?load=testData/myPlaceFull.txt" # TimerEnabled requires On to be set to 0 run ../AdvAir.sh Get Blab Brightness 'light:Study Patio' 127.0.0.1 ac2 TEST_ON # AdvAir.sh does a get first diff --git a/test/GetCurrentDoorState.bats b/test/GetCurrentDoorState.bats index 6c27b7a6..c59b53c0 100644 --- a/test/GetCurrentDoorState.bats +++ b/test/GetCurrentDoorState.bats @@ -10,14 +10,14 @@ teardown() } before() { - rm "/tmp/AA-001/AirConServer.out" + rm "${TMPDIR}/AA-001/AirConServer.out" } beforeEach() { - rm -f "/tmp/AA-001/myAirData.txt"* - rm -f "/tmp/AA-001/myAirConstants.txt"* - if [ ! -d "/tmp/AA-001" ]; then mkdir "/tmp/AA-001"; fi + _common_beforeEach + rm -f "${TMPDIR}/AA-001/myAirData.txt"* + rm -f "${TMPDIR}/AA-001/myAirConstants.txt"* } # Typical GarageDoorConfig for currentDoorState @@ -33,9 +33,9 @@ beforeEach() @test "AdvAir Test Get CurrentDoorState" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/myPlace.txt" + curl -s -g "http://localhost:$PORT?load=testData/myPlace.txt" run ../AdvAir.sh Get Blah CurrentDoorState 'thing:Garage' 127.0.0.1 TEST_ON assert_equal "$status" 0 assert_equal "${lines[0]}" "Try 0" @@ -53,9 +53,9 @@ beforeEach() @test "AdvAir Test Get CurrentDoorState - flip enabled" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/myPlace.txt" + curl -s -g "http://localhost:$PORT?load=testData/myPlace.txt" run ../AdvAir.sh Get Blah CurrentDoorState 'thing:Garage' flip 127.0.0.1 TEST_ON assert_equal "$status" 0 assert_equal "${lines[0]}" "Try 0" diff --git a/test/GetCurrentHeatingCoolingState.bats b/test/GetCurrentHeatingCoolingState.bats index c2fc3052..f1d60637 100644 --- a/test/GetCurrentHeatingCoolingState.bats +++ b/test/GetCurrentHeatingCoolingState.bats @@ -10,22 +10,22 @@ teardown() } before() { - rm -f "/tmp/AA-001/AirConServer.out" + rm -f "${TMPDIR}/AA-001/AirConServer.out" } beforeEach() { - rm -f "/tmp/AA-001/myAirData.txt"* - rm -f "/tmp/AA-001/myAirConstants.txt"* - if [ ! -d "/tmp/AA-001" ]; then mkdir "/tmp/AA-001"; fi + _common_beforeEach + rm -f "${TMPDIR}/AA-001/myAirData.txt"* + rm -f "${TMPDIR}/AA-001/myAirConstants.txt"* } @test "AdvAir Test Get CurrentHeatingCoolingState" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" # Bats "run" gobbles up all the stdout. Remove for debugging run ../AdvAir.sh Get Blah CurrentHeatingCoolingState 127.0.0.1 TEST_ON assert_equal "$status" 0 diff --git a/test/GetCurrentTemperature.bats b/test/GetCurrentTemperature.bats index 1c0ad8cd..c2760bc5 100644 --- a/test/GetCurrentTemperature.bats +++ b/test/GetCurrentTemperature.bats @@ -10,22 +10,22 @@ teardown() } before() { - rm -f "/tmp/AA-001/AirConServer.out" + rm -f "${TMPDIR}/AA-001/AirConServer.out" } beforeEach() { - rm -f "/tmp/AA-001/myAirData.txt"* - rm -f "/tmp/AA-001/myAirConstants.txt"* - if [ ! -d "/tmp/AA-001" ]; then mkdir "/tmp/AA-001"; fi + _common_beforeEach + rm -f "${TMPDIR}/AA-001/myAirData.txt"* + rm -f "${TMPDIR}/AA-001/myAirConstants.txt"* } @test "AdvAir Test Get CurrentTemperature" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" # Bats "run" gobbles up all the stdout. Remove for debugging run ../AdvAir.sh Get Blah CurrentTemperature TEST_ON 127.0.0.1 z01 assert_equal "$status" 0 @@ -44,9 +44,9 @@ beforeEach() @test "AdvAir Test Get CurrentTemperature z01" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" # Bats "run" gobbles up all the stdout. Remove for debugging run ../AdvAir.sh Get Blah CurrentTemperature TEST_ON 127.0.0.1 z01 assert_equal "$status" 0 @@ -66,9 +66,9 @@ beforeEach() @test "AdvAir Test Get CurrentTemperature z03" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" # Bats "run" gobbles up all the stdout. Remove for debugging run ../AdvAir.sh Get Blah CurrentTemperature TEST_ON 127.0.0.1 z03 assert_equal "$status" "0" @@ -84,14 +84,14 @@ beforeEach() assert_equal "${#lines[@]}" 8 } -@test "AdvAir Test Get CurrentTemperature with NoSensor Data (creating new myAirConstants" { +@test "AdvAir Test Get CurrentTemperature with NoSensor Data (creating new myAirConstants)" { # The old scripts return 0 because it does not realize noSensors before beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/oneZonePassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/oneZonePassingSystemData.txt" # Bats "run" gobbles up all the stdout. Remove for debugging run ../AdvAir.sh Get Blah CurrentTemperature TEST_ON 127.0.0.1 assert_equal "$status" "0" @@ -113,12 +113,12 @@ beforeEach() assert_equal "${#lines[@]}" 13 } -@test "AdvAir Test Get CurrentTemperature with NoSensor Data (with cached myAirConstants" { +@test "AdvAir Test Get CurrentTemperature with NoSensor Data (with cached myAirConstants)" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/oneZonePassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/oneZonePassingSystemData.txt" # Bats "run" gobbles up all the stdout. Remove for debugging run ../AdvAir.sh Get Blah CurrentTemperature TEST_ON 127.0.0.1 assert_equal "$status" 0 diff --git a/test/GetCurrentTemperature.bats_old b/test/GetCurrentTemperature.bats_old deleted file mode 100644 index 5a2b12dd..00000000 --- a/test/GetCurrentTemperature.bats_old +++ /dev/null @@ -1,210 +0,0 @@ -setup() -{ - load './test/setup' - _common_setup -} - -teardown() -{ - _common_teardown -} - -beforeEach() -{ - _common_beforeEach -} - -# if [ -f "/tmp/myAirContants.txt" ]; then rm "/tmp/myAirConstants.txt";fi - -@test "AdvAir ( ezone inline ) Test PassOn5 Get CurrentTemperature" { - # We symbolically link the directory of the test we want to use. - ln -s ./testData/dataPassOn5 ./data - beforeEach - if [ -f "/tmp/myAirContants.txt_TEST" ]; then rm "/tmp/myAirConstants.txt_TEST";fi - # Bats "run" gobbles up all the stdout. Remove for debugging - run ./compare/ezone.txt Get Blah CurrentTemperature TEST_ON - assert_equal "$status" 0 - assert_equal "${lines[0]}" "Try 0" - assert_equal "${lines[1]}" "Try 1" - assert_equal "${lines[2]}" "Try 2" - assert_equal "${lines[3]}" "Try 3" - assert_equal "${lines[4]}" "Try 4" - assert_equal "${lines[5]}" "25.4" - e_status=$status - e_lines=("${lines[@]}") - run ./compare/AdvAir.sh Get Blah CurrentTemperature TEST_ON 192.168.0.173 z01 - assert_equal "$status" "$e_status" - assert_equal "${lines[0]}" "Using IP: 192.168.0.173" - assert_equal "${lines[1]}" "${e_lines[0]}" - assert_equal "${lines[2]}" "${e_lines[1]}" - assert_equal "${lines[3]}" "${e_lines[2]}" - assert_equal "${lines[4]}" "${e_lines[3]}" - assert_equal "${lines[5]}" "${e_lines[4]}" - assert_equal "${lines[6]}" "${e_lines[5]}" -} - -@test "AdvAir ( ezone inline ) Test PassOn1 Get CurrentTemperature" { - ln -s ./testData/dataPassOn1 ./data - beforeEach - run ./compare/ezone.txt Get Blah CurrentTemperature TEST_ON - assert_equal "$status" 0 - assert_equal "${lines[0]}" "Try 0" - e_status=$status - e_lines=("${lines[@]}") - run ./compare/AdvAir.sh Get Blah CurrentTemperature TEST_ON 192.168.0.173 z01 - assert_equal "$status" "$e_status" - assert_equal "${lines[0]}" "Using IP: 192.168.0.173" - assert_equal "${lines[1]}" "${e_lines[0]}" -} - -@test "AdvAir ( ezone inline ) Test PassOn3 Get CurrentTemperature" { - ln -s ./testData/dataPassOn3 ./data - beforeEach - run ./compare/ezone.txt Get Blah CurrentTemperature TEST_ON - assert_equal "$status" 0 - assert_equal "${lines[0]}" "Try 0" - assert_equal "${lines[1]}" "Try 1" - assert_equal "${lines[2]}" "Try 2" - e_status=$status - e_lines=("${lines[@]}") - run ./compare/AdvAir.sh Get Blah CurrentTemperature TEST_ON 192.168.0.173 z01 - assert_equal "$status" "$e_status" - assert_equal "${lines[0]}" "Using IP: 192.168.0.173" - assert_equal "${lines[1]}" "${e_lines[0]}" - assert_equal "${lines[2]}" "${e_lines[1]}" - assert_equal "${lines[3]}" "${e_lines[2]}" -} - -@test "AdvAir ( ezone inline ) Test FailOn5 Get CurrentTemperature" { - ln -s ./testData/dataFailOn5 ./data - beforeEach - run ./compare/ezone.txt Get Blah CurrentTemperature TEST_ON - assert_equal "$status" 1 - assert_equal "${lines[0]}" "Try 0" - assert_equal "${lines[1]}" "Try 1" - assert_equal "${lines[2]}" "Try 2" - assert_equal "${lines[3]}" "Try 3" - assert_equal "${lines[4]}" "Try 4" - e_status=$status - e_lines=("${lines[@]}") - run ./compare/AdvAir.sh Get Blah CurrentTemperature TEST_ON 192.168.0.173 z01 - assert_equal "$status" "$e_status" - assert_equal "${lines[0]}" "Using IP: 192.168.0.173" - assert_equal "${lines[1]}" "${e_lines[0]}" - assert_equal "${lines[2]}" "${e_lines[1]}" - assert_equal "${lines[3]}" "${e_lines[2]}" - assert_equal "${lines[4]}" "${e_lines[3]}" - assert_equal "${lines[5]}" "${e_lines[4]}" -} - - -@test "AdvAir ( zones inline ) Test PassOn1 Get CurrentTemperature z01" { - ln -s ./testData/dataPassOn1 ./data - beforeEach - run ./compare/zones.txt Get Blah CurrentTemperature z01 TEST_ON - assert_equal "$status" 0 - assert_equal "${lines[0]}" "Try 0" - e_status=$status - e_lines=("${lines[@]}") - run ./compare/AdvAir.sh Get Blah CurrentTemperature TEST_ON 192.168.0.173 z01 - assert_equal "$status" "$e_status" - assert_equal "${lines[0]}" "Using IP: 192.168.0.173" - assert_equal "${lines[1]}" "${e_lines[0]}" -} - -@test "AdvAir ( zones inline ) Test PassOn3 Get CurrentTemperature z01" { - ln -s ./testData/dataPassOn3 ./data - beforeEach - run ./compare/zones.txt Get Blah CurrentTemperature z01 TEST_ON - assert_equal "$status" 0 - assert_equal "${lines[0]}" "Try 0" - assert_equal "${lines[1]}" "Try 1" - assert_equal "${lines[2]}" "Try 2" - e_status=$status - e_lines=("${lines[@]}") - run ./compare/AdvAir.sh Get Blah CurrentTemperature TEST_ON 192.168.0.173 z01 - assert_equal "$status" "$e_status" - assert_equal "${lines[0]}" "Using IP: 192.168.0.173" - assert_equal "${lines[1]}" "${e_lines[0]}" - assert_equal "${lines[2]}" "${e_lines[1]}" - assert_equal "${lines[3]}" "${e_lines[2]}" -} - -@test "AdvAir ( zones inline ) Test PassOn5 Get CurrentTemperature z01" { - ln -s ./testData/dataPassOn5 ./data - beforeEach - run ./compare/zones.txt Get Blah CurrentTemperature z01 TEST_ON - assert_equal "$status" 0 - assert_equal "${lines[0]}" "Try 0" - assert_equal "${lines[1]}" "Try 1" - assert_equal "${lines[2]}" "Try 2" - assert_equal "${lines[3]}" "Try 3" - assert_equal "${lines[4]}" "Try 4" - assert_equal "${lines[5]}" "25.4" - e_status=$status - e_lines=("${lines[@]}") - run ./compare/AdvAir.sh Get Blah CurrentTemperature TEST_ON 192.168.0.173 z01 - assert_equal "$status" "$e_status" - assert_equal "${lines[0]}" "Using IP: 192.168.0.173" - assert_equal "${lines[1]}" "${e_lines[0]}" - assert_equal "${lines[2]}" "${e_lines[1]}" - assert_equal "${lines[3]}" "${e_lines[2]}" - assert_equal "${lines[4]}" "${e_lines[3]}" - assert_equal "${lines[5]}" "${e_lines[4]}" - assert_equal "${lines[6]}" "${e_lines[5]}" -} - -@test "AdvAir ( zones inline ) Test FailOn5 Get CurrentTemperature z01" { - ln -s ./testData/dataFailOn5 ./data - beforeEach - run ./compare/zones.txt Get Blah CurrentTemperature z01 TEST_ON - assert_equal "$status" 1 - assert_equal "${lines[0]}" "Try 0" - assert_equal "${lines[1]}" "Try 1" - assert_equal "${lines[2]}" "Try 2" - assert_equal "${lines[3]}" "Try 3" - assert_equal "${lines[4]}" "Try 4" - e_status=$status - e_lines=("${lines[@]}") - run ./compare/AdvAir.sh Get Blah CurrentTemperature TEST_ON 192.168.0.173 z01 - assert_equal "$status" "$e_status" - assert_equal "${lines[0]}" "Using IP: 192.168.0.173" - assert_equal "${lines[1]}" "${e_lines[0]}" - assert_equal "${lines[2]}" "${e_lines[1]}" - assert_equal "${lines[3]}" "${e_lines[2]}" - assert_equal "${lines[4]}" "${e_lines[3]}" - assert_equal "${lines[5]}" "${e_lines[4]}" -} - -@test "AdvAir ( zones inline ) Test PassOn1 Get CurrentTemperature z03" { - ln -s ./testData/dataPassOn1 ./data - beforeEach - run ./compare/zones.txt Get Blah CurrentTemperature z03 TEST_ON - assert_equal "$status" 0 - assert_equal "${lines[0]}" "Try 0" - e_status=$status - e_lines=("${lines[@]}") - run ./compare/AdvAir.sh Get Blah CurrentTemperature TEST_ON 192.168.0.173 z03 - assert_equal "$status" "$e_status" - assert_equal "${lines[0]}" "Using IP: 192.168.0.173" - assert_equal "${lines[1]}" "${e_lines[0]}" -} - -@test "AdvAir ( ezone inline ) Test PassOn1 Get CurrentTemperature with NoSensor Data" { - # We symbolically link the directory of the test we want to use. - #ln -s ./testData/dataPassOn1 ./data - ln -s ./testData/dataOneZone ./data - beforeEach - # Bats "run" gobbles up all the stdout. Remove for debugging - run ./compare/ezone.txt Get Blah CurrentTemperature TEST_ON - assert_equal "$status" 0 - assert_equal "${lines[0]}" "Try 0" - assert_equal "${lines[1]}" "25.4" - e_status=$status - e_lines=("${lines[@]}") - run ./compare/AdvAir.sh Get Blah CurrentTemperature TEST_ON - assert_equal "$status" "$e_status" - assert_equal "${lines[0]}" "${e_lines[0]}" - # The noSensors fixes this - assert_equal "${lines[1]}" "23" -} diff --git a/test/GetOn.bats b/test/GetOn.bats index 687d08a8..5f15ba5b 100644 --- a/test/GetOn.bats +++ b/test/GetOn.bats @@ -10,23 +10,23 @@ teardown() } before() { - rm -f "/tmp/AA-001/AirConServer.out" + rm -f "${TMPDIR}/AA-001/AirConServer.out" } beforeEach() { - rm -f "/tmp/AA-001/myAirData.txt"* - rm -f "/tmp/AA-001/myAirConstants.txt"* - if [ ! -d "/tmp/AA-001" ]; then mkdir "/tmp/AA-001"; fi + _common_beforeEach + rm -f "${TMPDIR}/AA-001/myAirData.txt"* + rm -f "${TMPDIR}/AA-001/myAirConstants.txt"* } # ezone @test "AdvAir Test Get On Fan" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" run ../AdvAir.sh Get Fan On TEST_ON 127.0.0.1 assert_equal "$status" 0 assert_equal "${lines[0]}" "Using IP: 127.0.0.1" @@ -46,9 +46,9 @@ beforeEach() @test "AdvAir Test Get On z01" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" run ../AdvAir.sh Get Blab On TEST_ON 127.0.0.1 z01 assert_equal "$status" 0 assert_equal "${lines[0]}" "Using IP: 127.0.0.1" @@ -65,9 +65,9 @@ beforeEach() @test "AdvAir Test Get On light:Study Patio" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/myPlaceFull.txt" + curl -s -g "http://localhost:$PORT?load=testData/myPlaceFull.txt" # TimerEnabled requires On to be set to 0 run ../AdvAir.sh Get Blab On 'light:Study Patio' 127.0.0.1 ac2 TEST_ON # AdvAir.sh does a get first diff --git a/test/GetRotationSpeed.bats b/test/GetRotationSpeed.bats index 8a4f53b6..e3ab198a 100644 --- a/test/GetRotationSpeed.bats +++ b/test/GetRotationSpeed.bats @@ -10,22 +10,22 @@ teardown() } before() { - rm -f "/tmp/AA-001/AirConServer.out" + rm -f "${TMPDIR}/AA-001/AirConServer.out" } beforeEach() { - rm -f "/tmp/AA-001/myAirData.txt"* - rm -f "/tmp/AA-001/myAirConstants.txt"* - if [ ! -d "/tmp/AA-001" ]; then mkdir "/tmp/AA-001"; fi + _common_beforeEach + rm -f "${TMPDIR}/AA-001/myAirData.txt"* + rm -f "${TMPDIR}/AA-001/myAirConstants.txt"* } @test "AdvAir Test Get RotationSpeed" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" # Bats "run" gobbles up all the stdout. Remove for debugging run ../AdvAir.sh Get Blah RotationSpeed TEST_ON 127.0.0.1 fanSpeed assert_equal "$status" 0 diff --git a/test/GetSetRetry.bats b/test/GetSetRetry.bats index 7c454cfc..c472926c 100644 --- a/test/GetSetRetry.bats +++ b/test/GetSetRetry.bats @@ -10,23 +10,23 @@ teardown() } before() { - rm -f "/tmp/AA-001/AirConServer.out" + rm -f "${TMPDIR}/AA-001/AirConServer.out" } beforeEach() { - rm -f "/tmp/AA-001/myAirData.txt"* - rm -f "/tmp/AA-001/myAirConstants.txt"* - if [ ! -d "/tmp/AA-001" ]; then mkdir "/tmp/AA-001"; fi + _common_beforeEach + rm -f "${TMPDIR}/AA-001/myAirData.txt"* + rm -f "${TMPDIR}/AA-001/myAirConstants.txt"* } @test "AdvAir Test Get CurrentTemperature ( PassOn5 - Retry )" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?repeat=4&load=testData/failedAirConRetrieveSystemData.txt" - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?repeat=4&load=testData/failedAirConRetrieveSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" # Bats "run" gobbles up all the stdout. Remove for debugging run ../AdvAir.sh Get Blah CurrentTemperature TEST_ON 127.0.0.1 z01 assert_equal "$status" 0 @@ -53,9 +53,9 @@ beforeEach() @test "AdvAir Test Get CurrentTemperature ( PassOn1 - No Retry )" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" # Bats "run" gobbles up all the stdout. Remove for debugging run ../AdvAir.sh Get Blah CurrentTemperature TEST_ON 127.0.0.1 z01 assert_equal "$status" 0 @@ -74,10 +74,10 @@ beforeEach() @test "AdvAir Test Get CurrentTemperature ( PassOn3 - Retry )" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?repeat=2&load=testData/failedAirConRetrieveSystemData.txt" - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?repeat=2&load=testData/failedAirConRetrieveSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" # Bats "run" gobbles up all the stdout. Remove for debugging run ../AdvAir.sh Get Blah CurrentTemperature TEST_ON 127.0.0.1 z01 assert_equal "$status" 0 @@ -100,9 +100,9 @@ beforeEach() @test "AdvAir Test Get CurrentTemperature ( FailOn5 - Retry )" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/failedAirConRetrieveSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/failedAirConRetrieveSystemData.txt" # Bats "run" gobbles up all the stdout. Remove for debugging run ../AdvAir.sh Get Blah CurrentTemperature TEST_ON 127.0.0.1 z01 assert_equal "$status" 1 @@ -123,13 +123,12 @@ beforeEach() @test "AdvAir Test Set On 1 Fan ( PassOn5 - Retry )" { - # Old returned "Setting url: http://192.168.0.173:2025/setAircon?json={ac1:{info:{state:on,mode:vent,fan:auto}}}" beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?repeat=4&load=testData/failedAirConRetrieveSystemData.txt" - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?repeat=4&load=testData/failedAirConRetrieveSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" # Bats "run" gobbles up all the stdout. Remove for debugging run ../AdvAir.sh Set Fan On 1 127.0.0.1 TEST_ON assert_equal "$status" 0 @@ -155,13 +154,12 @@ beforeEach() # ezone (Cannot use compare as old does not allow IP and IP is now mandatory @test "AdvAir Test Set On 1 Fan ( PassOn3 - Retry )" { - # old returned "Setting url: http://192.168.0.173:2025/setAircon?json={ac1:{info:{state:on,mode:vent,fan:auto}}}" beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?repeat=2&load=testData/failedAirConRetrieveSystemData.txt" - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?repeat=2&load=testData/failedAirConRetrieveSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" run ../AdvAir.sh Set Fan On 1 127.0.0.1 TEST_ON assert_equal "$status" 0 # AdvAir.sh does a get first @@ -183,9 +181,9 @@ beforeEach() @test "AdvAir Test Set On 1 Fan ( FaillOn5 - Retry )" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/failedAirConRetrieveSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/failedAirConRetrieveSystemData.txt" run ../AdvAir.sh Set Fan On 1 127.0.0.1 TEST_ON # The new air will fail after the first 5 assert_equal "$status" "1" @@ -208,9 +206,9 @@ beforeEach() @test "AdvAir Test Set On 1 z01 ( PassOn1 - No Retry )" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?repeat=1&load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?repeat=1&load=testData/basicPassingSystemData.txt" run ../AdvAir.sh Set Fan On 1 z01 127.0.0.1 TEST_ON # AdvAir.sh does a get first assert_equal "$status" "0" diff --git a/test/GetStatusLowBattery.bats b/test/GetStatusLowBattery.bats index 5fcd847b..4fe4ad3a 100644 --- a/test/GetStatusLowBattery.bats +++ b/test/GetStatusLowBattery.bats @@ -10,22 +10,22 @@ teardown() } before() { - rm -f "/tmp/AA-001/AirConServer.out" + rm -f "${TMPDIR}/AA-001/AirConServer.out" } beforeEach() { - rm -f "/tmp/AA-001/myAirData.txt"* - rm -f "/tmp/AA-001/myAirConstants.txt"* - if [ ! -d "/tmp/AA-001" ]; then mkdir "/tmp/AA-001"; fi + _common_beforeEach + rm -f "${TMPDIR}/AA-001/myAirData.txt"* + rm -f "${TMPDIR}/AA-001/myAirConstants.txt"* } @test "AdvAir Test Get StatusLowBattery z01" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" run ../AdvAir.sh Get Blah StatusLowBattery z01 127.0.0.1 TEST_ON assert_equal "$status" 0 assert_equal "${lines[0]}" "Try 0" diff --git a/test/GetTargetDoorState.bats b/test/GetTargetDoorState.bats index ba9c5575..adaf5004 100644 --- a/test/GetTargetDoorState.bats +++ b/test/GetTargetDoorState.bats @@ -10,14 +10,14 @@ teardown() } before() { - rm -f "/tmp/AA-001/AirConServer.out" + rm -f "${TMPDIR}/AA-001/AirConServer.out" } beforeEach() { - rm -f "/tmp/AA-001/myAirData.txt"* - rm -f "/tmp/AA-001/myAirConstants.txt"* - if [ ! -d "/tmp/AA-001" ]; then mkdir "/tmp/AA-001"; fi + _common_beforeEach + rm -f "${TMPDIR}/AA-001/myAirData.txt"* + rm -f "${TMPDIR}/AA-001/myAirConstants.txt"* } # Typical GarageDoorConfig for currentDoorState @@ -33,9 +33,9 @@ beforeEach() @test "AdvAir Test Get TargetDoorState" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/myPlace.txt" + curl -s -g "http://localhost:$PORT?load=testData/myPlace.txt" run ../AdvAir.sh Get Blah TargetDoorState 'thing:Garage' 127.0.0.1 TEST_ON assert_equal "$status" 0 assert_equal "${lines[0]}" "Try 0" @@ -53,9 +53,9 @@ beforeEach() @test "AdvAir Test Get TargetDoorState - flip enabled" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/myPlace.txt" + curl -s -g "http://localhost:$PORT?load=testData/myPlace.txt" run ../AdvAir.sh Get Blah TargetDoorState 'thing:Garage' flip 127.0.0.1 TEST_ON assert_equal "$status" 0 assert_equal "${lines[0]}" "Try 0" diff --git a/test/GetTargetHeatingCoolingState.bats b/test/GetTargetHeatingCoolingState.bats index 741426bf..12b6bc6d 100644 --- a/test/GetTargetHeatingCoolingState.bats +++ b/test/GetTargetHeatingCoolingState.bats @@ -10,23 +10,23 @@ teardown() } before() { - rm -f "/tmp/AA-001/AirConServer.out" + rm -f "${TMPDIR}/AA-001/AirConServer.out" } beforeEach() { - rm -f "/tmp/AA-001/myAirData.txt"* - rm -f "/tmp/AA-001/myAirConstants.txt"* - if [ ! -d "/tmp/AA-001" ]; then mkdir "/tmp/AA-001"; fi + _common_beforeEach + rm -f "${TMPDIR}/AA-001/myAirData.txt"* + rm -f "${TMPDIR}/AA-001/myAirConstants.txt"* } @test "AdvAir Test Get TargetHeatingCoolingState" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" run ../AdvAir.sh Get Blah TargetHeatingCoolingState TEST_ON 127.0.0.1 assert_equal "$status" 0 assert_equal "${lines[0]}" "Using IP: 127.0.0.1" diff --git a/test/GetTargetTemperature.bats b/test/GetTargetTemperature.bats index a3edf1a6..4c730476 100644 --- a/test/GetTargetTemperature.bats +++ b/test/GetTargetTemperature.bats @@ -10,23 +10,23 @@ teardown() } before() { - rm -f "/tmp/AA-001/AirConServer.out" + rm -f "${TMPDIR}/AA-001/AirConServer.out" } beforeEach() { - rm -f "/tmp/AA-001/myAirData.txt"* - rm -f "/tmp/AA-001/myAirConstants.txt"* - if [ ! -d "/tmp/AA-001" ]; then mkdir "/tmp/AA-001"; fi + _common_beforeEach + rm -f "${TMPDIR}/AA-001/myAirData.txt"* + rm -f "${TMPDIR}/AA-001/myAirConstants.txt"* } @test "AdvAir Test Get TargetTemperature" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" run ../AdvAir.sh Get Blah TargetTemperature 127.0.0.1 TEST_ON assert_equal "$status" 0 assert_equal "${lines[0]}" "Try 0" diff --git a/test/GetTemperatureDisplayUnits.bats b/test/GetTemperatureDisplayUnits.bats deleted file mode 100644 index 617f8f20..00000000 --- a/test/GetTemperatureDisplayUnits.bats +++ /dev/null @@ -1,27 +0,0 @@ -setup() -{ - load './test/setup' - _common_setup -} - -teardown() -{ - _common_teardown -} - - -@test "AdvAir Test Get TemperatureDisplayUnits" { - # Bats "run" gobbles up all the stdout. Remove for debugging - # run ./compare/ezone.txt Get Blah TemperatureDisplayUnits TEST_ON - # assert_equal "$status" 0 - # For shellcheck - assert_equal "0" "0" - # No more lines than expected - # assert_equal "${#lines[@]}" 1 - # e_status=$status - # e_lines=("${lines[@]}") - # TemperatureDisplayUnits has been removed from AdvAir.sh - # run ../AdvAir.sh Get Blah TemperatureDisplayUnits TEST_ON - # assert_equal "$status" "$e_status" ] - # assert_equal "${lines[0]}" "${e_lines[0]}" -} diff --git a/test/InvalidOption.bats b/test/InvalidOption.bats index 7586dfe7..94d93925 100644 --- a/test/InvalidOption.bats +++ b/test/InvalidOption.bats @@ -1,53 +1,78 @@ -setup() -{ - load './test/setup' - _common_setup -} - -teardown() -{ - _common_teardown -} -before() +setup() { - rm -f "/tmp/AA-001/AirConServer.out" + load './test/setup' + _common_setup +} + +teardown() +{ + _common_teardown +} +before() +{ + rm -f "${TMPDIR}/AA-001/AirConServer.out" } beforeEach() { - rm -f "/tmp/AA-001/myAirData.txt"* - rm -f "/tmp/AA-001/myAirConstants.txt"* - if [ ! -d "/tmp/AA-001" ]; then mkdir "/tmp/AA-001"; fi + _common_beforeEach + rm -f "${TMPDIR}/AA-001/myAirData.txt"* + rm -f "${TMPDIR}/AA-001/myAirConstants.txt"* } -@test "AdvAir Test Invalid Option 'BLAH'" { - beforeEach - # Bats "run" gobbles up all the stdout. Remove for debugging - run ../AdvAir.sh Get Fan On TEST_ON BLAH - assert_equal "$status" "1" - assert_equal "${lines[0]}" "Unknown Option: BLAH" - -} - -@test "AdvAir Test IP" { - beforeEach - # Issue the reInit - curl -s -g "http://localhost:2025/reInit" - # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" - # Bats "run" gobbles up all the stdout. Remove for debugging - run ../AdvAir.sh Get Fan On TEST_ON 127.0.0.1 - assert_equal "$status" "0" - assert_equal "${lines[0]}" "Using IP: 127.0.0.1" - assert_equal "${lines[1]}" "Try 0" - assert_equal "${lines[2]}" "Parsing for jqPath: .aircons.ac1.info" - assert_equal "${lines[3]}" "Parsing for jqPath: .aircons.ac1.info.noOfZones" - assert_equal "${lines[4]}" "Parsing for jqPath: .aircons.ac1.zones.z01.rssi" - assert_equal "${lines[5]}" "Parsing for jqPath: .aircons.ac1.info.constant1" - assert_equal "${lines[6]}" "Parsing for jqPath: .aircons.ac1.info.state" - assert_equal "${lines[7]}" "Parsing for jqPath: .aircons.ac1.info.mode" - assert_equal "${lines[8]}" "0" - # No more lines than expected - assert_equal "${#lines[@]}" 9 - +@test "AdvAir Test Invalid Option 'BLAH'" { + beforeEach + # Bats "run" gobbles up all the stdout. Remove for debugging + run ../AdvAir.sh Get Fan On TEST_ON BLAH + assert_equal "$status" "1" + assert_equal "${lines[0]}" "Unknown Option: BLAH" + } + +@test "AdvAir Test IP" { + beforeEach + # Issue the reInit + curl -s -g "http://localhost:$PORT/reInit" + # Do the load + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" + # Bats "run" gobbles up all the stdout. Remove for debugging + run ../AdvAir.sh Get Fan On TEST_ON 127.0.0.1 + assert_equal "$status" "0" + assert_equal "${lines[0]}" "Using IP: 127.0.0.1" + assert_equal "${lines[1]}" "Try 0" + assert_equal "${lines[2]}" "Parsing for jqPath: .aircons.ac1.info" + assert_equal "${lines[3]}" "Parsing for jqPath: .aircons.ac1.info.noOfZones" + assert_equal "${lines[4]}" "Parsing for jqPath: .aircons.ac1.zones.z01.rssi" + assert_equal "${lines[5]}" "Parsing for jqPath: .aircons.ac1.info.constant1" + assert_equal "${lines[6]}" "Parsing for jqPath: .aircons.ac1.info.state" + assert_equal "${lines[7]}" "Parsing for jqPath: .aircons.ac1.info.mode" + assert_equal "${lines[8]}" "0" + # No more lines than expected + assert_equal "${#lines[@]}" 9 + +} + +@test "AdvAir Test IP-debug" { + beforeEach + # Issue the reInit + curl -s -g "http://localhost:$PORT/reInit" + # Do the load + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" + # Bats "run" gobbles up all the stdout. Remove for debugging + run ../AdvAir.sh Get Fan On TEST_ON 127.0.0.1-debug + assert_equal "$status" "0" + assert_equal "${lines[0]}" "Using IP: 127.0.0.1" + assert_equal "${lines[1]}" "Diagnostic log is turned on" + assert_equal "${lines[2]}" "Try 0" + assert_equal "${lines[3]}" "Parsing for jqPath: .aircons.ac1.info" + assert_equal "${lines[4]}" "Parsing for jqPath: .aircons.ac1.info.noOfZones" + assert_equal "${lines[5]}" "Parsing for jqPath: .aircons.ac1.zones.z01.rssi" + assert_equal "${lines[6]}" "Parsing for jqPath: .aircons.ac1.info.constant1" + assert_equal "${lines[7]}" "Parsing for jqPath: .aircons.ac1.info.state" + assert_equal "${lines[8]}" "Parsing for jqPath: .aircons.ac1.info.mode" + assert_equal "${lines[9]}" "0" + # No more lines than expected + assert_equal "${#lines[@]}" 10 + +} + diff --git a/test/SetBrightness.bats b/test/SetBrightness.bats index c93c39ca..ffa07c13 100644 --- a/test/SetBrightness.bats +++ b/test/SetBrightness.bats @@ -10,22 +10,22 @@ teardown() } before() { - rm -f "/tmp/AA-001/AirConServer.out" + rm -f "${TMPDIR}/AA-001/AirConServer.out" } beforeEach() { - rm -f "/tmp/AA-001/myAirData.txt"* - rm -f "/tmp/AA-001/myAirConstants.txt"* - if [ ! -d "/tmp/AA-001" ]; then mkdir "/tmp/AA-001"; fi + _common_beforeEach + rm -f "${TMPDIR}/AA-001/myAirData.txt"* + rm -f "${TMPDIR}/AA-001/myAirConstants.txt"* } @test "AdvAir Test SetBrightness With Zone Specified damper 15" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" run ../AdvAir.sh Set Blah Brightness 15 z01 127.0.0.1 TEST_ON assert_equal "$status" 0 # AdvAir.sh does a get first @@ -41,9 +41,9 @@ beforeEach() @test "AdvAir Test SetBrightness With timer enabled State Off" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" run ../AdvAir.sh Set Blah Brightness 15 timer 127.0.0.1 TEST_ON assert_equal "$status" 0 # AdvAir.sh does a get first @@ -60,9 +60,9 @@ beforeEach() @test "AdvAir Test Set brightness 80 light:Study Patio" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/myPlaceFull.txt" + curl -s -g "http://localhost:$PORT?load=testData/myPlaceFull.txt" # TimerEnabled requires On to be set to 0 run ../AdvAir.sh Set Blab Brightness 80 'light:Study Patio' 127.0.0.1 TEST_ON # AdvAir.sh does a get first diff --git a/test/SetOn.bats b/test/SetOn.bats index 1ceb231f..84e58c08 100644 --- a/test/SetOn.bats +++ b/test/SetOn.bats @@ -10,24 +10,23 @@ teardown() } before() { - rm -f "/tmp/AA-001/AirConServer.out" + rm -f "${TMPDIR}/AA-001/AirConServer.out" } beforeEach() { - rm -f "/tmp/AA-001/myAirData.txt"* - rm -f "/tmp/AA-001/myAirConstants.txt"* - if [ ! -d "/tmp/AA-001" ]; then mkdir "/tmp/AA-001"; fi + _common_beforeEach + rm -f "${TMPDIR}/AA-001/myAirData.txt"* + rm -f "${TMPDIR}/AA-001/myAirConstants.txt"* } # fanSpecified = true because no zone (z01) specified @test "AdvAir Test Set On 1 - fanSpecified = true (default)" { - # old returned "Setting url: http://192.168.0.173:2025/setAircon?json={ac1:{info:{state:on,mode:vent,fan:auto}}}" beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" run ../AdvAir.sh Set Blah On 1 127.0.0.1 TEST_ON assert_equal "$status" 0 # AdvAir.sh does a get first @@ -47,9 +46,9 @@ beforeEach() @test "AdvAir Test Set On 1 z01 - zoneSpecified = true" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" run ../AdvAir.sh Set Blah On 1 z01 127.0.0.1 TEST_ON # AdvAir.sh does a get first assert_equal "$status" "0" @@ -67,9 +66,9 @@ beforeEach() @test "AdvAir Test Set On 0 timer - timerSpecified = true" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" # TimerEnabled requires On to be set to 0 run ../AdvAir.sh Set Fan On 0 timer 127.0.0.1 TEST_ON # AdvAir.sh does a get first @@ -91,9 +90,9 @@ beforeEach() @test "AdvAir Test Set On 1 light - lightSpecified = true" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/myPlaceFull.txt" + curl -s -g "http://localhost:$PORT?load=testData/myPlaceFull.txt" # TimerEnabled requires On to be set to 0 run ../AdvAir.sh Set Fan On 1 'light:Study Patio' 127.0.0.1 TEST_ON # AdvAir.sh does a get first diff --git a/test/SetTargetDoorState.bats b/test/SetTargetDoorState.bats index 382e4020..78129500 100644 --- a/test/SetTargetDoorState.bats +++ b/test/SetTargetDoorState.bats @@ -14,22 +14,22 @@ teardown() } before() { - rm -f "/tmp/AA-001/AirConServer.out" + rm -f "${TMPDIR}/AA-001/AirConServer.out" } beforeEach() { - rm -f "/tmp/AA-001/myAirData.txt"* - rm -f "/tmp/AA-001/myAirConstants.txt"* - if [ ! -d "/tmp/AA-001" ]; then mkdir "/tmp/AA-001"; fi + _common_beforeEach + rm -f "${TMPDIR}/AA-001/myAirData.txt"* + rm -f "${TMPDIR}/AA-001/myAirConstants.txt"* } @test "AdvAir Test Set TargetDoorState" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/myPlace.txt" + curl -s -g "http://localhost:$PORT?load=testData/myPlace.txt" run ../AdvAir.sh Set Blah TargetDoorState 0 'thing:Garage' 127.0.0.1 TEST_ON assert_equal "$status" 0 assert_equal "${lines[0]}" "Try 0" @@ -45,9 +45,9 @@ beforeEach() @test "AdvAir Test Set TargetDoorState - flip enabled" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/myPlace.txt" + curl -s -g "http://localhost:$PORT?load=testData/myPlace.txt" run ../AdvAir.sh Set Blah TargetDoorState 0 'thing:Garage' 127.0.0.1 flip TEST_ON assert_equal "$status" 0 assert_equal "${lines[0]}" "Try 0" diff --git a/test/SetTargetHeatingCoolingState.bats b/test/SetTargetHeatingCoolingState.bats index 9fc53834..806462fd 100644 --- a/test/SetTargetHeatingCoolingState.bats +++ b/test/SetTargetHeatingCoolingState.bats @@ -10,22 +10,22 @@ teardown() } before() { - rm -f "/tmp/AA-001/AirConServer.out" + rm -f "${TMPDIR}/AA-001/AirConServer.out" } beforeEach() { - rm -f "/tmp/AA-001/myAirData.txt"* - rm -f "/tmp/AA-001/myAirConstants.txt"* - if [ ! -d "/tmp/AA-001" ]; then mkdir "/tmp/AA-001"; fi + _common_beforeEach + rm -f "${TMPDIR}/AA-001/myAirData.txt"* + rm -f "${TMPDIR}/AA-001/myAirConstants.txt"* } @test "AdvAir Test Set TargetHeatingCoolingState 1" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" run ../AdvAir.sh Set Blah TargetHeatingCoolingState 1 127.0.0.1 TEST_ON assert_equal "$status" 0 # AdvAir.sh does a get first diff --git a/test/SetTargetTemperature.bats b/test/SetTargetTemperature.bats index 963d65a3..dcabac6a 100644 --- a/test/SetTargetTemperature.bats +++ b/test/SetTargetTemperature.bats @@ -10,22 +10,22 @@ teardown() } before() { - rm -f "/tmp/AA-001/AirConServer.out" + rm -f "${TMPDIR}/AA-001/AirConServer.out" } beforeEach() { - rm -f "/tmp/AA-001/myAirData.txt"* - rm -f "/tmp/AA-001/myAirConstants.txt"* - if [ ! -d "/tmp/AA-001" ]; then mkdir "/tmp/AA-001"; fi + _common_beforeEach + rm -f "${TMPDIR}/AA-001/myAirData.txt"* + rm -f "${TMPDIR}/AA-001/myAirConstants.txt"* } @test "AdvAir Test Set TargetTemperature 23.5" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/basicPassingSystemData.txt" + curl -s -g "http://localhost:$PORT?load=testData/basicPassingSystemData.txt" # the first AdvAir.sh run is to create the myAirConstants.txt.ac1 run ../AdvAir.sh Get Blah TargetTemperature 127.0.0.1 TEST_ON run ../AdvAir.sh Set Blah TargetTemperature 23.5 127.0.0.1 TEST_ON diff --git a/test/StartServer b/test/StartServer index ba7f0932..8c6a056a 100644 --- a/test/StartServer +++ b/test/StartServer @@ -8,21 +8,23 @@ setup() _common_setup } +if [ -z "$TMPDIR" ]; then TMPDIR="/tmp"; fi +if [ ! -d "${TMPDIR}/AA-001" ]; then mkdir "${TMPDIR}/AA-001"; fi + startServer() { - echo "In startServer" >> /tmp/AA-001/AirConServer.out - - touch /tmp/AA-001/AirConServer.out + touch "${TMPDIR}/AA-001/AirConServer.out" + echo "In startServer" >> "${TMPDIR}"/AA-001/AirConServer.out # Start a new AirConServer - echo "Setup: Starting daemon" >> /tmp/AA-001/AirConServer.out - node ./AirConServer.js >> /tmp/AA-001/AirConServer.out 2>&1 & + echo "Setup: Starting daemon" >> "${TMPDIR}"/AA-001/AirConServer.out + node ./AirConServer.js >> "${TMPDIR}/AA-001/AirConServer.out" 2>&1 & rc=$? if [ "$rc" != 0 ]; then - echo "Setup: Starting Daemon failed rc: $rc" >> /tmp/AA-001/AirConServer.out + echo "Setup: Starting Daemon failed rc: $rc" >> "${TMPDIR}"/AA-001/AirConServer.out fi sleep 3 - echo "Setup: Daemon shold be started rc: $rc" >> /tmp/AA-001/AirConServer.out + echo "Setup: Daemon shold be started rc: $rc" >> "${TMPDIR}"/AA-001/AirConServer.out } diff --git a/test/StopServer b/test/StopServer index 26499ece..621d599a 100644 --- a/test/StopServer +++ b/test/StopServer @@ -8,24 +8,27 @@ setup() _common_setup } +if [ -z "$TMPDIR" ]; then TMPDIR="/tmp"; fi +if [ ! -d "${TMPDIR}/AA-001" ]; then mkdir "${TMPDIR}/AA-001"; fi + stopServer() { rc=0; - touch /tmp/AA-001/AA-001/AirConServer.out - echo "in stopServer" >> /tmp/AA-001/AirConServer.out + touch "${TMPDIR}"/AA-001/AirConServer.out + echo "in stopServer" >> "${TMPDIR}"/AA-001/AirConServer.out # Check if the server is running # lsof -Pi :3025 -sTCP:LISTEN # local rc=$? # if [ "$rc" = "0" ]; then if lsof -Pi :"$PORT" -sTCP:LISTEN -t >/dev/null ; then - echo "Setup: Stopping daemon" >> /tmp/AA-001/AirConServer.out + echo "Setup: Stopping daemon" >> "${TMPDIR}"/AA-001/AirConServer.out # Stop it if it is, Just in case its old - curl -s -g "http://localhost:$PORT/quit" >> /tmp/AA-001/AirConServer.out 2>&1 + curl -s -g "http://localhost:$PORT/quit" >> "${TMPDIR}"/AA-001/AirConServer.out 2>&1 rc=$? if [ "$rc" != 0 ]; then - echo "Setup: Stopping failed rc: $rc" >> /tmp/AA-001/AirConServer.out + echo "Setup: Stopping failed rc: $rc" >> "${TMPDIR}"/AA-001/AirConServer.out fi - echo "Setup: Curl has Stoped daemon rc: $rc" >> /tmp/AA-001/AirConServer.out + echo "Setup: Curl has Stoped daemon rc: $rc" >> "${TMPDIR}"/AA-001/AirConServer.out fi } diff --git a/test/sampleTest.bats b/test/sampleTest.bats index 2833b4bc..d98bfa96 100644 --- a/test/sampleTest.bats +++ b/test/sampleTest.bats @@ -21,9 +21,9 @@ # # For example in Terminal 2: # # Issue the reInit -# curl -s -g "http://localhost:2025/reInit" +# curl -s -g "http://localhost:$PORT/reInit" # # Do the load -# curl -s -g "http://localhost:2025?load=testData/myPlace.txt" +# curl -s -g "http://localhost:$PORT?load=testData/myPlace.txt" # run ../AdvAir.sh Get Blah CurrentDoorState 'thing:Garage' 127.0.0.1 TEST_ON # The results to stdout are usually just the result, but are expanded via TEST_ON: @@ -58,14 +58,14 @@ teardown() } before() { - rm -f "/tmp/AA-001/AirConServer.out" + rm -f "${TMPDIR}/AA-001/AirConServer.out" } beforeEach() { - rm -f "/tmp/AA-001/myAirData.txt"* - rm -f "/tmp/AA-001/myAirConstants.txt"* - if [ ! -d "/tmp/AA-001" ]; then mkdir "/tmp/AA-001"; fi + _common_beforeEach + rm -f "${TMPDIR}/AA-001/myAirData.txt"* + rm -f "${TMPDIR}/AA-001/myAirConstants.txt"* } @test "Sample Test (How to Skip)" { @@ -91,9 +91,9 @@ beforeEach() @test "AdvAir Test Get CurrentDoorState ( Sample )" { beforeEach # Issue the reInit - curl -s -g "http://localhost:2025/reInit" + curl -s -g "http://localhost:$PORT/reInit" # Do the load - curl -s -g "http://localhost:2025?load=testData/myPlace.txt" + curl -s -g "http://localhost:$PORT?load=testData/myPlace.txt" run ../AdvAir.sh Get Blah CurrentDoorState 'thing:Garage' 127.0.0.1 TEST_ON assert_equal "$status" 0 assert_equal "${lines[0]}" "Try 0" diff --git a/test/setup b/test/setup index 3f1bed14..c3209cbd 100644 --- a/test/setup +++ b/test/setup @@ -37,6 +37,9 @@ _common_teardown() _common_beforeEach() { + # define TMPDIR if not already defined + if [ -z "${TMPDIR}" ]; then TMPDIR="/tmp"; fi + if [ ! -d "${TMPDIR}/AA-001" ]; then mkdir "${TMPDIR}/AA-001"; fi # Constants can change with different data - rm -f "/tmp/AA-001/myAirConstants.txt"* + rm -f "${TMPDIR}/AA-001/myAirConstants.txt"* }