Add a timemachine tool script

- Wrapper around faketime
- Provides an interface to run tests at specific points in time
This commit is contained in:
Thomas Lauf 2019-01-19 10:29:45 +01:00
parent 42acf839d9
commit 68549dc22d

46
test/timemachine Normal file
View file

@ -0,0 +1,46 @@
#!/bin/bash
# parse options/arguments
until [[ -z "${1}" ]] ; do
case "${1}" in
--minute)
shift
minutes="${minutes} ${1}"
;;
--hour)
shift
hours="${hours} ${1}"
;;
--day)
shift
days="${days} ${1}"
;;
--fail-at-end)
fail_at_end=1
;;
-*)
echo "Unknown option '${1}'"
exit 1
;;
*)
tests="${tests} ${1}"
;;
esac
shift
done
for day in ${days-$(date --rfc-3339=date)} ; do
for minute in ${minutes-$(echo "0$(rand -M 60)" | sed "s|.\+\(..\)\$|\1|g")} ; do
for hour in ${hours-$(seq -w 0 23)} ; do
date="${day}T${hour}:${minute}"
for single_test in ${tests} ; do
echo "Running test ${single_test} at ${date}"
faketime "@${date}" "${single_test}"
if [[ $? -ne 0 ]] ; then
echo "Test ${single_test} broke at ${date}!"
[[ ${fail_at_end-0} -ne 0 ]] || break 2
fi
done
done
done
done