summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-08-02 22:58:39 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-08-02 23:13:38 +0200
commit1de8edac1a868ce564dbcb28f5ed52fab4f8ec61 (patch)
treeb9c15dfc9827310e142115ea1b8b91ab3a36052e
parenttest(tests): Init infrastructure (diff)
downloadnixos-server-1de8edac1a868ce564dbcb28f5ed52fab4f8ec61.tar.gz
nixos-server-1de8edac1a868ce564dbcb28f5ed52fab4f8ec61.zip
build(tests): Add complementary scripts
Diffstat (limited to '')
-rwxr-xr-xscripts/lint_missing_tests.sh66
-rwxr-xr-xscripts/test_interactive.sh15
2 files changed, 81 insertions, 0 deletions
diff --git a/scripts/lint_missing_tests.sh b/scripts/lint_missing_tests.sh
new file mode 100755
index 0000000..dffb86e
--- /dev/null
+++ b/scripts/lint_missing_tests.sh
@@ -0,0 +1,66 @@
+#!/usr/bin/env sh
+
+# Shell library {{{
+die() {
+    echo "$1" >&2
+    exit 1
+}
+warning() {
+    eprintln "\033[1;91m==> WARNING:\033[0m" "\033[1;93m$*\033[0m"
+}
+eprintln() {
+    >&2 println "$@"
+}
+println() {
+    printf "$*\n"
+}
+# }}}
+
+test_template() {
+    test_name="$(basename "$1")"
+    cat <<EOF
+{pkgs}:
+pkgs.testers.runNixOSTest {
+  name = "$test_name";
+
+  nodes.server = { pkgs, ... }: {
+    networking = {
+      firewall = {
+        allowedTCPPorts = [ 80 ];
+      };
+    };
+    services.nginx = {
+      enable = true;
+      virtualHosts."server" = {};
+    };
+  };
+
+  nodes.client = { pkgs, ... }: {
+    environment.systemPackages = with pkgs; [
+      curl
+    ];
+  };
+
+  testScript = ''
+    server.wait_for_unit("default.target")
+    client.wait_for_unit("default.target")
+    client.succeed("curl http://server/ | grep -o \"Welcome to nginx!\"")
+  '';
+}
+EOF
+}
+
+cd "$(dirname "$0")/.." || die "Bug: The root dir does not exist"
+
+fd default.nix ./modules | while IFS= read -r dir; do
+    mkdir --parents "tests/$(dirname "$dir")"
+
+    test_file="$(realpath --relative-to="$(pwd)" "tests/$(dirname "$dir")/test.nix")"
+    dir="$(realpath --relative-to="$(pwd)" "$dir")"
+
+    if [ "$1" = generate ]; then
+        test_template "$dir" >"$test_file"
+    else
+        warning "'$dir' is missing it's test (at '$test_file')!"
+    fi
+done
diff --git a/scripts/test_interactive.sh b/scripts/test_interactive.sh
new file mode 100755
index 0000000..d309799
--- /dev/null
+++ b/scripts/test_interactive.sh
@@ -0,0 +1,15 @@
+#!/usr/bin/env sh
+
+tast_target="$1"
+
+[ -z "$test_target" ] && {
+    echo "You need to select a test target!" 1>&2
+    echo "Usage: test_interactive TEST_TARGET" 1>&2
+    exit 1
+}
+
+nix build .#checks.x86_64-linux."$tast_target".driver
+
+./result/bin/nixos-test-driver --interactive
+
+# vim: ft=sh