Skip to content

Commit 1e933b5

Browse files
Add test for the create_zstream_branch tool
Signed-off-by: Nikola Forró <[email protected]> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 53a602b commit 1e933b5

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import asyncio
2+
import pytest
3+
from pathlib import Path
4+
5+
import git
6+
import koji
7+
from flexmock import flexmock
8+
9+
import distgit_tools
10+
from distgit_tools import create_zstream_branch
11+
12+
13+
@pytest.mark.parametrize(
14+
"branch_exists",
15+
[False, True],
16+
)
17+
@pytest.mark.asyncio
18+
async def test_create_zstream_branch(branch_exists, monkeypatch):
19+
package = "bash"
20+
branch = "rhel-10.0"
21+
user = "bot"
22+
ref = "123456abcdef"
23+
24+
async def init_kerberos_ticket():
25+
return f"{user}@EXAMPLE.COM"
26+
27+
flexmock(distgit_tools).should_receive("init_kerberos_ticket").replace_with(init_kerberos_ticket).once()
28+
29+
gitcmd = flexmock().should_receive("ls_remote").and_return(branch_exists).and_return(True).mock()
30+
flexmock(git.cmd.Git).new_instances(gitcmd)
31+
32+
flexmock(git.Repo).should_receive("clone_from").and_return(
33+
flexmock(
34+
git=gitcmd,
35+
remotes=flexmock(
36+
origin=flexmock(refs=[])
37+
.should_receive("push")
38+
.with_args(f"{ref}:refs/heads/{branch}")
39+
.times(0 if branch_exists else 1)
40+
.mock(),
41+
),
42+
),
43+
)
44+
45+
flexmock(koji.ClientSession).new_instances(
46+
flexmock(
47+
listTagged=lambda *_, **__: [{"build_id": 12345}],
48+
getBuild=lambda *_, **__: {"source": f"some_git_url#{ref}"},
49+
),
50+
)
51+
52+
monkeypatch.setenv("GITLAB_TOKEN", "<TOKEN>")
53+
54+
result = await create_zstream_branch(package=package, branch=branch)
55+
if branch_exists:
56+
assert "already exists" in result
57+
else:
58+
assert result.startswith("Successfully")

0 commit comments

Comments
 (0)