Refactor how tests are organized

This commit is contained in:
Brian Picciano 2023-09-01 18:28:22 +02:00
parent a77617ae96
commit 56f38ad451
7 changed files with 30 additions and 27 deletions

View File

@ -164,18 +164,9 @@ in rec {
'';
};
tests = pkgs.writeShellScript "isle-tests" ''
export PATH=${appImage}/bin:$PATH
test_dir=${./tests}
this_user="$(${pkgs.coreutils}/bin/whoami)"
echo "Requesting sudo in order to set thread capabilities, will drop back down to user '$this_user' immediately"
sudo ${pkgs.libcap}/bin/capsh \
--caps="cap_net_admin+eip cap_setpcap,cap_setuid,cap_setgid+ep" \
--keep=1 \
--user="$this_user" \
--addamb=cap_net_admin \
-- $test_dir/entrypoint.sh "$@"
tests = pkgs.writeScript "isle-tests" ''
export PATH=${pkgs.lib.makeBinPath [ appImage pkgs.busybox ]}
export SHELL=${pkgs.bash}/bin/bash
exec ${./tests}/entrypoint.sh "$@"
'';
}

View File

@ -12,7 +12,8 @@ let
# The author of go-appimage has set up some crazy continuous integration build
# system with github, which is really cool, except that it doesn't preserve
# any older builds of the project. And it's pretty difficult to build it
# ourselves. So fuck it, just embed a tarball into the repo.
# ourselves. So fuck it, just embed the build artifacts directly in this
# project.
src = {
"x86_64" = "${srcDir}/appimagetool-${version}-x86_64.AppImage";
"aarch64" = "${srcDir}/go-appimage/appimagetool-${version}-aarch64.AppImage";

View File

@ -1,3 +0,0 @@
#!/usr/bin/env sh
$(nix-build --no-out-link -A tests)

15
tests.sh Executable file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -e
entrypoint="$(nix-build --no-out-link -A tests)"
this_user="$(whoami)"
echo "Requesting sudo in order to set thread capabilities, will drop back down to user '$this_user' immediately"
sudo -E capsh \
--caps="cap_net_admin+eip cap_setpcap,cap_setuid,cap_setgid+ep" \
--keep=1 \
--user="$this_user" \
--addamb=cap_net_admin \
-- "$entrypoint" "$@"

19
tests/entrypoint.sh Normal file → Executable file
View File

@ -1,5 +1,9 @@
set -e
# cd into script's directory
cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null
root=$(pwd)
REGEXS=()
while [[ $# -gt 0 ]]; do
@ -29,10 +33,6 @@ EOF
esac
done
# cd into script's directory
cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null
root=$(pwd)
TMPDIR="$(mktemp --tmpdir -d isle-tests.XXXXXX)"
if [ -z "$KEEP_TMP" ]; then trap 'rm -rf $TMPDIR' EXIT; fi
@ -40,14 +40,14 @@ export TMPDIR
echo "tmp dir is $TMPDIR"
test_files=$(
find . -type f -name '*.sh' \
| sed "s|^\./||" \
find ./cases -type f -name '*.sh' \
| sed "s|^\./cases/||" \
| grep -v entrypoint.sh \
| sort -n\
| sort -n
)
for r in "${REGEXS[@]}"; do
test_files="$(echo "$test_files" | grep -P "$r")"
test_files="$(echo "$test_files" | grep "$r")"
done
echo -e "number of tests: $(echo "$test_files" | wc -l)\n"
@ -64,7 +64,7 @@ for file in $test_files; do
mkdir -p "$TMPDIR" "$XDG_RUNTIME_DIR" "$XDG_DATA_HOME"
cd "$TMPDIR"
if ! $SHELL -e -x "$root/$file" >"$output" 2>&1; then
if ! $SHELL -e -x "$root/cases/$file" >"$output" 2>&1; then
echo "$file FAILED"
if [ -z "$VERBOSE" ]; then
echo "output of test is as follows"
@ -78,4 +78,3 @@ for file in $test_files; do
done
echo -e '\nall tests succeeded!'