Preparing tests for sorted json output keys.

pull/708/head
Fredrik Öhrström 2022-11-20 13:29:28 +01:00
rodzic f650577ea2
commit 0eb90f697c
7 zmienionych plików z 24 dodań i 17 usunięć

Wyświetl plik

@ -2,4 +2,4 @@ name=Vatten
type=supercom587
id=12345678
key=
shell=echo "TESTING SHELL $METER_JSON" > /tmp/wmbusmeters_meter_shell_test
shell=echo "TESTING SHELL $(echo $METER_JSON | jq -c --sort-keys .)" > /tmp/wmbusmeters_meter_shell_test

Wyświetl plik

@ -10,14 +10,14 @@ mkdir -p $TEST
TESTNAME="Test aes encrypted telegrams"
TESTRESULT="ERROR"
cat simulations/serial_aes.msg | grep '^{' | tr -d '#' > $TEST/test_expected.txt
cat simulations/serial_aes.msg | grep '^{' | tr -d '#' | jq --sort-keys . > $TEST/test_expected.txt
cat simulations/serial_aes.msg | grep '^[CT]' | tr -d '#' > $TEST/test_input.txt
cat $TEST/test_input.txt | $PROG --format=json "stdin:rtlwmbus" \
ApWater apator162 88888888 00000000000000000000000000000000 \
Vatten multical21 76348799 28F64A24988064A079AA2C807D6102AE \
Wasser supercom587 77777777 5065747220486F6C79737A6577736B69 > $TEST/test_output.txt 2> $TEST/test_stderr.txt
Wasser supercom587 77777777 5065747220486F6C79737A6577736B69 2> $TEST/test_stderr.txt | jq --sort-keys . > $TEST/test_output.txt
cat $TEST/test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_response.txt
cat $TEST/test_output.txt | sed 's/"timestamp": "....-..-..T..:..:..Z"/"timestamp": "1111-11-11T11:11:11Z"/' > $TEST/test_response.txt
diff $TEST/test_expected.txt $TEST/test_response.txt
if [ "$?" = "0" ]
then

Wyświetl plik

@ -18,11 +18,11 @@ METERS="Wasser apator162 20202020 NOKEY
MyTapWatere apator162 27202020 NOKEY
MyTapWaterf apator162 03410514 NOKEY"
cat simulations/simulation_apas.txt | grep '^{' > $TEST/test_expected.txt
$PROG --format=json simulations/simulation_apas.txt $METERS > $TEST/test_output.txt 2> $TEST/test_stderr.txt
cat simulations/simulation_apas.txt | grep '^{' | jq --sort-keys . > $TEST/test_expected.txt
$PROG --format=json simulations/simulation_apas.txt $METERS 2> $TEST/test_stderr.txt | jq --sort-keys . > $TEST/test_output.txt
if [ "$?" = "0" ]
then
cat $TEST/test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt
cat $TEST/test_output.txt | sed 's/"timestamp": "....-..-..T..:..:..Z"/"timestamp": "1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt
diff $TEST/test_expected.txt $TEST/test_responses.txt
if [ "$?" = "0" ]
then

Wyświetl plik

@ -20,11 +20,11 @@ METERS="IzarWater izar 21242472 NOKEY
IzarWater5 izar 20e4ffde NOKEY
IzarWater6 auto 48500375 NOKEY"
cat simulations/simulation_izars.txt | grep '^{' > $TEST/test_expected.txt
$PROG --format=json simulations/simulation_izars.txt $METERS > $TEST/test_output.txt 2> $TEST/test_stderr.txt
cat simulations/simulation_izars.txt | grep '^{' | jq --sort-keys . > $TEST/test_expected.txt
$PROG --format=json simulations/simulation_izars.txt $METERS 2> $TEST/test_stderr.txt | jq --sort-keys . > $TEST/test_output.txt
if [ "$?" = "0" ]
then
cat $TEST/test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt
cat $TEST/test_output.txt | sed 's/"timestamp": "....-..-..T..:..:..Z"/"timestamp": "1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt
diff $TEST/test_expected.txt $TEST/test_responses.txt
if [ "$?" = "0" ]
then

Wyświetl plik

@ -8,7 +8,8 @@ TEST=testoutput
TESTNAME="Test that failed decryption warning only prints once."
TESTRESULT="OK"
$PROG --format=json simulations/simulation_bad_keys.txt room fhkvdataiv 03065716 NOKEY > $TEST/test_output.txt 2> $TEST/test_stderr.txt
$PROG --format=json simulations/simulation_bad_keys.txt room fhkvdataiv 03065716 NOKEY \
2> $TEST/test_stderr.txt | jq --sort-keys . > $TEST/test_output.txt
cat > $TEST/expected_err.txt <<EOF
(wmbus) WARNING! no key to decrypt payload! Permanently ignoring telegrams from id: 03065716 mfct: (TCH) Techem Service (0x5068) type: Heat Cost Allocator (0x08) ver: 0x94
@ -21,7 +22,8 @@ then
TESTRESULT="ERROR"
fi
$PROG --format=json simulations/simulation_bad_keys.txt room fhkvdataiv 03065716 00112233445566778899AABBCCDDEEFF > $TEST/test_output.txt 2> $TEST/test_stderr.txt
$PROG --format=json simulations/simulation_bad_keys.txt room fhkvdataiv 03065716 00112233445566778899AABBCCDDEEFF \
2> $TEST/test_stderr.txt | jq --sort-keys . > $TEST/test_output.txt
cat > $TEST/expected_err.txt <<EOF
(wmbus) WARNING!! decrypted content failed check, did you use the correct decryption key? Permanently ignoring telegrams from id: 03065716 mfct: (TCH) Techem Service (0x5068) type: Heat Cost Allocator (0x08) ver: 0x94

Wyświetl plik

@ -8,11 +8,13 @@ TEST=testoutput
TESTNAME="Test shell invocation"
TESTRESULT="ERROR"
$PROG --shell='echo "$METER_JSON"' simulations/simulation_shell.txt MWW supercom587 12345678 "" > $TEST/test_output.txt 2> $TEST/test_stderr.txt
$PROG --shell='echo "$METER_JSON"' simulations/simulation_shell.txt MWW supercom587 12345678 "" \
2> $TEST/test_stderr.txt | jq --sort-keys . > $TEST/test_output.txt
if [ "$?" = "0" ]
then
cat $TEST/test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt
echo '{"media":"warm water","meter":"supercom587","name":"MWW","id":"12345678","total_m3":5.548,"timestamp":"1111-11-11T11:11:11Z"}' > $TEST/test_expected.txt
cat $TEST/test_output.txt | sed 's/"timestamp": "....-..-..T..:..:..Z"/"timestamp": "1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt
echo '{"media":"warm water","meter":"supercom587","name":"MWW","id":"12345678","total_m3":5.548,"timestamp":"1111-11-11T11:11:11Z"}' \
| jq --sort-keys . > $TEST/test_expected.txt
diff $TEST/test_expected.txt $TEST/test_responses.txt
if [ "$?" = "0" ]
then

Wyświetl plik

@ -7,16 +7,19 @@ mkdir -p $TEST
TESTNAME="Test shell in config file"
TESTRESULT="ERROR"
$PROG --useconfig=tests/config5 > $TEST/test_output.txt 2> $TEST/test_stderr.txt
$PROG --useconfig=tests/config5 2> $TEST/test_stderr.txt > $TEST/test_output.txt
if [ "$?" = "0" ]
then
INFO=$(cat /tmp/wmbusmeters_meter_shell_test | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/')
EXPECTED=$(echo 'TESTING SHELL {"media":"warm water","meter":"supercom587","name":"Vatten","id":"12345678","total_m3":5.548,"timestamp":"1111-11-11T11:11:11Z"}')
EXPECTED='TESTING SHELL {"id":"12345678","media":"warm water","meter":"supercom587","name":"Vatten","timestamp":"1111-11-11T11:11:11Z","total_m3":5.548}'
if [ "$INFO" = "$EXPECTED" ]
then
echo OK: $TESTNAME
TESTRESULT="OK"
else
echo "Expected: $EXPECTED"
echo "Got : $INFO"
fi
fi