From b38b0bd932044ddceaa2ffe523c04de024fd87dc Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Tue, 20 Sep 2022 15:22:37 +0100 Subject: [PATCH] add rudimentary test harness, turn example-configuration into a test --- make-image.nix | 6 ++--- run-tests.sh | 7 ++++++ .../smoke/configuration.nix | 0 tests/smoke/run.sh | 22 +++++++++++++++++++ 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100755 run-tests.sh rename example-configuration.nix => tests/smoke/configuration.nix (100%) create mode 100755 tests/smoke/run.sh diff --git a/make-image.nix b/make-image.nix index bcd6b48..003dcea 100644 --- a/make-image.nix +++ b/make-image.nix @@ -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 diff --git a/run-tests.sh b/run-tests.sh new file mode 100755 index 0000000..4934d8d --- /dev/null +++ b/run-tests.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +export TMPDIR=${TMPDIR-/tmp} +for i in tests/*/run.sh; do + echo $i + $i +done diff --git a/example-configuration.nix b/tests/smoke/configuration.nix similarity index 100% rename from example-configuration.nix rename to tests/smoke/configuration.nix diff --git a/tests/smoke/run.sh b/tests/smoke/run.sh new file mode 100755 index 0000000..01114d2 --- /dev/null +++ b/tests/smoke/run.sh @@ -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