update
This commit is contained in:
@@ -2,7 +2,12 @@
|
||||
|
||||
import pytest
|
||||
|
||||
from flow.commands.bootstrap import _get_profiles, _plan_actions
|
||||
from flow.commands.bootstrap import (
|
||||
_get_profiles,
|
||||
_plan_actions,
|
||||
_resolve_package_manager,
|
||||
_resolve_package_name,
|
||||
)
|
||||
from flow.core.config import AppConfig, FlowContext
|
||||
from flow.core.console import ConsoleLogger
|
||||
from flow.core.platform import PlatformInfo
|
||||
@@ -60,6 +65,22 @@ def test_plan_packages(ctx):
|
||||
assert "install-binary" in types
|
||||
|
||||
|
||||
def test_plan_packages_uses_package_map(ctx):
|
||||
ctx.manifest["package-map"] = {
|
||||
"fd": {"apt": "fd-find"},
|
||||
}
|
||||
env_config = {
|
||||
"package-manager": "apt",
|
||||
"packages": {
|
||||
"standard": ["fd"],
|
||||
},
|
||||
}
|
||||
|
||||
actions = _plan_actions(ctx, "test", env_config, {})
|
||||
install = [a for a in actions if a.type == "install-packages"][0]
|
||||
assert install.data["packages"] == ["fd-find"]
|
||||
|
||||
|
||||
def test_plan_ssh_keygen(ctx):
|
||||
env_config = {
|
||||
"ssh_keygen": [
|
||||
@@ -127,3 +148,41 @@ def test_get_profiles_rejects_environments(ctx):
|
||||
ctx.manifest = {"environments": {"legacy": {"os": "linux"}}}
|
||||
with pytest.raises(RuntimeError, match="no longer supported"):
|
||||
_get_profiles(ctx)
|
||||
|
||||
|
||||
def test_resolve_package_manager_explicit_value(ctx):
|
||||
assert _resolve_package_manager(ctx, {"package-manager": "dnf"}) == "dnf"
|
||||
|
||||
|
||||
def test_resolve_package_manager_linux_ubuntu(ctx):
|
||||
os_release = "ID=ubuntu\nID_LIKE=debian"
|
||||
assert _resolve_package_manager(ctx, {}, os_release_text=os_release) == "apt"
|
||||
|
||||
|
||||
def test_resolve_package_manager_linux_fedora(ctx):
|
||||
os_release = "ID=fedora\nID_LIKE=rhel"
|
||||
assert _resolve_package_manager(ctx, {}, os_release_text=os_release) == "dnf"
|
||||
|
||||
|
||||
def test_resolve_package_name_with_package_map(ctx):
|
||||
ctx.manifest["package-map"] = {
|
||||
"fd": {
|
||||
"apt": "fd-find",
|
||||
"dnf": "fd-find",
|
||||
"brew": "fd",
|
||||
}
|
||||
}
|
||||
assert _resolve_package_name(ctx, "fd", "apt") == "fd-find"
|
||||
assert _resolve_package_name(ctx, "fd", "dnf") == "fd-find"
|
||||
assert _resolve_package_name(ctx, "fd", "brew") == "fd"
|
||||
|
||||
|
||||
def test_resolve_package_name_falls_back_with_warning(ctx):
|
||||
warnings = []
|
||||
ctx.console.warn = warnings.append
|
||||
ctx.manifest["package-map"] = {"python3-dev": {"apt": "python3-dev"}}
|
||||
|
||||
resolved = _resolve_package_name(ctx, "python3-dev", "dnf", warn_missing=True)
|
||||
|
||||
assert resolved == "python3-dev"
|
||||
assert warnings
|
||||
|
||||
@@ -55,6 +55,7 @@ def test_dotfiles_help():
|
||||
assert "unlink" in result.stdout
|
||||
assert "status" in result.stdout
|
||||
assert "sync" in result.stdout
|
||||
assert "repo" in result.stdout
|
||||
|
||||
|
||||
def test_bootstrap_help():
|
||||
@@ -66,6 +67,7 @@ def test_bootstrap_help():
|
||||
assert "run" in result.stdout
|
||||
assert "list" in result.stdout
|
||||
assert "show" in result.stdout
|
||||
assert "packages" in result.stdout
|
||||
|
||||
|
||||
def test_package_help():
|
||||
|
||||
@@ -15,6 +15,15 @@ def test_complete_bootstrap_profiles(monkeypatch):
|
||||
assert out == ["linux-vm"]
|
||||
|
||||
|
||||
def test_complete_bootstrap_packages_options(monkeypatch):
|
||||
monkeypatch.setattr(completion, "_list_bootstrap_profiles", lambda: ["linux-vm", "macos-host"])
|
||||
out = completion.complete(["flow", "bootstrap", "packages", "--p"], 4)
|
||||
assert out == ["--profile"]
|
||||
|
||||
out = completion.complete(["flow", "bootstrap", "packages", "--profile", "m"], 5)
|
||||
assert out == ["macos-host"]
|
||||
|
||||
|
||||
def test_complete_package_install(monkeypatch):
|
||||
monkeypatch.setattr(completion, "_list_manifest_packages", lambda: ["neovim", "fzf"])
|
||||
out = completion.complete(["flow", "package", "install", "n"], 4)
|
||||
@@ -33,6 +42,11 @@ def test_complete_dotfiles_profile_value(monkeypatch):
|
||||
assert out == ["work"]
|
||||
|
||||
|
||||
def test_complete_dotfiles_repo_subcommands():
|
||||
out = completion.complete(["flow", "dotfiles", "repo", "p"], 4)
|
||||
assert out == ["pull", "push"]
|
||||
|
||||
|
||||
def test_complete_enter_targets(monkeypatch):
|
||||
monkeypatch.setattr(completion, "_list_targets", lambda: ["personal@orb", "work@ec2"])
|
||||
out = completion.complete(["flow", "enter", "p"], 3)
|
||||
|
||||
@@ -5,7 +5,7 @@ from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from flow.commands.dotfiles import _discover_packages, _walk_package
|
||||
from flow.commands.dotfiles import _discover_packages, _resolve_edit_target, _walk_package
|
||||
from flow.core.config import AppConfig, FlowContext
|
||||
from flow.core.console import ConsoleLogger
|
||||
from flow.core.platform import PlatformInfo
|
||||
@@ -64,3 +64,17 @@ def test_walk_package(dotfiles_tree):
|
||||
targets = {str(t) for _, t in pairs}
|
||||
assert str(home / ".zshrc") in targets
|
||||
assert str(home / ".zshenv") in targets
|
||||
|
||||
|
||||
def test_resolve_edit_target_package(dotfiles_tree):
|
||||
target = _resolve_edit_target("zsh", dotfiles_dir=dotfiles_tree)
|
||||
assert target == dotfiles_tree / "common" / "zsh"
|
||||
|
||||
|
||||
def test_resolve_edit_target_repo_path(dotfiles_tree):
|
||||
target = _resolve_edit_target("common/zsh/.zshrc", dotfiles_dir=dotfiles_tree)
|
||||
assert target == dotfiles_tree / "common" / "zsh" / ".zshrc"
|
||||
|
||||
|
||||
def test_resolve_edit_target_missing_returns_none(dotfiles_tree):
|
||||
assert _resolve_edit_target("does-not-exist", dotfiles_dir=dotfiles_tree) is None
|
||||
|
||||
Reference in New Issue
Block a user