forked from moormaster/python3-voltcraft-sem6000
-
Notifications
You must be signed in to change notification settings - Fork 2
/
integration-test.sh
executable file
·75 lines (60 loc) · 1.78 KB
/
integration-test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
usage() {
echo "$0 <bluetooth address> <pin>" 1>&2
}
main() {
ADDRESS="$1"
PIN="$2"
SCRIPTDIR="$( dirname "$0" )"
ORIGINAL_SETTINGS_FILE="original_settings.json"
SETTINGS_FILE_FOR_TEST="settings_for_integration_test.json"
TMPFILE="$( mktemp )"
TEST_FAILED=0
if [ -f "$SCRIPTDIR/${ORIGINAL_SETTINGS_FILE}" ]
then
echo "$SCRIPTDIR/${ORIGINAL_SETTINGS_FILE} already exists ... aborting" 1>&2
return 1
fi
echo "Backing up original settings to $SCRIPTDIR/${ORIGINAL_SETTINGS_FILE} ..." 1>&2
if ! "$SCRIPTDIR/sem6000-settings-backup-demo.py" "$ADDRESS" "$PIN" > "$SCRIPTDIR/${ORIGINAL_SETTINGS_FILE}"
then
echo "Failed to backup current settings ... aborting" 1>&2
return 1
fi
echo "" 1>&2
echo "Running integration test... " 1>&2
"$SCRIPTDIR/sem6000-cli-demo.py" "$ADDRESS" "$PIN" change_date_and_time "2000-01-01T00:00"
"$SCRIPTDIR/sem6000-settings-restore-demo.py" "$ADDRESS" "$PIN" "$SCRIPTDIR/${SETTINGS_FILE_FOR_TEST}"
"$SCRIPTDIR/sem6000-settings-backup-demo.py" "$ADDRESS" "$PIN" > "$TMPFILE"
if ! diff "$TMPFILE" "${SETTINGS_FILE_FOR_TEST}"
then
TEST_FAILED=1
echo "FAILED" 1>&2
fi
echo "" 1>&2
echo "Test reading values that are not covered by backup/restore settings script..." 1>&2
if ! "$SCRIPTDIR/sem6000-read-tests.py" "$ADDRESS" "$PIN"
then
TEST_FAILED=1
echo "FAILED" 1>&2
fi
echo "" 1>&2
echo "Restoring original settings from $SCRIPTDIR/${ORIGINAL_SETTINGS_FILE} ..." 1>&2
"$SCRIPTDIR/sem6000-settings-restore-demo.py" "$ADDRESS" "$PIN" "$SCRIPTDIR/${ORIGINAL_SETTINGS_FILE}"
"$SCRIPTDIR/sem6000-cli-demo.py" "$ADDRESS" "$PIN" synchronize_date_and_time
echo "" 1>&2
if [ "${TEST_FAILED}" == "0" ]
then
echo "Test succeeded."
return 0
else
echo "Test failed."
return 1
fi
}
if [ $# -lt 2 ]
then
usage
exit 1
fi
main "$@"