Refactor how tests are organized
This commit is contained in:
parent
a77617ae96
commit
56f38ad451
17
default.nix
17
default.nix
@ -164,18 +164,9 @@ in rec {
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
tests = pkgs.writeShellScript "isle-tests" ''
|
tests = pkgs.writeScript "isle-tests" ''
|
||||||
export PATH=${appImage}/bin:$PATH
|
export PATH=${pkgs.lib.makeBinPath [ appImage pkgs.busybox ]}
|
||||||
test_dir=${./tests}
|
export SHELL=${pkgs.bash}/bin/bash
|
||||||
|
exec ${./tests}/entrypoint.sh "$@"
|
||||||
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 "$@"
|
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,8 @@ let
|
|||||||
# The author of go-appimage has set up some crazy continuous integration build
|
# 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
|
# 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
|
# 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 = {
|
src = {
|
||||||
"x86_64" = "${srcDir}/appimagetool-${version}-x86_64.AppImage";
|
"x86_64" = "${srcDir}/appimagetool-${version}-x86_64.AppImage";
|
||||||
"aarch64" = "${srcDir}/go-appimage/appimagetool-${version}-aarch64.AppImage";
|
"aarch64" = "${srcDir}/go-appimage/appimagetool-${version}-aarch64.AppImage";
|
||||||
|
15
tests.sh
Executable file
15
tests.sh
Executable 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
19
tests/entrypoint.sh
Normal file → Executable file
@ -1,5 +1,9 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
# cd into script's directory
|
||||||
|
cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null
|
||||||
|
root=$(pwd)
|
||||||
|
|
||||||
REGEXS=()
|
REGEXS=()
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
@ -29,10 +33,6 @@ EOF
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# cd into script's directory
|
|
||||||
cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null
|
|
||||||
root=$(pwd)
|
|
||||||
|
|
||||||
TMPDIR="$(mktemp --tmpdir -d isle-tests.XXXXXX)"
|
TMPDIR="$(mktemp --tmpdir -d isle-tests.XXXXXX)"
|
||||||
if [ -z "$KEEP_TMP" ]; then trap 'rm -rf $TMPDIR' EXIT; fi
|
if [ -z "$KEEP_TMP" ]; then trap 'rm -rf $TMPDIR' EXIT; fi
|
||||||
|
|
||||||
@ -40,14 +40,14 @@ export TMPDIR
|
|||||||
echo "tmp dir is $TMPDIR"
|
echo "tmp dir is $TMPDIR"
|
||||||
|
|
||||||
test_files=$(
|
test_files=$(
|
||||||
find . -type f -name '*.sh' \
|
find ./cases -type f -name '*.sh' \
|
||||||
| sed "s|^\./||" \
|
| sed "s|^\./cases/||" \
|
||||||
| grep -v entrypoint.sh \
|
| grep -v entrypoint.sh \
|
||||||
| sort -n\
|
| sort -n
|
||||||
)
|
)
|
||||||
|
|
||||||
for r in "${REGEXS[@]}"; do
|
for r in "${REGEXS[@]}"; do
|
||||||
test_files="$(echo "$test_files" | grep -P "$r")"
|
test_files="$(echo "$test_files" | grep "$r")"
|
||||||
done
|
done
|
||||||
|
|
||||||
echo -e "number of tests: $(echo "$test_files" | wc -l)\n"
|
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"
|
mkdir -p "$TMPDIR" "$XDG_RUNTIME_DIR" "$XDG_DATA_HOME"
|
||||||
cd "$TMPDIR"
|
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"
|
echo "$file FAILED"
|
||||||
if [ -z "$VERBOSE" ]; then
|
if [ -z "$VERBOSE" ]; then
|
||||||
echo "output of test is as follows"
|
echo "output of test is as follows"
|
||||||
@ -78,4 +78,3 @@ for file in $test_files; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
echo -e '\nall tests succeeded!'
|
echo -e '\nall tests succeeded!'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user