faas-gitops 0.4.1__tar.gz → 0.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {faas_gitops-0.4.1/src/faas_gitops.egg-info → faas_gitops-0.5.0}/PKG-INFO +1 -1
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/pyproject.toml +1 -1
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/cli/app.py +8 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/cli/parser.py +10 -0
- faas_gitops-0.5.0/src/faas_gitops/usecases/format.py +63 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0/src/faas_gitops.egg-info}/PKG-INFO +1 -1
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops.egg-info/SOURCES.txt +4 -1
- faas_gitops-0.5.0/tests/test_format.py +158 -0
- faas_gitops-0.5.0/tests/test_version.py +16 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/MANIFEST.in +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/setup.cfg +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/__init__.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/adapters/__init__.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/adapters/bizy_function_provider.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/adapters/bizy_template_provider.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/adapters/git_cli_gateway.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/cli/__init__.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/config.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/filtering.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/infra/__init__.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/infra/yaml_utils.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/layout.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/models.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/protocols/__init__.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/protocols/faas_function.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/protocols/faas_template.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/protocols/git_gateway.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/result.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/usecases/__init__.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/usecases/apply_function_changes.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/usecases/apply_plan.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/usecases/apply_template_changes.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/usecases/deploy_functions.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/usecases/detect_drift.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/usecases/detect_function_drift.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/usecases/detect_template_drift.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/usecases/plan.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/usecases/render_definitions.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/usecases/snapshot.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/usecases/sync_functions.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops/usecases/sync_templates.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops.egg-info/dependency_links.txt +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops.egg-info/entry_points.txt +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops.egg-info/requires.txt +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/src/faas_gitops.egg-info/top_level.txt +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/tests/test_apply_function_changes.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/tests/test_apply_plan.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/tests/test_apply_template_changes.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/tests/test_deploy_functions.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/tests/test_detect_drift.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/tests/test_detect_function_drift.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/tests/test_git_cli_gateway.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/tests/test_plan.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/tests/test_render_definitions.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/tests/test_result_contract.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/tests/test_scope_args.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/tests/test_snapshot.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/tests/test_sync_functions.py +0 -0
- {faas_gitops-0.4.1 → faas_gitops-0.5.0}/tests/test_sync_templates.py +0 -0
|
@@ -23,6 +23,7 @@ from faas_gitops.usecases.apply_template_changes import ApplyTemplateChanges
|
|
|
23
23
|
from faas_gitops.usecases.deploy_functions import DeployFunctions
|
|
24
24
|
from faas_gitops.usecases.detect_function_drift import DetectFunctionDrift
|
|
25
25
|
from faas_gitops.usecases.detect_template_drift import DetectTemplateDrift
|
|
26
|
+
from faas_gitops.usecases.format import format_branch
|
|
26
27
|
from faas_gitops.usecases.render_definitions import render_definitions
|
|
27
28
|
from faas_gitops.usecases.snapshot import snapshot
|
|
28
29
|
from faas_gitops.usecases.sync_functions import SyncFunctions
|
|
@@ -137,6 +138,13 @@ async def async_main() -> int:
|
|
|
137
138
|
logger.info(f"render-definitions: {n} file(s) written")
|
|
138
139
|
return 0
|
|
139
140
|
|
|
141
|
+
if args.command == "format":
|
|
142
|
+
git = _make_git()
|
|
143
|
+
repo_path = await git.clone_repo(repo_slug)
|
|
144
|
+
n = await format_branch(git, repo_path, branch=args.branch, settings=settings)
|
|
145
|
+
logger.info(f"format: {n} file(s) formatted")
|
|
146
|
+
return 0
|
|
147
|
+
|
|
140
148
|
if args.command == "detect-template-changes":
|
|
141
149
|
git = _make_git()
|
|
142
150
|
repo_path = await git.clone_repo(repo_slug)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import argparse
|
|
4
|
+
import importlib.metadata
|
|
4
5
|
|
|
5
6
|
from faas_gitops.config import Settings
|
|
6
7
|
from faas_gitops.filtering import match_scope
|
|
@@ -49,6 +50,9 @@ def in_template_scope(item_id: str, tags: list[str], settings: Settings) -> bool
|
|
|
49
50
|
|
|
50
51
|
def build_parser(settings: Settings) -> argparse.ArgumentParser:
|
|
51
52
|
parser = argparse.ArgumentParser(prog="faas-gitops")
|
|
53
|
+
parser.add_argument(
|
|
54
|
+
"--version", action="version", version=importlib.metadata.version("faas-gitops"),
|
|
55
|
+
)
|
|
52
56
|
sub = parser.add_subparsers(dest="command")
|
|
53
57
|
|
|
54
58
|
def _add_repo(p: argparse.ArgumentParser) -> None:
|
|
@@ -91,6 +95,12 @@ def build_parser(settings: Settings) -> argparse.ArgumentParser:
|
|
|
91
95
|
add_scope_args(p)
|
|
92
96
|
_add_repo(p)
|
|
93
97
|
|
|
98
|
+
p = sub.add_parser("format")
|
|
99
|
+
p.add_argument("--branch", required=True,
|
|
100
|
+
help="branch whose template + function YAML files get re-formatted in place")
|
|
101
|
+
add_scope_args(p)
|
|
102
|
+
_add_repo(p)
|
|
103
|
+
|
|
94
104
|
p = sub.add_parser("detect-template-changes")
|
|
95
105
|
add_scope_args(p)
|
|
96
106
|
_add_repo(p)
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""Re-format template and function YAML files on a branch to the canonical FaaS yaml format."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
import aiofiles
|
|
7
|
+
from loguru import logger
|
|
8
|
+
from tqdm.asyncio import tqdm_asyncio
|
|
9
|
+
|
|
10
|
+
from faas_gitops.config import Settings
|
|
11
|
+
from faas_gitops.infra.yaml_utils import dump_faas_yaml, load_yaml
|
|
12
|
+
from faas_gitops.layout import FUNCTION_DIR, FUNCTION_META, FUNCTION_BASE, FUNCTION_DEFINITION, TEMPLATE_DIR, TEMPLATE_PRIMARY
|
|
13
|
+
from faas_gitops.protocols.git_gateway import GitWriter
|
|
14
|
+
|
|
15
|
+
_TEMPLATE_YAML = (TEMPLATE_PRIMARY, "schema.yaml")
|
|
16
|
+
_FUNCTION_YAML = (FUNCTION_META, FUNCTION_BASE, FUNCTION_DEFINITION)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _collect(root: Path, names: tuple[str, ...]) -> list[Path]:
|
|
20
|
+
if not root.is_dir():
|
|
21
|
+
return []
|
|
22
|
+
return sorted(p for p in root.rglob("*.yaml") if p.name in names)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
async def _format_file(path: Path) -> bool:
|
|
26
|
+
try:
|
|
27
|
+
async with aiofiles.open(path) as f:
|
|
28
|
+
original = await f.read()
|
|
29
|
+
data = load_yaml(original)
|
|
30
|
+
if not data:
|
|
31
|
+
return False
|
|
32
|
+
formatted = dump_faas_yaml(data)
|
|
33
|
+
if formatted == original:
|
|
34
|
+
return False
|
|
35
|
+
async with aiofiles.open(path, "w") as f:
|
|
36
|
+
await f.write(formatted)
|
|
37
|
+
return True
|
|
38
|
+
except Exception as e:
|
|
39
|
+
logger.warning(f"format failed for {path}: {e}")
|
|
40
|
+
return False
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _in_scope(path: Path, settings: Settings) -> bool:
|
|
44
|
+
if path.parts[0] == TEMPLATE_DIR:
|
|
45
|
+
return not settings.scoped_templates or "/".join(path.parts[1:3]) in settings.scoped_templates
|
|
46
|
+
return not settings.scoped_functions or path.parts[1] in settings.scoped_functions
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
async def format_branch(git: GitWriter, repo_path: Path, *, branch: str, settings: Settings) -> int:
|
|
50
|
+
await git.prepare_branch(repo_path=repo_path, branch=branch, force=False)
|
|
51
|
+
logger.info(f"format: branch={branch}")
|
|
52
|
+
|
|
53
|
+
paths = [
|
|
54
|
+
p for p in _collect(repo_path / TEMPLATE_DIR, _TEMPLATE_YAML) + _collect(repo_path / FUNCTION_DIR, _FUNCTION_YAML)
|
|
55
|
+
if _in_scope(p.relative_to(repo_path), settings)
|
|
56
|
+
]
|
|
57
|
+
changed = sum(await tqdm_asyncio.gather(
|
|
58
|
+
*[_format_file(p) for p in paths], desc=f"format [{branch}]", unit="file",
|
|
59
|
+
))
|
|
60
|
+
await git.commit_and_push(
|
|
61
|
+
repo_path, ".", f"format[{changed}]", branch=branch, force=False, create_pr=False,
|
|
62
|
+
)
|
|
63
|
+
return changed
|
|
@@ -33,6 +33,7 @@ src/faas_gitops/usecases/deploy_functions.py
|
|
|
33
33
|
src/faas_gitops/usecases/detect_drift.py
|
|
34
34
|
src/faas_gitops/usecases/detect_function_drift.py
|
|
35
35
|
src/faas_gitops/usecases/detect_template_drift.py
|
|
36
|
+
src/faas_gitops/usecases/format.py
|
|
36
37
|
src/faas_gitops/usecases/plan.py
|
|
37
38
|
src/faas_gitops/usecases/render_definitions.py
|
|
38
39
|
src/faas_gitops/usecases/snapshot.py
|
|
@@ -44,6 +45,7 @@ tests/test_apply_template_changes.py
|
|
|
44
45
|
tests/test_deploy_functions.py
|
|
45
46
|
tests/test_detect_drift.py
|
|
46
47
|
tests/test_detect_function_drift.py
|
|
48
|
+
tests/test_format.py
|
|
47
49
|
tests/test_git_cli_gateway.py
|
|
48
50
|
tests/test_plan.py
|
|
49
51
|
tests/test_render_definitions.py
|
|
@@ -51,4 +53,5 @@ tests/test_result_contract.py
|
|
|
51
53
|
tests/test_scope_args.py
|
|
52
54
|
tests/test_snapshot.py
|
|
53
55
|
tests/test_sync_functions.py
|
|
54
|
-
tests/test_sync_templates.py
|
|
56
|
+
tests/test_sync_templates.py
|
|
57
|
+
tests/test_version.py
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"""Tests for format use case."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from unittest.mock import AsyncMock, MagicMock
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
|
|
9
|
+
from faas_gitops.config import Settings
|
|
10
|
+
from faas_gitops.infra.yaml_utils import dump_faas_yaml
|
|
11
|
+
from faas_gitops.usecases.format import format_branch
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _setup_repo(repo: Path) -> None:
|
|
15
|
+
tpl_dir = repo / "templates" / "org" / "tpl"
|
|
16
|
+
tpl_dir.mkdir(parents=True)
|
|
17
|
+
(tpl_dir / "info.yaml").write_text("{subject: org, id: tpl}\n") # flow style → re-formatted
|
|
18
|
+
(tpl_dir / "template.jinja").write_text("name: {{ name }}\n") # not YAML → untouched
|
|
19
|
+
(tpl_dir / "schema.yaml").write_text(dump_faas_yaml({"type": "object"})) # already canonical
|
|
20
|
+
|
|
21
|
+
func_dir = repo / "functions" / "fn1"
|
|
22
|
+
func_dir.mkdir(parents=True)
|
|
23
|
+
(func_dir / "meta.yaml").write_text("functionName: f1\ntags:\n - gitops\n") # indented seq → re-formatted
|
|
24
|
+
(func_dir / "base.yaml").write_text(dump_faas_yaml({"templateName": "org/tpl"})) # already canonical
|
|
25
|
+
(func_dir / "definition.yaml").write_text("key: value\n") # extra spaces → re-formatted
|
|
26
|
+
(func_dir / "rendered.yaml").write_text("key: value\n") # machine-generated → untouched
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _make_git() -> MagicMock:
|
|
30
|
+
git = MagicMock()
|
|
31
|
+
git.prepare_branch = AsyncMock()
|
|
32
|
+
git.commit_and_push = AsyncMock()
|
|
33
|
+
return git
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class TestFormat:
|
|
37
|
+
@pytest.mark.asyncio
|
|
38
|
+
async def test_formats_templates_and_functions(self, tmp_path: Path) -> None:
|
|
39
|
+
_setup_repo(tmp_path)
|
|
40
|
+
git = _make_git()
|
|
41
|
+
n = await format_branch(git, tmp_path, branch="feat/x", settings=Settings())
|
|
42
|
+
assert n == 3
|
|
43
|
+
assert (tmp_path / "templates" / "org" / "tpl" / "info.yaml").read_text() == dump_faas_yaml(
|
|
44
|
+
{"subject": "org", "id": "tpl"}
|
|
45
|
+
)
|
|
46
|
+
assert (tmp_path / "functions" / "fn1" / "meta.yaml").read_text() == dump_faas_yaml(
|
|
47
|
+
{"functionName": "f1", "tags": ["gitops"]}
|
|
48
|
+
)
|
|
49
|
+
assert (tmp_path / "functions" / "fn1" / "definition.yaml").read_text() == dump_faas_yaml(
|
|
50
|
+
{"key": "value"}
|
|
51
|
+
)
|
|
52
|
+
assert (tmp_path / "templates" / "org" / "tpl" / "schema.yaml").read_text() == dump_faas_yaml(
|
|
53
|
+
{"type": "object"}
|
|
54
|
+
)
|
|
55
|
+
assert (tmp_path / "functions" / "fn1" / "base.yaml").read_text() == dump_faas_yaml(
|
|
56
|
+
{"templateName": "org/tpl"}
|
|
57
|
+
)
|
|
58
|
+
assert (tmp_path / "templates" / "org" / "tpl" / "template.jinja").read_text() == "name: {{ name }}\n"
|
|
59
|
+
assert (tmp_path / "functions" / "fn1" / "rendered.yaml").read_text() == "key: value\n"
|
|
60
|
+
git.prepare_branch.assert_awaited_once_with(repo_path=tmp_path, branch="feat/x", force=False)
|
|
61
|
+
git.commit_and_push.assert_awaited_once_with(
|
|
62
|
+
tmp_path, ".", "format[3]", branch="feat/x", force=False, create_pr=False,
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
@pytest.mark.asyncio
|
|
66
|
+
async def test_idempotent_second_run_is_noop(self, tmp_path: Path) -> None:
|
|
67
|
+
_setup_repo(tmp_path)
|
|
68
|
+
git = _make_git()
|
|
69
|
+
await format_branch(git, tmp_path, branch="feat/x", settings=Settings())
|
|
70
|
+
n = await format_branch(git, tmp_path, branch="feat/x", settings=Settings())
|
|
71
|
+
assert n == 0
|
|
72
|
+
|
|
73
|
+
@pytest.mark.asyncio
|
|
74
|
+
async def test_scope_functions_filters(self, tmp_path: Path) -> None:
|
|
75
|
+
# Given fn1 (2 files to format) + fn2 (1 file) + org/tpl info.yaml (1 file), only fn1 files are excluded
|
|
76
|
+
_setup_repo(tmp_path)
|
|
77
|
+
func_dir = tmp_path / "functions" / "fn2"
|
|
78
|
+
func_dir.mkdir(parents=True)
|
|
79
|
+
(func_dir / "meta.yaml").write_text("functionName: f2\n")
|
|
80
|
+
(func_dir / "base.yaml").write_text("templateName: org/tpl\n")
|
|
81
|
+
(func_dir / "definition.yaml").write_text("key: other\n")
|
|
82
|
+
git = _make_git()
|
|
83
|
+
n = await format_branch(
|
|
84
|
+
git, tmp_path, branch="feat/x", settings=Settings(scoped_functions={"fn2"}),
|
|
85
|
+
)
|
|
86
|
+
assert n == 2 # fn2/meta.yaml + org/tpl/info.yaml (templates unscoped → pass)
|
|
87
|
+
assert (tmp_path / "functions" / "fn2" / "meta.yaml").read_text() == dump_faas_yaml(
|
|
88
|
+
{"functionName": "f2"}
|
|
89
|
+
)
|
|
90
|
+
assert (tmp_path / "functions" / "fn1" / "meta.yaml").read_text() == "functionName: f1\ntags:\n - gitops\n"
|
|
91
|
+
|
|
92
|
+
@pytest.mark.asyncio
|
|
93
|
+
async def test_scope_templates_filters(self, tmp_path: Path) -> None:
|
|
94
|
+
# Given org/tpl info (1 file) + org/tpl2 info (1 file) + fn1 (2 files), only org/tpl is excluded
|
|
95
|
+
_setup_repo(tmp_path)
|
|
96
|
+
tpl_dir = tmp_path / "templates" / "org" / "tpl2"
|
|
97
|
+
tpl_dir.mkdir(parents=True)
|
|
98
|
+
(tpl_dir / "info.yaml").write_text("{subject: org, id: tpl2}\n")
|
|
99
|
+
git = _make_git()
|
|
100
|
+
n = await format_branch(
|
|
101
|
+
git, tmp_path, branch="feat/x", settings=Settings(scoped_templates={"org/tpl2"}),
|
|
102
|
+
)
|
|
103
|
+
assert n == 3 # tpl2/info.yaml + fn1/meta.yaml + fn1/definition.yaml (functions unscoped → pass)
|
|
104
|
+
assert (tmp_path / "templates" / "org" / "tpl" / "info.yaml").read_text() == "{subject: org, id: tpl}\n"
|
|
105
|
+
|
|
106
|
+
@pytest.mark.asyncio
|
|
107
|
+
async def test_invalid_yaml_skipped_with_warning(self, tmp_path: Path) -> None:
|
|
108
|
+
tpl_dir = tmp_path / "templates" / "org" / "tpl"
|
|
109
|
+
tpl_dir.mkdir(parents=True)
|
|
110
|
+
(tpl_dir / "info.yaml").write_text("{subject: org, id: tpl}\n")
|
|
111
|
+
(tpl_dir / "schema.yaml").write_text("{{ not valid yaml\n")
|
|
112
|
+
git = _make_git()
|
|
113
|
+
n = await format_branch(git, tmp_path, branch="feat/x", settings=Settings())
|
|
114
|
+
assert n == 1
|
|
115
|
+
assert (tpl_dir / "schema.yaml").read_text() == "{{ not valid yaml\n"
|
|
116
|
+
|
|
117
|
+
@pytest.mark.asyncio
|
|
118
|
+
async def test_empty_or_comment_only_yaml_untouched(self, tmp_path: Path) -> None:
|
|
119
|
+
func_dir = tmp_path / "functions" / "fn1"
|
|
120
|
+
func_dir.mkdir(parents=True)
|
|
121
|
+
(func_dir / "meta.yaml").write_text("# comment only\n")
|
|
122
|
+
(func_dir / "base.yaml").write_text("")
|
|
123
|
+
git = _make_git()
|
|
124
|
+
n = await format_branch(git, tmp_path, branch="feat/x", settings=Settings())
|
|
125
|
+
assert n == 0
|
|
126
|
+
assert (func_dir / "meta.yaml").read_text() == "# comment only\n"
|
|
127
|
+
|
|
128
|
+
@pytest.mark.asyncio
|
|
129
|
+
async def test_no_dirs(self, tmp_path: Path) -> None:
|
|
130
|
+
git = _make_git()
|
|
131
|
+
n = await format_branch(git, tmp_path, branch="feat/x", settings=Settings())
|
|
132
|
+
assert n == 0
|
|
133
|
+
git.prepare_branch.assert_awaited_once_with(repo_path=tmp_path, branch="feat/x", force=False)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
class TestFormatParser:
|
|
137
|
+
def _parser(self):
|
|
138
|
+
from faas_gitops.cli.parser import build_parser
|
|
139
|
+
return build_parser(Settings())
|
|
140
|
+
|
|
141
|
+
def test_branch_required_and_scope_args_accepted(self) -> None:
|
|
142
|
+
args = self._parser().parse_args(["format", "--branch", "feat/x", "--functions", "fn1"])
|
|
143
|
+
assert args.command == "format"
|
|
144
|
+
assert args.branch == "feat/x"
|
|
145
|
+
assert args.functions == "fn1"
|
|
146
|
+
|
|
147
|
+
def test_missing_branch_exits(self) -> None:
|
|
148
|
+
with pytest.raises(SystemExit):
|
|
149
|
+
self._parser().parse_args(["format"])
|
|
150
|
+
|
|
151
|
+
def test_scope_from_args_on_format_namespace(self) -> None:
|
|
152
|
+
"""format registers scope args; scope_from_args works unchanged (regression)."""
|
|
153
|
+
from faas_gitops.cli.parser import scope_from_args
|
|
154
|
+
|
|
155
|
+
args = self._parser().parse_args(["format", "--branch", "feat/x"])
|
|
156
|
+
settings = scope_from_args(args)
|
|
157
|
+
assert settings.scoped_functions is None
|
|
158
|
+
assert settings.scoped_templates is None
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""--version flag support."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import importlib.metadata
|
|
5
|
+
|
|
6
|
+
import pytest
|
|
7
|
+
|
|
8
|
+
from faas_gitops.cli.parser import build_parser
|
|
9
|
+
from faas_gitops.config import Settings
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_version_flag_prints_package_version(capsys) -> None:
|
|
13
|
+
with pytest.raises(SystemExit) as excinfo:
|
|
14
|
+
build_parser(Settings()).parse_args(["--version"])
|
|
15
|
+
assert excinfo.value.code == 0
|
|
16
|
+
assert importlib.metadata.version("faas-gitops") in capsys.readouterr().out
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|