Skip to content

Commit eb70885

Browse files
committed
Add jinja2 transform and GraphQL query for tags, and implement branch selection test
1 parent 003d6ab commit eb70885

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

tests/fixtures/repos/ctl_integration/.infrahub.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ generator_definitions:
2626
parameters:
2727
name: "name__value"
2828

29+
jinja2_transforms:
30+
- name: tags
31+
query: "tags_query"
32+
template_path: "templates/tags.j2"
2933

3034
queries:
3135
- name: animal_person
3236
file_path: queries/animal_person.gql
37+
- name: tags_query
38+
file_path: templates/tags_query.gql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{ data['BuiltinTag']['edges'][0]['node']['name']['value'] }}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
query TagsQuery($name: String!) {
2+
BuiltinTag(name__value: $name) {
3+
edges {
4+
node {
5+
name {
6+
value
7+
}
8+
}
9+
}
10+
}
11+
}

tests/unit/ctl/test_render_app.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,44 @@ def test_validate_template_not_found(test_case: RenderAppFailure, httpx_mock: HT
7373
output = runner.invoke(app, ["render", test_case.template, "name=red"])
7474
assert test_case.error in strip_color(output.stdout)
7575
assert output.exit_code == 1
76+
77+
78+
@pytest.mark.parametrize(
79+
"cli_branch,env_branch,from_git,expected_branch",
80+
[
81+
("cli-branch", None, False, "cli-branch"),
82+
(None, "env-branch", False, "env-branch"),
83+
(None, None, True, "git-branch"),
84+
],
85+
)
86+
@requires_python_310
87+
def test_render_branch_selection(monkeypatch, httpx_mock: HTTPXMock, cli_branch, env_branch, from_git, expected_branch):
88+
"""Test that the render command uses the correct branch source."""
89+
90+
if from_git:
91+
monkeypatch.setattr("dulwich.porcelain.active_branch", lambda _: b"git-branch")
92+
93+
httpx_mock.add_response(
94+
method="POST",
95+
url=f"http://mock/graphql/{expected_branch}",
96+
json=json.loads(
97+
read_fixture(
98+
"red_tag.json",
99+
"unit/test_infrahubctl/red_tags_query",
100+
)
101+
),
102+
)
103+
104+
with temp_repo_and_cd(source_dir=FIXTURE_BASE_DIR / "ctl_integration"):
105+
args = ["render", "tags", "name=red"]
106+
env = {}
107+
# Add test-specific variables
108+
if cli_branch:
109+
args.extend(["--branch", cli_branch])
110+
if env_branch:
111+
env["INFRAHUB_DEFAULT_BRANCH"] = env_branch
112+
env["INFRAHUB_DEFAULT_BRANCH_FROM_GIT"] = "false"
113+
if from_git:
114+
env["INFRAHUB_DEFAULT_BRANCH_FROM_GIT"] = "true"
115+
output = runner.invoke(app, args, env=env)
116+
assert output.exit_code == 0

0 commit comments

Comments
 (0)