forked from ddev/ddev-cron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.bats
88 lines (72 loc) · 2.34 KB
/
test.bats
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
76
77
78
79
80
81
82
83
84
85
86
87
88
setup() {
set -eu -o pipefail
export DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.."
export TESTDIR=~/tmp/ddev-cron
mkdir -p $TESTDIR
export PROJNAME=ddev-cron
export DDEV_NON_INTERACTIVE=true
ddev delete -Oy ${PROJNAME} || true
cd "${TESTDIR}"
ddev config --project-name=${PROJNAME}
ddev start -y
echo "# ddev started at $(date)" >&3
}
teardown() {
set -eu -o pipefail
cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 )
ddev delete -Oy ${PROJNAME}
[ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR}
}
health_checks() {
# Make sure cron process is running.
# We use `time_cron_checks` to check the example cron job is actually correctly implemented.
# This is due to the need to test the health-check when there are no jobs added.
ddev exec 'sudo killall -0 cron'
}
time_cron_checks() {
# ASSERT time.log was written to
grep UTC time.log
# ASSERT job displays under current user's crontab
ddev exec crontab -l | grep '* * * * * date | tee -a /var/www/html/time.log'
}
@test "install from directory" {
set -eu -o pipefail
cd ${TESTDIR}
echo "# ddev get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
ddev get ${DIR}
# Set the example cron job as an actual cron job.
mv ./.ddev/web-build/time.cron.example ./.ddev/web-build/time.cron
ddev restart
# The example runs every minute so we should wait at least the length.
sleep 61
# Check service works
health_checks
# Check example cron job works
time_cron_checks
}
@test "install from release" {
set -eu -o pipefail
cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 )
echo "# ddev get ddev/ddev-cron with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
ddev get ddev/ddev-cron
# Set the example cron job as an actual cron job.
mv ./.ddev/web-build/time.cron.example ./.ddev/web-build/time.cron
ddev restart
# The example runs every minute so we should wait at least the length.
sleep 61
# Check service works
health_checks
# Check example cron job works
time_cron_checks
}
@test "services work when no valid jobs are present" {
set -eu -o pipefail
cd ${TESTDIR}
echo "# ddev get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
ddev get ${DIR}
ddev restart
# We should wait at least one cycle.
sleep 61
# Check service works
health_checks
}