1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-08 11:16:47 +00:00

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.
This commit is contained in:
catborise 2026-11-06 11:18:11 +03:00
parent 7be6be78f1
commit 00fb8c1d21
3 changed files with 24 additions and 4 deletions

View file

@ -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 <data_dir>/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

View file

@ -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; }

View file

@ -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)