From 00fb8c1d21581972e0e4a947dd131efe7b90b35c Mon Sep 17 00:00:00 2001 From: catborise Date: Fri, 6 Nov 2026 11:18:11 +0300 Subject: [PATCH] test: the installer library's shell tests run with the suite conf/test_install_lib.sh tested conf/install-lib.sh, but no CI step or test ran it. It moves to webvirtcloud/tests/sh/install_lib.test.sh, takes the library's path as its argument, and test_install_lib runs it in bash, as the JS tests run in node. --- conf/install-lib.sh | 2 +- .../tests/sh/install_lib.test.sh | 6 +++--- webvirtcloud/tests/test_install_lib.py | 20 +++++++++++++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) rename conf/test_install_lib.sh => webvirtcloud/tests/sh/install_lib.test.sh (95%) create mode 100644 webvirtcloud/tests/test_install_lib.py diff --git a/conf/install-lib.sh b/conf/install-lib.sh index b8fbb8b8..c1b6f6fe 100755 --- a/conf/install-lib.sh +++ b/conf/install-lib.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # Idempotent installer primitives. Sourcing this file has NO side effects; -# it only defines functions, so it can be unit-tested (conf/test_install_lib.sh). +# it only defines functions, so it can be unit-tested (webvirtcloud/tests/sh/install_lib.test.sh). # Create /secret_key (mode 600) only if missing or empty; keep an # existing key. A blank key would make Django fail to boot, so an empty file is diff --git a/conf/test_install_lib.sh b/webvirtcloud/tests/sh/install_lib.test.sh similarity index 95% rename from conf/test_install_lib.sh rename to webvirtcloud/tests/sh/install_lib.test.sh index 89eec413..36c8e1b8 100755 --- a/conf/test_install_lib.sh +++ b/webvirtcloud/tests/sh/install_lib.test.sh @@ -1,9 +1,9 @@ #!/usr/bin/env bash -# Unit tests for conf/install-lib.sh. Run: bash conf/test_install_lib.sh +# Unit tests for conf/install-lib.sh, run by webvirtcloud/tests/test_install_lib.py: +# bash webvirtcloud/tests/sh/install_lib.test.sh conf/install-lib.sh set -u -here="$(cd "$(dirname "$0")" && pwd)" # shellcheck source=/dev/null -. "$here/install-lib.sh" +. "$1" fail=0 check() { if eval "$2"; then echo "ok - $1"; else echo "NOT ok - $1"; fail=1; fi; } diff --git a/webvirtcloud/tests/test_install_lib.py b/webvirtcloud/tests/test_install_lib.py new file mode 100644 index 00000000..8d67ad2d --- /dev/null +++ b/webvirtcloud/tests/test_install_lib.py @@ -0,0 +1,20 @@ +"""The installer's functions (conf/install-lib.sh), tested in bash.""" + +import shutil +import subprocess +import unittest +from pathlib import Path + +from django.conf import settings + +BASE = Path(settings.BASE_DIR) + + +class InstallLibTestCase(unittest.TestCase): + @unittest.skipUnless(shutil.which("bash"), "bash is not installed") + def test_install_lib(self): + result = subprocess.run( + ["bash", str(BASE / "webvirtcloud/tests/sh/install_lib.test.sh"), str(BASE / "conf/install-lib.sh")], + capture_output=True, text=True, timeout=120, + ) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr)