added package removal, brew, flatpak, ostree, nix xupport
This commit is contained in:
parent
da6d24c74f
commit
df1f387795
16 changed files with 596 additions and 362 deletions
|
|
@ -1,22 +1,37 @@
|
|||
import datetime as dt
|
||||
from pathlib import Path
|
||||
|
||||
import tomlkit
|
||||
import datetime as dt
|
||||
|
||||
from forge import cli
|
||||
from curator import cli
|
||||
|
||||
|
||||
def test_parse_config_arrays(tmp_path: Path) -> None:
|
||||
config_path = tmp_path / "forge.toml"
|
||||
def test_parse_config_line_format(tmp_path: Path) -> None:
|
||||
config_path = tmp_path / "inventory.toml"
|
||||
config_path.write_text(
|
||||
"""
|
||||
copr = ["copr.fedorainfracloud.org/user/repo"]
|
||||
packages = ["git", "vim"]
|
||||
|
||||
[forge]
|
||||
[curator]
|
||||
version = "1.0"
|
||||
last_switch = ""
|
||||
|
||||
[copr]
|
||||
copr.fedorainfracloud.org/user/repo
|
||||
|
||||
[dnf]
|
||||
git
|
||||
vim
|
||||
|
||||
[brew]
|
||||
wget
|
||||
|
||||
[flatpak]
|
||||
org.mozilla.firefox
|
||||
|
||||
[rpm-ostree]
|
||||
podman
|
||||
|
||||
[nix]
|
||||
nixpkgs#git
|
||||
|
||||
[dotfiles]
|
||||
".bashrc" = ".bashrc"
|
||||
|
||||
|
|
@ -30,18 +45,33 @@ backup_dir = "backup"
|
|||
|
||||
assert config.copr == ["copr.fedorainfracloud.org/user/repo"]
|
||||
assert config.packages == ["git", "vim"]
|
||||
assert config.brew_packages == ["wget"]
|
||||
assert config.flatpak_refs == ["org.mozilla.firefox"]
|
||||
assert config.rpm_ostree_packages == ["podman"]
|
||||
assert config.nix_packages == ["nixpkgs#git"]
|
||||
assert config.dotfiles == {".bashrc": ".bashrc"}
|
||||
assert config.options["backup"] is True
|
||||
assert config.legacy is False
|
||||
|
||||
|
||||
def test_parse_config_legacy_format(tmp_path: Path) -> None:
|
||||
config_path = tmp_path / "forge.toml"
|
||||
config_path = tmp_path / "inventory.toml"
|
||||
config_path.write_text(
|
||||
"""
|
||||
[packages]
|
||||
git
|
||||
vim
|
||||
[dnf]
|
||||
git
|
||||
vim
|
||||
|
||||
[brew]
|
||||
wget
|
||||
|
||||
[flatpak]
|
||||
org.mozilla.firefox
|
||||
|
||||
[rpm-ostree]
|
||||
podman
|
||||
|
||||
[nix]
|
||||
nixpkgs#git
|
||||
|
||||
[copr]
|
||||
copr.fedorainfracloud.org/user/repo
|
||||
|
|
@ -54,9 +84,12 @@ copr.fedorainfracloud.org/user/repo
|
|||
config = cli.parse_config(config_path)
|
||||
|
||||
assert config.packages == ["git", "vim"]
|
||||
assert config.brew_packages == ["wget"]
|
||||
assert config.flatpak_refs == ["org.mozilla.firefox"]
|
||||
assert config.rpm_ostree_packages == ["podman"]
|
||||
assert config.nix_packages == ["nixpkgs#git"]
|
||||
assert config.copr == ["copr.fedorainfracloud.org/user/repo"]
|
||||
assert config.dotfiles == {".bashrc": ".bashrc"}
|
||||
assert config.legacy is True
|
||||
|
||||
|
||||
def test_diff_items() -> None:
|
||||
|
|
@ -67,10 +100,10 @@ def test_diff_items() -> None:
|
|||
|
||||
def test_update_last_switch_creates_backup(tmp_path: Path) -> None:
|
||||
config_dir = tmp_path
|
||||
config_path = config_dir / "forge.toml"
|
||||
config_path = config_dir / "inventory.toml"
|
||||
config_path.write_text(
|
||||
"""
|
||||
[forge]
|
||||
[curator]
|
||||
version = "1.0"
|
||||
last_switch = ""
|
||||
""".strip()
|
||||
|
|
@ -79,10 +112,13 @@ last_switch = ""
|
|||
options = {"backup": True, "backup_dir": "backup"}
|
||||
cli.update_last_switch(config_path, options)
|
||||
|
||||
doc = tomlkit.parse(config_path.read_text())
|
||||
assert isinstance(doc["forge"]["last_switch"], dt.datetime)
|
||||
lines = [line.strip() for line in config_path.read_text().splitlines() if line.strip()]
|
||||
last_switch_line = [line for line in lines if line.startswith("last_switch")]
|
||||
assert last_switch_line, "last_switch should be written"
|
||||
ts_str = last_switch_line[0].split("=", 1)[1].strip().strip('"')
|
||||
dt.datetime.fromisoformat(ts_str)
|
||||
|
||||
backup_dir = config_dir / "backup"
|
||||
backups = list(backup_dir.iterdir())
|
||||
assert backups, "expected a backup of forge.toml to be created"
|
||||
assert any(path.name.startswith("forge.toml.") for path in backups)
|
||||
assert backups, "expected a backup of inventory.toml to be created"
|
||||
assert any(path.name.startswith("inventory.toml.") for path in backups)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue