refactor
This commit is contained in:
@@ -4,16 +4,20 @@ import pytest
|
||||
|
||||
from flow.core.errors import ConfigError, FlowError
|
||||
from flow.domain.packages.catalog import normalize_profile_entry, parse_catalog
|
||||
from flow.domain.packages.planning import plan_install
|
||||
from flow.domain.packages.resolution import (
|
||||
binary_template_context,
|
||||
detect_package_manager,
|
||||
pm_cask_install_command,
|
||||
pm_install_command,
|
||||
pm_update_command,
|
||||
resolve_binary_asset,
|
||||
resolve_download_url,
|
||||
resolve_extract_dir,
|
||||
resolve_source_name,
|
||||
resolve_spec,
|
||||
)
|
||||
from flow.domain.packages.models import PackageDef, ProfilePackageRef
|
||||
from flow.domain.packages.models import InstalledState, PackageDef, ProfilePackageRef
|
||||
|
||||
|
||||
class TestParseCatalog:
|
||||
@@ -77,6 +81,26 @@ class TestResolveSpec:
|
||||
assert result.name == "unknown"
|
||||
assert result.type == "binary"
|
||||
|
||||
def test_profile_object_overrides_catalog(self):
|
||||
catalog = {"docker": PackageDef(
|
||||
name="docker", type="pkg", sources={"apt": "docker-ce"},
|
||||
source=None, version=None, asset_pattern=None,
|
||||
platform_map={}, extract_dir=None, install={},
|
||||
post_install=None, allow_sudo=False,
|
||||
)}
|
||||
ref = ProfilePackageRef(
|
||||
name="docker",
|
||||
type=None,
|
||||
source=None,
|
||||
version=None,
|
||||
asset_pattern=None,
|
||||
post_install="sudo groupadd docker || true",
|
||||
allow_sudo=True,
|
||||
)
|
||||
result = resolve_spec(ref, catalog)
|
||||
assert result.post_install == "sudo groupadd docker || true"
|
||||
assert result.allow_sudo is True
|
||||
|
||||
|
||||
class TestResolveSourceName:
|
||||
def test_with_pm_mapping(self):
|
||||
@@ -125,6 +149,19 @@ class TestResolveBinaryAsset:
|
||||
assert "x64" in result
|
||||
assert "linux" in result
|
||||
|
||||
def test_double_brace_pattern_uses_platform_map_context(self):
|
||||
pkg = PackageDef(
|
||||
name="nvim", type="binary", sources={},
|
||||
source="github:neovim/neovim",
|
||||
version="0.10.4",
|
||||
asset_pattern="nvim-{{os}}-{{arch}}.tar.gz",
|
||||
platform_map={"linux-x64": {"os": "linux", "arch": "x86_64"}},
|
||||
extract_dir="nvim-{{os}}64", install={},
|
||||
post_install=None, allow_sudo=False,
|
||||
)
|
||||
assert resolve_binary_asset(pkg, "linux-x64") == "nvim-linux-x86_64.tar.gz"
|
||||
assert resolve_extract_dir(pkg, "linux-x64") == "nvim-linux64"
|
||||
|
||||
|
||||
class TestResolveDownloadUrl:
|
||||
def test_github_shorthand_with_version(self):
|
||||
@@ -140,6 +177,18 @@ class TestResolveDownloadUrl:
|
||||
assert "github.com/neovim/neovim" in url
|
||||
assert "v0.10.4" in url
|
||||
|
||||
def test_github_shorthand_prefixes_v(self):
|
||||
pkg = PackageDef(
|
||||
name="nvim", type="binary", sources={},
|
||||
source="github:neovim/neovim",
|
||||
version="0.10.4",
|
||||
asset_pattern=None, platform_map={},
|
||||
extract_dir=None, install={},
|
||||
post_install=None, allow_sudo=False,
|
||||
)
|
||||
url = resolve_download_url(pkg, "nvim.tar.gz", "linux-x64")
|
||||
assert "/download/v0.10.4/" in url
|
||||
|
||||
def test_github_latest(self):
|
||||
pkg = PackageDef(
|
||||
name="nvim", type="binary", sources={},
|
||||
@@ -181,7 +230,24 @@ class TestPmCommands:
|
||||
cmd = pm_install_command("apt", ["fd-find"])
|
||||
assert "apt-get install" in cmd
|
||||
|
||||
def test_brew_cask_install(self):
|
||||
cmd = pm_cask_install_command("brew", ["wezterm"])
|
||||
assert "--cask" in cmd
|
||||
assert "wezterm" in cmd
|
||||
|
||||
def test_detect_package_manager_returns_something(self):
|
||||
# Just verify it doesn't error
|
||||
result = detect_package_manager()
|
||||
assert result is None or result in ("apt", "dnf", "brew")
|
||||
|
||||
|
||||
class TestPlanning:
|
||||
def test_cask_package_is_planned(self):
|
||||
pkg = PackageDef(
|
||||
name="wezterm", type="cask", sources={"brew": "wezterm"},
|
||||
source=None, version=None, asset_pattern=None,
|
||||
platform_map={}, extract_dir=None, install={},
|
||||
post_install=None, allow_sudo=False,
|
||||
)
|
||||
plan = plan_install([pkg], InstalledState(), "macos-arm64", "brew")
|
||||
assert plan.install_ops[0].method == "cask"
|
||||
|
||||
Reference in New Issue
Block a user