2023-09-22 16:32:09 +00:00
|
|
|
import json
|
|
|
|
import subprocess
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
from cli import Cli
|
2023-10-21 15:19:06 +00:00
|
|
|
|
2023-09-22 16:32:09 +00:00
|
|
|
|
2023-09-22 17:17:45 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def cli() -> Cli:
|
|
|
|
return Cli()
|
|
|
|
|
|
|
|
|
2023-09-22 16:32:09 +00:00
|
|
|
@pytest.mark.impure
|
2023-10-04 09:01:12 +00:00
|
|
|
def test_create_flake(
|
2023-09-22 17:17:45 +00:00
|
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
|
|
capsys: pytest.CaptureFixture,
|
2023-10-19 23:11:32 +00:00
|
|
|
temporary_home: Path,
|
2023-09-22 17:17:45 +00:00
|
|
|
cli: Cli,
|
2024-05-31 15:58:42 +00:00
|
|
|
clan_core: Path,
|
2023-09-22 16:32:09 +00:00
|
|
|
) -> None:
|
2023-11-15 13:28:40 +00:00
|
|
|
flake_dir = temporary_home / "test-flake"
|
2023-10-19 23:11:32 +00:00
|
|
|
|
2024-05-31 15:58:42 +00:00
|
|
|
url = f"{clan_core}#default"
|
|
|
|
cli.run(["flakes", "create", str(flake_dir), f"--url={url}"])
|
2023-10-09 12:01:34 +00:00
|
|
|
assert (flake_dir / ".clan-flake").exists()
|
|
|
|
monkeypatch.chdir(flake_dir)
|
2023-11-15 13:28:40 +00:00
|
|
|
cli.run(["machines", "create", "machine1"])
|
2023-09-22 16:32:09 +00:00
|
|
|
capsys.readouterr() # flush cache
|
2023-10-19 23:11:32 +00:00
|
|
|
|
2024-05-26 12:17:17 +00:00
|
|
|
# create a hardware-configuration.nix that doesn't throw an eval error
|
|
|
|
|
|
|
|
for patch_machine in ["jon", "sara"]:
|
|
|
|
with open(
|
|
|
|
flake_dir / "machines" / f"{patch_machine}/hardware-configuration.nix", "w"
|
|
|
|
) as hw_config_nix:
|
|
|
|
hw_config_nix.write("{}")
|
|
|
|
|
2023-11-15 13:28:40 +00:00
|
|
|
cli.run(["machines", "list"])
|
2023-09-22 16:32:09 +00:00
|
|
|
assert "machine1" in capsys.readouterr().out
|
|
|
|
flake_show = subprocess.run(
|
|
|
|
["nix", "flake", "show", "--json"],
|
|
|
|
check=True,
|
|
|
|
capture_output=True,
|
|
|
|
text=True,
|
|
|
|
)
|
|
|
|
flake_outputs = json.loads(flake_show.stdout)
|
|
|
|
try:
|
|
|
|
flake_outputs["nixosConfigurations"]["machine1"]
|
|
|
|
except KeyError:
|
|
|
|
pytest.fail("nixosConfigurations.machine1 not found in flake outputs")
|
2024-05-31 15:22:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.impure
|
|
|
|
def test_ui_template(
|
|
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
|
|
capsys: pytest.CaptureFixture,
|
|
|
|
temporary_home: Path,
|
|
|
|
cli: Cli,
|
2024-05-31 15:58:42 +00:00
|
|
|
clan_core: Path,
|
2024-05-31 15:22:38 +00:00
|
|
|
) -> None:
|
|
|
|
flake_dir = temporary_home / "test-flake"
|
2024-05-31 15:58:42 +00:00
|
|
|
url = f"{clan_core}#empty"
|
|
|
|
cli.run(["flakes", "create", str(flake_dir), f"--url={url}"])
|
2024-05-31 15:22:38 +00:00
|
|
|
assert (flake_dir / ".clan-flake").exists()
|
|
|
|
monkeypatch.chdir(flake_dir)
|
|
|
|
cli.run(["machines", "create", "machine1"])
|
|
|
|
capsys.readouterr() # flush cache
|
|
|
|
|
|
|
|
cli.run(["machines", "list"])
|
|
|
|
assert "machine1" in capsys.readouterr().out
|
|
|
|
flake_show = subprocess.run(
|
|
|
|
["nix", "flake", "show", "--json"],
|
|
|
|
check=True,
|
|
|
|
capture_output=True,
|
|
|
|
text=True,
|
|
|
|
)
|
|
|
|
flake_outputs = json.loads(flake_show.stdout)
|
|
|
|
try:
|
|
|
|
flake_outputs["nixosConfigurations"]["machine1"]
|
|
|
|
except KeyError:
|
|
|
|
pytest.fail("nixosConfigurations.machine1 not found in flake outputs")
|