clan-core/pkgs/clan-cli/tests/test_vms_cli.py

44 lines
1.0 KiB
Python
Raw Normal View History

2023-10-03 15:18:36 +00:00
import os
2023-10-05 13:56:15 +00:00
from typing import TYPE_CHECKING
2023-10-23 20:34:43 +00:00
2023-10-03 15:18:36 +00:00
import pytest
from cli import Cli
2023-10-23 20:34:43 +00:00
from fixtures_flakes import FlakeForTest
2023-10-03 15:18:36 +00:00
2023-10-05 13:56:15 +00:00
if TYPE_CHECKING:
from age_keys import KeyPair
2023-10-03 15:18:36 +00:00
no_kvm = not os.path.exists("/dev/kvm")
@pytest.mark.impure
2023-10-23 20:34:43 +00:00
def test_inspect(
test_flake_with_core: FlakeForTest, capsys: pytest.CaptureFixture
) -> None:
2023-10-03 15:18:36 +00:00
cli = Cli()
2023-11-15 13:28:40 +00:00
cli.run(["--flake", str(test_flake_with_core.path), "vms", "inspect", "vm1"])
2023-10-03 15:18:36 +00:00
out = capsys.readouterr() # empty the buffer
assert "Cores" in out.out
@pytest.mark.skipif(no_kvm, reason="Requires KVM")
@pytest.mark.impure
2023-11-24 13:52:38 +00:00
def test_run(
2023-10-05 13:56:15 +00:00
monkeypatch: pytest.MonkeyPatch,
2023-10-23 20:31:12 +00:00
test_flake_with_core: FlakeForTest,
2023-10-05 13:56:15 +00:00
age_keys: list["KeyPair"],
) -> None:
2023-10-23 20:31:12 +00:00
monkeypatch.chdir(test_flake_with_core.path)
2023-10-05 13:56:15 +00:00
monkeypatch.setenv("SOPS_AGE_KEY", age_keys[0].privkey)
2023-10-03 15:18:36 +00:00
cli = Cli()
2023-10-23 20:34:43 +00:00
cli.run(
[
"secrets",
"users",
"add",
"user1",
age_keys[0].pubkey,
]
)
2023-11-24 13:52:38 +00:00
cli.run(["vms", "run", "vm1"])