add rudimentary test harness, turn example-configuration into a test

module-based-network
Daniel Barlow 2022-09-20 15:22:37 +01:00
parent 4b118bca19
commit b38b0bd932
4 changed files with 32 additions and 3 deletions

View File

@ -1,14 +1,14 @@
pkgs: config:
let
inherit (pkgs) buildPlatform callPackage runCommandNoCC closureInfo stdenv writeText s6-rc;
inherit (pkgs) buildPlatform callPackage stdenvNoCC closureInfo stdenv writeText s6-rc;
# we need to generate s6 db, by generating closure of all
# config.services and calling s6-rc-compile on them
allServices = closureInfo {
rootPaths = builtins.attrValues config.services;
};
s6db = stdenv.mkDerivation {
name = "make-s6-db";
s6db = stdenvNoCC.mkDerivation {
name = "s6-rc-db";
nativeBuildInputs = [pkgs.buildPackages.s6-rc];
builder = writeText "find-s6-services" ''
source $stdenv/setup

7
run-tests.sh Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/env bash
export TMPDIR=${TMPDIR-/tmp}
for i in tests/*/run.sh; do
echo $i
$i
done

22
tests/smoke/run.sh Executable file
View File

@ -0,0 +1,22 @@
set -e
NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build -I liminix-config=./tests/smoke/configuration.nix -o smoke.img
TESTS=$(cat <<"EOF"
trap 'echo "command $(eval echo $BASH_COMMAND) failed with exit code $?"; exit $?' ERR
dest_path=${TMPDIR}/smoke.img-$$
echo $dest_path
unsquashfs -q -d $dest_path smoke.img
cd $dest_path;
db=*-s6-rc-db/compiled/
test -d $db
chmod -R +w $db
# check we have closure of config.services (lo.link.service exists only
# as a dependency)
test "$(s6-rc-db -c $db type lo.link.service)" = "oneshot"
echo OK
EOF
)
nix-shell -p s6-rc -p squashfsTools --run "$TESTS" || exit 1