impure-tests: migrate bash to pytest and fix stuff
This commit is contained in:
@@ -6,6 +6,8 @@ from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
from typing import Any
|
||||
|
||||
from clan_cli.nix import nix_shell
|
||||
|
||||
from ..dirs import get_clan_flake_toplevel
|
||||
from ..errors import ClanError
|
||||
from ..ssh import parse_deployment_address
|
||||
@@ -47,7 +49,8 @@ secrets={shlex.quote(str(secrets_dir))}
|
||||
{generator}
|
||||
"""
|
||||
try:
|
||||
subprocess.run(["bash", "-c", text], check=True)
|
||||
cmd = nix_shell(["bash"], ["bash", "-c", text])
|
||||
subprocess.run(cmd, check=True)
|
||||
except subprocess.CalledProcessError:
|
||||
msg = "failed to the following command:\n"
|
||||
msg += text
|
||||
|
||||
@@ -32,6 +32,6 @@ mkShell {
|
||||
register-python-argcomplete --shell fish clan > $tmp_path/share/fish/vendor_completions.d/clan.fish
|
||||
register-python-argcomplete --shell bash clan > $tmp_path/share/bash-completion/completions/clan
|
||||
|
||||
${clan-cli}/bin/clan machines create example
|
||||
./bin/clan machines create example
|
||||
'';
|
||||
}
|
||||
|
||||
31
pkgs/clan-cli/tests/end_to_end/test_basics.py
Normal file
31
pkgs/clan-cli/tests/end_to_end/test_basics.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import json
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from cli import Cli
|
||||
|
||||
|
||||
@pytest.mark.impure
|
||||
def test_basics(
|
||||
monkeypatch: pytest.MonkeyPatch, temporary_dir: Path, capsys: pytest.CaptureFixture
|
||||
) -> None:
|
||||
monkeypatch.chdir(temporary_dir)
|
||||
cli = Cli()
|
||||
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")
|
||||
@@ -106,7 +106,10 @@ exec {bash} -l "${{@}}"
|
||||
|
||||
@pytest.fixture
|
||||
def sshd(
|
||||
sshd_config: SshdConfig, command: "Command", unused_tcp_port: "PortFunction"
|
||||
sshd_config: SshdConfig,
|
||||
command: "Command",
|
||||
unused_tcp_port: "PortFunction",
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> Iterator[Sshd]:
|
||||
import subprocess
|
||||
|
||||
@@ -121,7 +124,7 @@ def sshd(
|
||||
proc = command.run(
|
||||
[sshd, "-f", str(sshd_config.path), "-D", "-p", str(port)], extra_env=env
|
||||
)
|
||||
|
||||
monkeypatch.delenv("SSH_AUTH_SOCK", raising=False)
|
||||
while True:
|
||||
print(sshd_config.path)
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user