aboutsummaryrefslogtreecommitdiff
path: root/tests/installer-steps/test_required_software.py
blob: 85b01d8dfe698a3970d811c2a3829ab7f66bb69c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""Test that install_required_software declares the expected base packages.

inetutils provides /usr/bin/ftp, which TRAMP's /ftp: method (ange-ftp) shells
out to; Arch ships no command-line ftp client by default. It must be in the
base install so every machine gets it (Craig's dirvish config has an FTP
quick-access entry that depends on it).

Method mirrors test_orchestrators: sed-extract install_required_software from
the real `archsetup`, stub pacman_install as a recorder that echoes the package
name, run, and assert membership.

Run from repo root:
    python3 -m unittest tests.installer-steps.test_required_software
"""

import os
import subprocess
import textwrap
import unittest

REPO_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
ARCHSETUP = os.path.join(REPO_ROOT, "archsetup")


def required_packages():
    """Return (exit_code, [package, ...]) declared by install_required_software."""
    script = textwrap.dedent(f"""\
        display() {{ :; }}
        pacman_install() {{ echo "$1"; }}
        source <(sed -n '/^install_required_software() {{/,/^}}/p' "{ARCHSETUP}")
        install_required_software
    """)
    result = subprocess.run(
        ["bash", "-c", script], capture_output=True, text=True, timeout=10,
    )
    return result.returncode, result.stdout.split()


class RequiredSoftware(unittest.TestCase):
    def test_installs_inetutils_for_ftp(self):
        rc, pkgs = required_packages()
        self.assertEqual(rc, 0)
        self.assertIn(
            "inetutils", pkgs,
            "inetutils (provides /usr/bin/ftp for TRAMP's /ftp: method) must be "
            "in the base install",
        )

    def test_core_base_packages_present(self):
        # Guard a few load-bearing entries so a bad edit to the list is caught.
        rc, pkgs = required_packages()
        self.assertEqual(rc, 0)
        for p in ("base-devel", "git", "stow", "openssh", "curl"):
            self.assertIn(p, pkgs, f"{p} dropped from the base install")


if __name__ == "__main__":
    unittest.main()