78 lines
2.3 KiB
Python
78 lines
2.3 KiB
Python
"""Tests for flow.core.config."""
|
|
|
|
import pytest
|
|
|
|
from flow.core.config import AppConfig, load_config, load_manifest
|
|
|
|
|
|
def test_load_config_missing_path(tmp_path):
|
|
cfg = load_config(tmp_path / "nonexistent")
|
|
assert isinstance(cfg, AppConfig)
|
|
assert cfg.dotfiles_url == ""
|
|
assert cfg.container_registry == "registry.tomastm.com"
|
|
assert cfg.dotfiles_pull_before_edit is True
|
|
|
|
|
|
def test_load_config_merged_yaml(tmp_path):
|
|
(tmp_path / "10-config.yaml").write_text(
|
|
"repository:\n"
|
|
" dotfiles-url: git@github.com:user/dots.git\n"
|
|
" dotfiles-branch: dev\n"
|
|
" pull-before-edit: false\n"
|
|
"paths:\n"
|
|
" projects-dir: ~/code\n"
|
|
"defaults:\n"
|
|
" container-registry: my.registry.com\n"
|
|
" container-tag: v1\n"
|
|
" tmux-session: main\n"
|
|
"targets:\n"
|
|
" personal: orb personal@orb\n"
|
|
" work@ec2: work.ec2.internal ~/.ssh/id_work\n"
|
|
)
|
|
|
|
cfg = load_config(tmp_path)
|
|
assert cfg.dotfiles_url == "git@github.com:user/dots.git"
|
|
assert cfg.dotfiles_branch == "dev"
|
|
assert cfg.dotfiles_pull_before_edit is False
|
|
assert cfg.projects_dir == "~/code"
|
|
assert cfg.container_registry == "my.registry.com"
|
|
assert cfg.container_tag == "v1"
|
|
assert cfg.tmux_session == "main"
|
|
assert len(cfg.targets) == 2
|
|
assert cfg.targets[0].namespace == "personal"
|
|
assert cfg.targets[1].ssh_identity == "~/.ssh/id_work"
|
|
|
|
|
|
def test_load_config_pull_before_edit_string_true(tmp_path):
|
|
(tmp_path / "10-config.yaml").write_text(
|
|
"repository:\n"
|
|
" pull-before-edit: yes\n"
|
|
)
|
|
|
|
cfg = load_config(tmp_path)
|
|
assert cfg.dotfiles_pull_before_edit is True
|
|
|
|
|
|
def test_load_manifest_missing_path(tmp_path):
|
|
result = load_manifest(tmp_path / "nonexistent")
|
|
assert result == {}
|
|
|
|
|
|
def test_load_manifest_valid_directory(tmp_path):
|
|
(tmp_path / "manifest.yaml").write_text(
|
|
"profiles:\n"
|
|
" linux-vm:\n"
|
|
" os: linux\n"
|
|
" hostname: devbox\n"
|
|
)
|
|
result = load_manifest(tmp_path)
|
|
assert result["profiles"]["linux-vm"]["os"] == "linux"
|
|
|
|
|
|
def test_load_manifest_non_dict_raises(tmp_path):
|
|
bad = tmp_path / "bad.yaml"
|
|
bad.write_text("- a\n- b\n")
|
|
|
|
with pytest.raises(RuntimeError, match="must contain a mapping"):
|
|
load_manifest(bad)
|