evobackup/test/main.bats

70 lines
1.9 KiB
Plaintext
Raw Normal View History

2018-03-05 15:29:08 +01:00
#!/usr/bin/env bats
load test_helper
@test "init-filesystem" {
2019-01-08 11:01:17 +01:00
inode=$(stat --format=%i /backup)
2018-03-28 15:11:49 +02:00
if [ "${inode}" -eq 256 ]; then
# On a btrfs filesystem, the jail should be a btrfs volume
2020-04-02 13:32:14 +02:00
run stat --format=%i "${JAILPATH}"
2018-03-28 15:11:49 +02:00
[ "${output}" -eq 256 ]
else
# On an ext4 filesystem, the jail should be a regular directory
2020-04-02 13:32:14 +02:00
run test -d "${JAILPATH}"
2018-03-28 15:11:49 +02:00
[ "${status}" -eq 0 ]
fi
}
2020-04-02 18:28:15 +02:00
2018-03-28 15:11:49 +02:00
@test "start" {
2019-01-08 11:01:17 +01:00
/usr/lib/bkctld/bkctld-start "${JAILNAME}"
2020-04-02 13:32:14 +02:00
pid=$(cat "${JAILPATH}/${SSHD_PID}")
# A started jail should have an SSH pid file
2018-03-28 15:11:49 +02:00
run ps --pid "${pid}"
assert_success
2018-03-28 15:11:49 +02:00
}
@test "stop" {
2019-01-08 11:01:17 +01:00
/usr/lib/bkctld/bkctld-start "${JAILNAME}"
2020-04-02 13:32:14 +02:00
pid=$(cat "${JAILPATH}/${SSHD_PID}")
2019-01-08 11:01:17 +01:00
/usr/lib/bkctld/bkctld-stop "${JAILNAME}"
# A stopped jail should not have an SSH pid file
2018-03-28 15:11:49 +02:00
run ps --pid "${pid}"
assert_failure
2018-03-28 15:11:49 +02:00
}
@test "reload" {
2019-01-08 11:01:17 +01:00
/usr/lib/bkctld/bkctld-start "${JAILNAME}"
/usr/lib/bkctld/bkctld-reload "${JAILNAME}"
# A reloaded jail should mention the restart in the authlog
2020-04-02 13:32:14 +02:00
run grep "Received SIGHUP; restarting." "${JAILPATH}/var/log/authlog"
assert_success
2018-03-28 15:11:49 +02:00
}
@test "restart" {
2019-01-08 11:01:17 +01:00
/usr/lib/bkctld/bkctld-start "${JAILNAME}"
pid_before=$(cat "${JAILPATH}/${SSHD_PID}")
2019-01-08 11:01:17 +01:00
/usr/lib/bkctld/bkctld-restart "${JAILNAME}"
pid_after=$(cat "${JAILPATH}/${SSHD_PID}")
2020-04-02 14:51:09 +02:00
# A restarted jail should have a different pid
refute_equal "${pid_before}" "${pid_after}"
2018-03-05 15:29:08 +01:00
}
2018-03-28 15:11:49 +02:00
@test "status" {
2019-01-08 11:01:17 +01:00
run /usr/lib/bkctld/bkctld-status "${JAILNAME}"
assert_success
2018-03-28 15:11:49 +02:00
}
@test "is-on" {
2019-01-08 11:01:17 +01:00
/usr/lib/bkctld/bkctld-start "${JAILNAME}"
# A started jail should report to be ON
run /usr/lib/bkctld/bkctld-is-on "${JAILNAME}"
assert_success
2020-04-02 14:51:09 +02:00
/usr/lib/bkctld/bkctld-stop "${JAILNAME}"
# A stopped jail should not report to be ON
run /usr/lib/bkctld/bkctld-is-on "${JAILNAME}"
assert_failure
}