| |
@@ -4,6 +4,7 @@
|
| |
import pytest
|
| |
|
| |
from rpmautospec import tag_package
|
| |
+ from ..common import MainArgs
|
| |
|
| |
|
| |
VALID_HASH = "0123456789abcdef0123456789abcdef01234567"
|
| |
@@ -19,16 +20,25 @@
|
| |
else:
|
| |
buildsys_host = "src.fedoraproject.org"
|
| |
|
| |
- build = {
|
| |
- "name": "pkgname",
|
| |
- "epoch": None,
|
| |
- "version": "1.0",
|
| |
- "release": "1.fc32",
|
| |
- "owner_name": "hamburglar",
|
| |
- "source": f"git+https://{buildsys_host}/rpms/pkgname#{VALID_HASH}",
|
| |
- "build_id": 123,
|
| |
- "task_id": 54321,
|
| |
- }
|
| |
+ builds = [
|
| |
+ {
|
| |
+ "name": "pkgname",
|
| |
+ "epoch": None,
|
| |
+ "version": "1.0",
|
| |
+ "release": f"{relver}.fc{distver}",
|
| |
+ "nvr": f"pkgname-1.0-{relver}.fc{distver}",
|
| |
+ "owner_name": "hamburglar",
|
| |
+ "source": f"git+https://{buildsys_host}/rpms/pkgname#{VALID_HASH}",
|
| |
+ "build_id": build_id,
|
| |
+ "task_id": 54321,
|
| |
+ }
|
| |
+ for build_id, (distver, relver) in enumerate(
|
| |
+ ((distver, relver) for distver in (32, 31, 30) for relver in (3, 2, 1)), 123
|
| |
+ )
|
| |
+ ]
|
| |
+
|
| |
+ firstbuild = builds[0]
|
| |
+ lastbuild = builds[-1]
|
| |
|
| |
for phenomenon in phenomena:
|
| |
if phenomenon in (
|
| |
@@ -40,27 +50,30 @@
|
| |
"wrongbuildsys",
|
| |
"tagcmdfails",
|
| |
"pagure_tag",
|
| |
+ "tagallbuilds",
|
| |
):
|
| |
# Ignore phenomena handled above and/or in the test method.
|
| |
pass
|
| |
elif phenomenon == "epoch":
|
| |
- build["epoch"] = 1
|
| |
+ firstbuild["epoch"] = 1
|
| |
elif phenomenon == "modularbuild":
|
| |
- build["owner_name"] = "mbs/mbs.fedoraproject.org"
|
| |
+ firstbuild["owner_name"] = "mbs/mbs.fedoraproject.org"
|
| |
elif phenomenon in ("invalidhash", "tooshorthash"):
|
| |
- if "source" in build:
|
| |
+ if "source" in firstbuild:
|
| |
# Don't accidentally put the source back if it shouldn't be.
|
| |
if phenomenon == "invalidhash":
|
| |
hash_val = INVALID_HASH
|
| |
else:
|
| |
hash_val = TOO_SHORT_HASH
|
| |
- build["source"] = f"git+https://src.fedoraproject.org/rpms/pkgname#{hash_val}"
|
| |
+ firstbuild["source"] = f"git+https://src.fedoraproject.org/rpms/pkgname#{hash_val}"
|
| |
elif phenomenon == "nosource":
|
| |
- del build["source"]
|
| |
+ del firstbuild["source"]
|
| |
+ elif phenomenon == "releasewithoutdisttag":
|
| |
+ lastbuild["release"] = "1"
|
| |
else:
|
| |
raise ValueError(f"Don't understand phenomenon: {phenomenon}")
|
| |
|
| |
- return [build]
|
| |
+ return builds
|
| |
|
| |
|
| |
class TestTagPackage:
|
| |
@@ -86,6 +99,8 @@
|
| |
"nosource,wrongbuildsys",
|
| |
"tagcmdfails",
|
| |
"pagure_tag",
|
| |
+ "tagallbuilds",
|
| |
+ "releasewithoutdisttag",
|
| |
),
|
| |
)
|
| |
@mock.patch("rpmautospec.tag_package.run_command")
|
| |
@@ -101,7 +116,7 @@
|
| |
|
| |
get_package_builds.return_value = test_builds = get_test_builds(phenomena)
|
| |
|
| |
- main_args = mock.Mock()
|
| |
+ main_args = MainArgs()
|
| |
# This IP address is from the reserved TEST-NET-1 address space, i.e. should be
|
| |
# guaranteed to not exist or be routable. Just in case we fail to mock out code that
|
| |
# attempts to contact a remote Koji instance.
|
| |
@@ -113,6 +128,8 @@
|
| |
main_args.pagure_url = "https://192.0.2.2"
|
| |
main_args.pagure_token = "token"
|
| |
|
| |
+ main_args.tag_latest_builds = "tagallbuilds" not in phenomena
|
| |
+
|
| |
if "trailingslashpath" in phenomena:
|
| |
# This shouldn't change anything, really.
|
| |
main_args.worktree_path += "/"
|
| |
@@ -144,15 +161,16 @@
|
| |
kojiclient.getTaskChildren.return_value = tasks
|
| |
|
| |
if "tagcmdfails" in phenomena:
|
| |
- run_command.side_effect = RuntimeError("lp0 is on fire")
|
| |
+ # It's always the first build that fails
|
| |
+ run_command.side_effect = [RuntimeError("lp0 is on fire")] + [0] * len(test_builds)
|
| |
|
| |
tag_package.main(main_args)
|
| |
|
| |
if "pagure_tag" in phenomena:
|
| |
- pagure_post.assert_called_once_with(
|
| |
+ pagure_post.assert_any_call(
|
| |
"https://192.0.2.2/api/0/rpms/pkgname/git/tags",
|
| |
data={
|
| |
- "tagname": "build/pkgname-0-1.0-1.fc32",
|
| |
+ "tagname": "build/pkgname-0-1.0-3.fc32",
|
| |
"commit_hash": "0123456789abcdef0123456789abcdef01234567",
|
| |
"message": None,
|
| |
"with_commits": True,
|
| |
@@ -162,11 +180,14 @@
|
| |
)
|
| |
|
| |
if "nosource" in phenomena:
|
| |
- kojiclient.getTaskChildren.assert_called_once_with(test_builds[0]["task_id"])
|
| |
+ kojiclient.getTaskChildren.assert_any_call(test_builds[0]["task_id"])
|
| |
|
| |
if any(p in ("notasks", "nosrpmtask") for p in phenomena):
|
| |
kojiclient.getTaskRequest.assert_not_called()
|
| |
|
| |
+ if "modularbuild" in phenomena:
|
| |
+ assert any("Ignoring modular build:" in m for m in caplog.messages)
|
| |
+
|
| |
if any(
|
| |
p
|
| |
in (
|
| |
@@ -176,22 +197,36 @@
|
| |
"nosrpmtask",
|
| |
"notasks",
|
| |
"wrongbuildsys",
|
| |
+ "tagcmdfails",
|
| |
)
|
| |
for p in phenomena
|
| |
):
|
| |
- run_command.assert_not_called()
|
| |
+ first_build_skipped = True
|
| |
else:
|
| |
- build = test_builds[0]
|
| |
- nevr = "-".join(
|
| |
- str(build[partname]) if build[partname] else "0"
|
| |
- for partname in ("name", "epoch", "version", "release")
|
| |
- )
|
| |
- tag = f"build/{nevr}"
|
| |
- run_command.assert_called_once_with(
|
| |
- ["git", "tag", "--force", tag, commit], cwd=repopath
|
| |
+ first_build_skipped = False
|
| |
+
|
| |
+ build = test_builds[0]
|
| |
+ nevr = "-".join(
|
| |
+ str(build[partname]) if build[partname] else "0"
|
| |
+ for partname in ("name", "epoch", "version", "release")
|
| |
+ )
|
| |
+ tag = f"build/{nevr}"
|
| |
+
|
| |
+ if first_build_skipped:
|
| |
+ assert all(
|
| |
+ c.args != ["git", "tag", "--force", tag, commit] for c in run_command.call_args_list
|
| |
)
|
| |
+ else:
|
| |
+ run_command.assert_any_call(["git", "tag", "--force", tag, commit], cwd=repopath)
|
| |
|
| |
- if "tagcmdfails" in phenomena:
|
| |
- assert "lp0 is on fire" in caplog.text
|
| |
- else:
|
| |
- assert f"Tagged commit {commit} as {tag}" in caplog.messages
|
| |
+ if "tagcmdfails" in phenomena:
|
| |
+ assert "lp0 is on fire" in caplog.text
|
| |
+
|
| |
+ if not first_build_skipped:
|
| |
+ assert f"Tagged commit {commit} as {tag}" in caplog.messages
|
| |
+
|
| |
+ if "tagallbuilds" not in phenomena:
|
| |
+ assert any("Skipping older build:" in s for s in caplog.messages)
|
| |
+
|
| |
+ if "releasewithoutdisttag" in phenomena:
|
| |
+ assert any("Can't find dist tag for build:" in s for s in caplog.messages)
|
| |
Also, add default values in help for options in all sub parsers. Fix some broken tests.