|
9 | 9 | from git import Repo |
10 | 10 | from moto import mock_aws |
11 | 11 |
|
| 12 | +import gardenlinux |
12 | 13 | import gardenlinux.github.__main__ as gh |
13 | 14 | from gardenlinux.apt.debsource import DebsrcFile |
14 | 15 | from gardenlinux.features import CName |
@@ -421,3 +422,43 @@ def test_script_parse_args_upload_command_required_args(monkeypatch, capfd): |
421 | 422 |
|
422 | 423 | assert "the following arguments are required: --release_id, --file_path" in captured.err, \ |
423 | 424 | "Expected help message on missing arguments for 'upload' command" |
| 425 | + |
| 426 | + |
| 427 | +def test_script_create_dry_run(monkeypatch, capfd): |
| 428 | + |
| 429 | + monkeypatch.setattr(sys, "argv", ["gh", "create", "--owner", "gardenlinux", "--repo", |
| 430 | + "gardenlinux", "--tag", GARDENLINUX_RELEASE, "--commit", GARDENLINUX_COMMIT, "--dry-run"]) |
| 431 | + monkeypatch.setattr("gardenlinux.github.__main__.create_github_release_notes", |
| 432 | + lambda tag, commit: f"{tag} {commit}") |
| 433 | + |
| 434 | + gh.main() |
| 435 | + captured = capfd.readouterr() |
| 436 | + |
| 437 | + assert captured.out == f"{GARDENLINUX_RELEASE} {GARDENLINUX_COMMIT}\n", \ |
| 438 | + "Expected dry-run create to return generated release notes text" |
| 439 | + |
| 440 | + |
| 441 | +def test_script_create(monkeypatch, caplog): |
| 442 | + monkeypatch.setattr(sys, "argv", ["gh", "create", "--owner", "gardenlinux", "--repo", |
| 443 | + "gardenlinux", "--tag", GARDENLINUX_RELEASE, "--commit", GARDENLINUX_COMMIT]) |
| 444 | + monkeypatch.setattr("gardenlinux.github.__main__.create_github_release_notes", |
| 445 | + lambda tag, commit: f"{tag} {commit}") |
| 446 | + monkeypatch.setattr("gardenlinux.github.__main__.create_github_release", |
| 447 | + lambda a1, a2, a3, a4, a5: GARDENLINUX_RELEASE) |
| 448 | + |
| 449 | + gh.main() |
| 450 | + |
| 451 | + assert any(f"Release created with ID: {GARDENLINUX_RELEASE}" in record.message for record in caplog.records), \ |
| 452 | + "Expected a release creation confirmation log entry" |
| 453 | + |
| 454 | + |
| 455 | +def test_script_upload_dry_run(monkeypatch, capfd): |
| 456 | + monkeypatch.setattr(sys, "argv", ["gh", "upload", "--owner", "gardenlinux", "--repo", |
| 457 | + "gardenlinux", "--release_id", GARDENLINUX_RELEASE, "--file_path", "foo", "--dry-run"]) |
| 458 | + monkeypatch.setattr("gardenlinux.github.__main__.upload_to_github_release_page", |
| 459 | + lambda a1, a2, a3, a4, dry_run: print(f"dry-run: {dry_run}")) |
| 460 | + |
| 461 | + gh.main() |
| 462 | + captured = capfd.readouterr() |
| 463 | + |
| 464 | + assert captured.out == "dry-run: True\n" |
0 commit comments