2023-09-22 16:32:09 +00:00
|
|
|
import json
|
|
|
|
import subprocess
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
from cli import Cli
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
temporary_dir: Path,
|
|
|
|
capsys: pytest.CaptureFixture,
|
|
|
|
cli: Cli,
|
2023-09-22 16:32:09 +00:00
|
|
|
) -> None:
|
|
|
|
monkeypatch.chdir(temporary_dir)
|
|
|
|
cli.run(["create"])
|
|
|
|
assert (temporary_dir / ".clan-flake").exists()
|
|
|
|
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")
|
2023-09-22 17:17:45 +00:00
|
|
|
# configure machine1
|
|
|
|
capsys.readouterr()
|
|
|
|
cli.run(["config", "--machine", "machine1", "services.openssh.enable"])
|
|
|
|
capsys.readouterr()
|
|
|
|
cli.run(["config", "--machine", "machine1", "services.openssh.enable", "true"])
|