evobackup/test/main.bats

80 lines
2.3 KiB
Plaintext
Raw Normal View History

2018-03-05 15:29:08 +01:00
#!/usr/bin/env bats
2020-04-08 16:49:27 +02:00
# shellcheck disable=SC1089,SC1083,SC2154
2018-03-05 15:29:08 +01:00
load test_helper
2020-04-05 11:53:44 +02:00
@test "Filesystem type" {
if is_btrfs "/backup"; then
# On a btrfs filesystem, the jail should be a btrfs volume
2020-04-05 11:53:44 +02:00
run is_btrfs "${JAILPATH}"
assert_success
2018-03-28 15:11:49 +02:00
else
# On an ext4 filesystem, the jail should be a regular directory
2020-04-02 13:32:14 +02:00
run test -d "${JAILPATH}"
2020-04-05 11:53:44 +02:00
assert_success
2018-03-28 15:11:49 +02:00
fi
}
2020-04-02 18:28:15 +02:00
@test "New jail should have a incs_policy file" {
run test -f "/etc/evobackup/${JAILNAME}.d/incs_policy"
assert_success
}
@test "New jail should have a check_policy file" {
run test -f "/etc/evobackup/${JAILNAME}.d/check_policy"
assert_success
}
2020-04-05 11:53:44 +02:00
@test "A jail should be able to be started" {
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
}
2020-04-05 11:53:44 +02:00
@test "A jail should be able to be stopped" {
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
}
2020-04-05 11:53:44 +02:00
@test "A jail should be able to be reloaded" {
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
}
2020-04-05 11:53:44 +02:00
@test "A jail should be able to be restarted" {
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
}
2020-04-05 11:53:44 +02:00
@test "Status should return information" {
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
}
2020-04-05 11:53:44 +02:00
@test "ON/OFF status can be retrived with '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
}