Merge pull request 'rename machine_flake back to clan_flake' (#290) from Mic92-clan-fixture into main
This commit is contained in:
commit
28bc5fa058
@ -0,0 +1,34 @@
|
||||
import shutil
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from typing import Generator
|
||||
|
||||
import pytest
|
||||
|
||||
from clan_cli.dirs import nixpkgs_source
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def monkeymodule() -> Generator[pytest.MonkeyPatch, None, None]:
|
||||
with pytest.MonkeyPatch.context() as mp:
|
||||
yield mp
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def clan_flake(monkeymodule: pytest.MonkeyPatch) -> Generator[Path, None, None]:
|
||||
template = Path(__file__).parent / "clan_flake"
|
||||
# copy the template to a new temporary location
|
||||
with tempfile.TemporaryDirectory() as tmpdir_:
|
||||
home = Path(tmpdir_)
|
||||
flake = home / "clan_flake"
|
||||
shutil.copytree(template, flake)
|
||||
# in the flake.nix file replace the string __CLAN_URL__ with the the clan flake
|
||||
# provided by get_clan_flake_toplevel
|
||||
flake_nix = flake / "flake.nix"
|
||||
flake_nix.write_text(
|
||||
flake_nix.read_text().replace("__NIXPKGS__", str(nixpkgs_source()))
|
||||
)
|
||||
# check that an empty config is returned if no json file exists
|
||||
monkeymodule.chdir(flake)
|
||||
monkeymodule.setenv("HOME", str(home))
|
||||
yield flake
|
@ -12,5 +12,5 @@ pytest_plugins = [
|
||||
"command",
|
||||
"ports",
|
||||
"host_group",
|
||||
"machine_flake",
|
||||
"clan_flake",
|
||||
]
|
||||
|
@ -1,34 +0,0 @@
|
||||
import shutil
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from typing import Generator
|
||||
|
||||
import pytest
|
||||
|
||||
from clan_cli.dirs import nixpkgs_source
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def monkeymodule() -> Generator[pytest.MonkeyPatch, None, None]:
|
||||
with pytest.MonkeyPatch.context() as mp:
|
||||
yield mp
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def machine_flake(monkeymodule: pytest.MonkeyPatch) -> Generator[Path, None, None]:
|
||||
template = Path(__file__).parent / "machine_flake"
|
||||
# copy the template to a new temporary location
|
||||
with tempfile.TemporaryDirectory() as tmpdir_:
|
||||
home = Path(tmpdir_)
|
||||
flake = home / "machine_flake"
|
||||
shutil.copytree(template, flake)
|
||||
# in the flake.nix file replace the string __CLAN_URL__ with the the clan flake
|
||||
# provided by get_clan_flake_toplevel
|
||||
flake_nix = flake / "flake.nix"
|
||||
flake_nix.write_text(
|
||||
flake_nix.read_text().replace("__NIXPKGS__", str(nixpkgs_source()))
|
||||
)
|
||||
# check that an empty config is returned if no json file exists
|
||||
monkeymodule.chdir(flake)
|
||||
monkeymodule.setenv("HOME", str(home))
|
||||
yield flake
|
@ -50,7 +50,7 @@ def test_set_some_option(
|
||||
|
||||
|
||||
def test_configure_machine(
|
||||
machine_flake: Path,
|
||||
clan_flake: Path,
|
||||
temporary_dir: Path,
|
||||
capsys: pytest.CaptureFixture,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
|
@ -10,7 +10,7 @@ if TYPE_CHECKING:
|
||||
|
||||
def test_import_sops(
|
||||
test_root: Path,
|
||||
machine_flake: Path,
|
||||
clan_flake: Path,
|
||||
capsys: pytest.CaptureFixture,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
age_keys: list["KeyPair"],
|
||||
|
@ -3,7 +3,7 @@ from pathlib import Path
|
||||
from api import TestClient
|
||||
|
||||
|
||||
def test_machines(api: TestClient, machine_flake: Path) -> None:
|
||||
def test_machines(api: TestClient, clan_flake: Path) -> None:
|
||||
response = api.get("/api/machines")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"machines": []}
|
||||
@ -21,7 +21,7 @@ def test_machines(api: TestClient, machine_flake: Path) -> None:
|
||||
assert response.json() == {"machines": [{"name": "test", "status": "unknown"}]}
|
||||
|
||||
|
||||
def test_configure_machine(api: TestClient, machine_flake: Path) -> None:
|
||||
def test_configure_machine(api: TestClient, clan_flake: Path) -> None:
|
||||
# ensure error 404 if machine does not exist when accessing the config
|
||||
response = api.get("/api/machines/machine1/config")
|
||||
assert response.status_code == 404
|
||||
|
@ -4,9 +4,7 @@ import pytest
|
||||
from cli import Cli
|
||||
|
||||
|
||||
def test_machine_subcommands(
|
||||
machine_flake: Path, capsys: pytest.CaptureFixture
|
||||
) -> None:
|
||||
def test_machine_subcommands(clan_flake: Path, capsys: pytest.CaptureFixture) -> None:
|
||||
cli = Cli()
|
||||
cli.run(["machines", "create", "machine1"])
|
||||
|
||||
|
@ -3,6 +3,6 @@ from pathlib import Path
|
||||
from clan_cli.config import machine
|
||||
|
||||
|
||||
def test_schema_for_machine(machine_flake: Path) -> None:
|
||||
schema = machine.schema_for_machine("machine1", machine_flake)
|
||||
def test_schema_for_machine(clan_flake: Path) -> None:
|
||||
schema = machine.schema_for_machine("machine1", clan_flake)
|
||||
assert "properties" in schema
|
||||
|
@ -8,13 +8,13 @@ from host_group import HostGroup
|
||||
|
||||
|
||||
def test_update(
|
||||
machine_flake: Path, host_group: HostGroup, monkeypatch: pytest.MonkeyPatch
|
||||
clan_flake: Path, host_group: HostGroup, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
assert len(host_group.hosts) == 1
|
||||
host = host_group.hosts[0]
|
||||
|
||||
with TemporaryDirectory() as tmpdir:
|
||||
host.meta["flake_uri"] = machine_flake
|
||||
host.meta["flake_uri"] = clan_flake
|
||||
host.meta["flake_path"] = str(Path(tmpdir) / "rsync-target")
|
||||
host.ssh_options["SendEnv"] = "REALPATH"
|
||||
bin = Path(tmpdir).joinpath("bin")
|
||||
|
@ -14,12 +14,12 @@ if TYPE_CHECKING:
|
||||
|
||||
def _test_identities(
|
||||
what: str,
|
||||
machine_flake: Path,
|
||||
clan_flake: Path,
|
||||
capsys: pytest.CaptureFixture,
|
||||
age_keys: list["KeyPair"],
|
||||
) -> None:
|
||||
cli = Cli()
|
||||
sops_folder = machine_flake / "sops"
|
||||
sops_folder = clan_flake / "sops"
|
||||
|
||||
cli.run(["secrets", what, "add", "foo", age_keys[0].pubkey])
|
||||
assert (sops_folder / what / "foo" / "key.json").exists()
|
||||
@ -60,19 +60,19 @@ def _test_identities(
|
||||
|
||||
|
||||
def test_users(
|
||||
machine_flake: Path, capsys: pytest.CaptureFixture, age_keys: list["KeyPair"]
|
||||
clan_flake: Path, capsys: pytest.CaptureFixture, age_keys: list["KeyPair"]
|
||||
) -> None:
|
||||
_test_identities("users", machine_flake, capsys, age_keys)
|
||||
_test_identities("users", clan_flake, capsys, age_keys)
|
||||
|
||||
|
||||
def test_machines(
|
||||
machine_flake: Path, capsys: pytest.CaptureFixture, age_keys: list["KeyPair"]
|
||||
clan_flake: Path, capsys: pytest.CaptureFixture, age_keys: list["KeyPair"]
|
||||
) -> None:
|
||||
_test_identities("machines", machine_flake, capsys, age_keys)
|
||||
_test_identities("machines", clan_flake, capsys, age_keys)
|
||||
|
||||
|
||||
def test_groups(
|
||||
machine_flake: Path, capsys: pytest.CaptureFixture, age_keys: list["KeyPair"]
|
||||
clan_flake: Path, capsys: pytest.CaptureFixture, age_keys: list["KeyPair"]
|
||||
) -> None:
|
||||
cli = Cli()
|
||||
capsys.readouterr() # empty the buffer
|
||||
@ -100,7 +100,7 @@ def test_groups(
|
||||
|
||||
cli.run(["secrets", "groups", "remove-user", "group1", "user1"])
|
||||
cli.run(["secrets", "groups", "remove-machine", "group1", "machine1"])
|
||||
groups = os.listdir(machine_flake / "sops" / "groups")
|
||||
groups = os.listdir(clan_flake / "sops" / "groups")
|
||||
assert len(groups) == 0
|
||||
|
||||
|
||||
@ -114,7 +114,7 @@ def use_key(key: str, monkeypatch: pytest.MonkeyPatch) -> Iterator[None]:
|
||||
|
||||
|
||||
def test_secrets(
|
||||
machine_flake: Path,
|
||||
clan_flake: Path,
|
||||
capsys: pytest.CaptureFixture,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
age_keys: list["KeyPair"],
|
||||
@ -125,7 +125,7 @@ def test_secrets(
|
||||
assert capsys.readouterr().out == ""
|
||||
|
||||
monkeypatch.setenv("SOPS_NIX_SECRET", "foo")
|
||||
monkeypatch.setenv("SOPS_AGE_KEY_FILE", str(machine_flake / ".." / "age.key"))
|
||||
monkeypatch.setenv("SOPS_AGE_KEY_FILE", str(clan_flake / ".." / "age.key"))
|
||||
cli.run(["secrets", "key", "generate"])
|
||||
capsys.readouterr() # empty the buffer
|
||||
cli.run(["secrets", "key", "show"])
|
||||
|
Loading…
Reference in New Issue
Block a user