tests: add test for creating machine on minimal clan

This commit is contained in:
DavHau
2024-06-09 02:38:19 -07:00
parent 1eaf6cec39
commit 07fb01d9db
6 changed files with 57 additions and 10 deletions

View File

@@ -179,12 +179,15 @@ def type_to_dict(t: Any, scope: str = "", type_map: dict[TypeVar, type] = {}) ->
raise JSchemaTypeError(
f"Usage of the Any type is not supported for API functions. In: {scope}"
)
if t is pathlib.Path:
return {
# TODO: maybe give it a pattern for URI
"type": "string",
}
if t is dict:
raise JSchemaTypeError(
"Error: generic dict type not supported. Use dict[str. Any] instead"
)
# Optional[T] gets internally transformed Union[T,NoneType]
if t is NoneType:

View File

@@ -9,7 +9,8 @@ from ..cmd import CmdOut, run
from ..errors import ClanError
from ..nix import nix_command, nix_shell
DEFAULT_TEMPLATE_URL: str = "git+https://git.clan.lol/clan/clan-core"
default_template_url: str = "git+https://git.clan.lol/clan/clan-core"
minimal_template_url: str = "git+https://git.clan.lol/clan/clan-core#templates.minimal"
@dataclass
@@ -21,7 +22,9 @@ class CreateClanResponse:
@API.register
def create_clan(directory: Path, template_url: str) -> CreateClanResponse:
def create_clan(
directory: Path, template_url: str = minimal_template_url
) -> CreateClanResponse:
if not directory.exists():
directory.mkdir()
else:
@@ -78,7 +81,7 @@ def register_create_parser(parser: argparse.ArgumentParser) -> None:
"--url",
type=str,
help="url to the clan template",
default=DEFAULT_TEMPLATE_URL,
default=default_template_url,
)
parser.add_argument(
"path", type=Path, help="Path to the clan directory", default=Path(".")

View File

@@ -2,6 +2,7 @@ import argparse
import logging
from dataclasses import dataclass
from pathlib import Path
from typing import Any
from clan_cli.api import API
from clan_cli.config.machine import set_config_for_machine
@@ -12,7 +13,7 @@ log = logging.getLogger(__name__)
@dataclass
class MachineCreateRequest:
name: str
config: dict[str, int]
config: dict[str, Any]
@API.register

View File

@@ -12,7 +12,7 @@ log = logging.getLogger(__name__)
@API.register
def list_machines(flake_url: str | Path, debug: bool) -> list[str]:
def list_machines(flake_url: str | Path, debug: bool = False) -> list[str]:
config = nix_config()
system = config["system"]
cmd = nix_eval(