Merge pull request 'pkgs/cli: Validate clan flake for clan machines list' (#4512) from kenji/ke-fix-list into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/4512
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import argparse
|
||||
import logging
|
||||
|
||||
from clan_lib.flake import Flake
|
||||
from clan_lib.flake import require_flake
|
||||
from clan_lib.machines.actions import list_machines
|
||||
|
||||
from clan_cli.completions import add_dynamic_completer, complete_tags
|
||||
@@ -10,7 +10,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def list_command(args: argparse.Namespace) -> None:
|
||||
flake: Flake = args.flake
|
||||
flake = require_flake(args.flake)
|
||||
|
||||
for name in list_machines(flake, opts={"filter": {"tags": args.tags}}):
|
||||
print(name)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import pytest
|
||||
from clan_lib.errors import ClanError
|
||||
|
||||
from clan_cli.tests import fixtures_flakes
|
||||
from clan_cli.tests.helpers import cli
|
||||
@@ -359,3 +360,12 @@ def list_mixed_tagged_untagged(
|
||||
assert "machine-with-tags" not in output.out
|
||||
assert "machine-without-tags" not in output.out
|
||||
assert output.out.strip() == ""
|
||||
|
||||
|
||||
def test_machines_list_require_flake_error() -> None:
|
||||
"""Test that machines list command fails when flake is required but not provided."""
|
||||
with pytest.raises(ClanError) as exc_info:
|
||||
cli.run(["machines", "list"])
|
||||
|
||||
error_message = str(exc_info.value)
|
||||
assert "flake" in error_message.lower()
|
||||
|
||||
Reference in New Issue
Block a user