Merge pull request 'drop clan_flake fixture' (#289) from Mic92-clan-fixture into main
This commit is contained in:
commit
f9a5362245
@ -1,23 +0,0 @@
|
||||
from pathlib import Path
|
||||
from typing import Iterator
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def clan_flake(temporary_dir: Path, monkeypatch: pytest.MonkeyPatch) -> Iterator[Path]:
|
||||
flake = temporary_dir / "clan-flake"
|
||||
flake.mkdir()
|
||||
(flake / ".clan-flake").touch()
|
||||
(flake / "flake.nix").write_text(
|
||||
"""
|
||||
{
|
||||
description = "A flake for testing clan";
|
||||
inputs = {};
|
||||
outputs = { self }: {};
|
||||
}
|
||||
"""
|
||||
)
|
||||
monkeypatch.chdir(flake)
|
||||
monkeypatch.setenv("HOME", str(temporary_dir))
|
||||
yield flake
|
@ -6,7 +6,6 @@ sys.path.append(os.path.join(os.path.dirname(__file__), "helpers"))
|
||||
pytest_plugins = [
|
||||
"api",
|
||||
"temporary_dir",
|
||||
"clan_flake",
|
||||
"root",
|
||||
"age_keys",
|
||||
"sshd",
|
||||
|
0
pkgs/clan-cli/tests/machine_flake/.clan_flake
Normal file
0
pkgs/clan-cli/tests/machine_flake/.clan_flake
Normal file
@ -10,7 +10,7 @@ if TYPE_CHECKING:
|
||||
|
||||
def test_import_sops(
|
||||
test_root: Path,
|
||||
clan_flake: Path,
|
||||
machine_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, clan_flake: Path) -> None:
|
||||
def test_machines(api: TestClient, machine_flake: Path) -> None:
|
||||
response = api.get("/api/machines")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"machines": []}
|
||||
|
@ -4,7 +4,9 @@ import pytest
|
||||
from cli import Cli
|
||||
|
||||
|
||||
def test_machine_subcommands(clan_flake: Path, capsys: pytest.CaptureFixture) -> None:
|
||||
def test_machine_subcommands(
|
||||
machine_flake: Path, capsys: pytest.CaptureFixture
|
||||
) -> None:
|
||||
cli = Cli()
|
||||
cli.run(["machines", "create", "machine1"])
|
||||
|
||||
|
@ -8,13 +8,13 @@ from host_group import HostGroup
|
||||
|
||||
|
||||
def test_update(
|
||||
clan_flake: Path, host_group: HostGroup, monkeypatch: pytest.MonkeyPatch
|
||||
machine_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"] = clan_flake
|
||||
host.meta["flake_uri"] = machine_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,
|
||||
clan_flake: Path,
|
||||
machine_flake: Path,
|
||||
capsys: pytest.CaptureFixture,
|
||||
age_keys: list["KeyPair"],
|
||||
) -> None:
|
||||
cli = Cli()
|
||||
sops_folder = clan_flake / "sops"
|
||||
sops_folder = machine_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(
|
||||
clan_flake: Path, capsys: pytest.CaptureFixture, age_keys: list["KeyPair"]
|
||||
machine_flake: Path, capsys: pytest.CaptureFixture, age_keys: list["KeyPair"]
|
||||
) -> None:
|
||||
_test_identities("users", clan_flake, capsys, age_keys)
|
||||
_test_identities("users", machine_flake, capsys, age_keys)
|
||||
|
||||
|
||||
def test_machines(
|
||||
clan_flake: Path, capsys: pytest.CaptureFixture, age_keys: list["KeyPair"]
|
||||
machine_flake: Path, capsys: pytest.CaptureFixture, age_keys: list["KeyPair"]
|
||||
) -> None:
|
||||
_test_identities("machines", clan_flake, capsys, age_keys)
|
||||
_test_identities("machines", machine_flake, capsys, age_keys)
|
||||
|
||||
|
||||
def test_groups(
|
||||
clan_flake: Path, capsys: pytest.CaptureFixture, age_keys: list["KeyPair"]
|
||||
machine_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(clan_flake / "sops" / "groups")
|
||||
groups = os.listdir(machine_flake / "sops" / "groups")
|
||||
assert len(groups) == 0
|
||||
|
||||
|
||||
@ -114,7 +114,7 @@ def use_key(key: str, monkeypatch: pytest.MonkeyPatch) -> Iterator[None]:
|
||||
|
||||
|
||||
def test_secrets(
|
||||
clan_flake: Path,
|
||||
machine_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(clan_flake / ".." / "age.key"))
|
||||
monkeypatch.setenv("SOPS_AGE_KEY_FILE", str(machine_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