flow
This commit is contained in:
129
tests/test_bootstrap.py
Normal file
129
tests/test_bootstrap.py
Normal file
@@ -0,0 +1,129 @@
|
||||
"""Tests for flow.commands.bootstrap — action planning."""
|
||||
|
||||
import pytest
|
||||
|
||||
from flow.commands.bootstrap import _get_profiles, _plan_actions
|
||||
from flow.core.config import AppConfig, FlowContext
|
||||
from flow.core.console import ConsoleLogger
|
||||
from flow.core.platform import PlatformInfo
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def ctx():
|
||||
return FlowContext(
|
||||
config=AppConfig(),
|
||||
manifest={
|
||||
"binaries": {
|
||||
"neovim": {
|
||||
"version": "0.10.4",
|
||||
"source": "github:neovim/neovim",
|
||||
"asset-pattern": "nvim-{{os}}-{{arch}}.tar.gz",
|
||||
"platform-map": {"linux-arm64": {"os": "linux", "arch": "arm64"}},
|
||||
"install-script": "echo install",
|
||||
},
|
||||
},
|
||||
},
|
||||
platform=PlatformInfo(os="linux", arch="arm64", platform="linux-arm64"),
|
||||
console=ConsoleLogger(),
|
||||
)
|
||||
|
||||
|
||||
def test_plan_empty_profile(ctx):
|
||||
actions = _plan_actions(ctx, "test", {}, {})
|
||||
assert actions == []
|
||||
|
||||
|
||||
def test_plan_hostname(ctx):
|
||||
actions = _plan_actions(ctx, "test", {"hostname": "myhost"}, {})
|
||||
types = [a.type for a in actions]
|
||||
assert "set-hostname" in types
|
||||
|
||||
|
||||
def test_plan_locale_and_shell(ctx):
|
||||
actions = _plan_actions(ctx, "test", {"locale": "en_US.UTF-8", "shell": "zsh"}, {})
|
||||
types = [a.type for a in actions]
|
||||
assert "set-locale" in types
|
||||
assert "set-shell" in types
|
||||
|
||||
|
||||
def test_plan_packages(ctx):
|
||||
env_config = {
|
||||
"packages": {
|
||||
"standard": ["git", "zsh", "tmux"],
|
||||
"binary": ["neovim"],
|
||||
},
|
||||
}
|
||||
actions = _plan_actions(ctx, "test", env_config, {})
|
||||
types = [a.type for a in actions]
|
||||
assert "pm-update" in types
|
||||
assert "install-packages" in types
|
||||
assert "install-binary" in types
|
||||
|
||||
|
||||
def test_plan_ssh_keygen(ctx):
|
||||
env_config = {
|
||||
"ssh_keygen": [
|
||||
{"type": "ed25519", "comment": "test@host", "filename": "id_ed25519"},
|
||||
],
|
||||
}
|
||||
actions = _plan_actions(ctx, "test", env_config, {})
|
||||
types = [a.type for a in actions]
|
||||
assert "generate-ssh-key" in types
|
||||
|
||||
|
||||
def test_plan_runcmd(ctx):
|
||||
env_config = {"runcmd": ["echo hello", "mkdir -p ~/tmp"]}
|
||||
actions = _plan_actions(ctx, "test", env_config, {})
|
||||
run_cmds = [a for a in actions if a.type == "run-command"]
|
||||
assert len(run_cmds) == 2
|
||||
|
||||
|
||||
def test_plan_requires(ctx):
|
||||
env_config = {"requires": ["VAR1", "VAR2"]}
|
||||
actions = _plan_actions(ctx, "test", env_config, {})
|
||||
checks = [a for a in actions if a.type == "check-variable"]
|
||||
assert len(checks) == 2
|
||||
assert all(not a.skip_on_error for a in checks)
|
||||
|
||||
|
||||
def test_plan_full_profile(ctx):
|
||||
"""Test planning with a realistic linux-vm profile."""
|
||||
env_config = {
|
||||
"requires": ["TARGET_HOSTNAME"],
|
||||
"os": "linux",
|
||||
"hostname": "$TARGET_HOSTNAME",
|
||||
"shell": "zsh",
|
||||
"locale": "en_US.UTF-8",
|
||||
"packages": {
|
||||
"standard": ["zsh", "tmux", "git"],
|
||||
"binary": ["neovim"],
|
||||
},
|
||||
"ssh_keygen": [{"type": "ed25519", "comment": "test"}],
|
||||
"configs": ["bin"],
|
||||
"runcmd": ["mkdir -p ~/projects"],
|
||||
}
|
||||
actions = _plan_actions(ctx, "linux-vm", env_config, {"TARGET_HOSTNAME": "myvm"})
|
||||
assert len(actions) >= 8
|
||||
|
||||
types = [a.type for a in actions]
|
||||
assert "check-variable" in types
|
||||
assert "set-hostname" in types
|
||||
assert "set-locale" in types
|
||||
assert "set-shell" in types
|
||||
assert "pm-update" in types
|
||||
assert "install-packages" in types
|
||||
assert "install-binary" in types
|
||||
assert "generate-ssh-key" in types
|
||||
assert "link-config" in types
|
||||
assert "run-command" in types
|
||||
|
||||
|
||||
def test_get_profiles_from_manifest(ctx):
|
||||
ctx.manifest = {"profiles": {"linux": {"os": "linux"}}}
|
||||
assert "linux" in _get_profiles(ctx)
|
||||
|
||||
|
||||
def test_get_profiles_rejects_environments(ctx):
|
||||
ctx.manifest = {"environments": {"legacy": {"os": "linux"}}}
|
||||
with pytest.raises(RuntimeError, match="no longer supported"):
|
||||
_get_profiles(ctx)
|
||||
Reference in New Issue
Block a user