commit b38b0bd932044ddceaa2ffe523c04de024fd87dc
parent 4b118bca19b29c9427f3c0cd9a0005695637f46e
Author: Daniel Barlow <dan@telent.net>
Date: Tue, 20 Sep 2022 15:22:37 +0100
add rudimentary test harness, turn example-configuration into a test
Diffstat:
4 files changed, 32 insertions(+), 3 deletions(-)
diff --git 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
@@ -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
diff --git a/tests/smoke/run.sh 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