gen2stage4/tests/test_helper.bash
lucianposton 94b0040499
Add BATS tests with automated github workflow (#34)
Added tests, including test cases for:
* the -b option
* the -c (connman) option
* the -e option
* the -k option
* the -l option
* portage dirs


Signed-off-by: Lucian Poston <lucianposton@pm.me>
2020-02-07 00:59:18 +01:00

44 lines
884 B
Bash

#!/bin/bash
test_directory="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export PATH="$test_directory/..:$PATH"
test_uname="test-uname"
uname() { echo "$test_uname"; }
export -f uname
# bypasses mkstage4.sh root check
whoami() { echo "root"; }
export -f whoami
skip_if_not_root() {
if [ "$EUID" -ne 0 ]; then
skip "Must be root for this test."
fi
}
d() {
mkdir -p "${1}"
}
f() {
mkdir -p "$(dirname "${1}")" && touch "${1}"
}
assert_tar_includes() {
test -f "${1}" || test -d "${1}"
tar --list -f "${2-test.tar.bz2}" | grep -q "^${1}$"
}
assert_tar_includes_partial() {
tar --list -f "${2-test.tar.bz2}" | grep -q "${1}"
}
assert_tar_excludes() {
test -f "${1}" || test -d "${1}"
! tar --list -f "${2-test.tar.bz2}" | grep -q "^${1}$"
}
assert_tar_excludes_partial() {
! tar --list -f "${2-test.tar.bz2}" | grep -q "${1}"
}