summaryrefslogtreecommitdiffstatshomepage
path: root/tests/test_canonical_defaults.py
blob: 6ddb767a976261e593d8e2fc4a464da36b57d2be (plain) (blame)
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
59
60
import json
import subprocess
import unittest
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]


def chezmoi(role, *args):
    return subprocess.check_output(
        [
            "chezmoi",
            "--config",
            "/dev/null",
            "--config-format",
            "toml",
            "--override-data",
            json.dumps({"machineRole": role}),
            "-S",
            str(ROOT),
            *args,
        ],
        text=True,
    )


class DefaultTests(unittest.TestCase):
    def test_corporate_defaults_use_managed_launchers(self):
        rendered = chezmoi(
            "canonical",
            "execute-template",
            "--file",
            str(ROOT / "dot_config/mimeapps.list.tmpl"),
        )
        for value in (
            "inode/directory=dotfiles-yazi.desktop",
            "text/plain=dotfiles-nvim.desktop",
            "image/png=imv.desktop",
            "application/pdf=org.pwmt.zathura.desktop",
        ):
            self.assertIn(value, rendered)

    def test_launchers_are_corporate_only_and_use_ghostty(self):
        for role in ("host", "vm", "canonical"):
            files = chezmoi(role, "managed", "--include=files").splitlines()
            for app in ("yazi", "nvim"):
                target = f".local/share/applications/dotfiles-{app}.desktop"
                self.assertEqual(target in files, role == "canonical")
                entry = chezmoi(
                    role,
                    "execute-template",
                    "--file",
                    str(
                        ROOT
                        / f"dot_local/share/applications/dotfiles-{app}.desktop.tmpl"
                    ),
                )
                self.assertIn("Exec=/snap/bin/ghostty -e ", entry)
                self.assertIn(f'/.nix-profile/bin/{app}"', entry)
                self.assertIn("Terminal=false", entry)