From 0f989126cc2f8daa3b040930285c61ea3f513b54 Mon Sep 17 00:00:00 2001 From: fkolwa Date: Thu, 17 Nov 2022 13:43:14 +0100 Subject: [PATCH] Add Google image formatting to CLI --- src/rhelocator/cli.py | 4 ++-- src/rhelocator/update_images/gcp.py | 2 +- tests/test_cli.py | 20 ++++++++------------ 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/rhelocator/cli.py b/src/rhelocator/cli.py index 03df1f11..ac954bcd 100644 --- a/src/rhelocator/cli.py +++ b/src/rhelocator/cli.py @@ -53,8 +53,8 @@ def aws_regions() -> None: @click.command() def gcp_images() -> None: """Dump GCP images for all regions in JSON format.""" - images = gcp.get_images() - click.echo(json.dumps(images, indent=2)) + images = gcp.format_all_images() + dump_images(images) @click.command() diff --git a/src/rhelocator/update_images/gcp.py b/src/rhelocator/update_images/gcp.py index 5eb9534e..c903d8dc 100644 --- a/src/rhelocator/update_images/gcp.py +++ b/src/rhelocator/update_images/gcp.py @@ -116,7 +116,7 @@ def format_image(image: dict[str, str]) -> dict[str, str]: """ arch = image["architecture"] - image_id = image["id"] + image_id = image["name"] date = image["creation_timestamp"] version = parse_image_version_from_name(image["name"]) diff --git a/tests/test_cli.py b/tests/test_cli.py index f43a6d95..3aae5593 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -140,13 +140,11 @@ def test_gcp_images_live(runner): result = runner.invoke(cli.gcp_images) parsed = json.loads(result.output) - assert isinstance(parsed, list) + assert isinstance(parsed["images"]["google"], list) - for img in parsed: - assert img["architecture"] in ["arm64", "x86_64"] - assert "creation_timestamp" in img - assert "Red Hat" in img["description"] - assert "rhel" in img["name"] + for image in parsed["images"]["google"]: + expected_keys = ["name", "arch", "version", "imageId", "date", "selflink"] + assert list(image.keys()) == expected_keys assert result.exit_code == 0 @@ -156,12 +154,10 @@ def test_gcp_images_offline(mock_gcp_images, runner): result = runner.invoke(cli.gcp_images) parsed = json.loads(result.output) - assert isinstance(parsed, list) + assert isinstance(parsed["images"]["google"], list) - for img in parsed: - assert img["architecture"] in ["arm64", "x86_64"] - assert "creation_timestamp" in img - assert "Red Hat" in img["description"] - assert "rhel" in img["name"] + for image in parsed["images"]["google"]: + expected_keys = ["name", "arch", "version", "imageId", "date", "selflink"] + assert list(image.keys()) == expected_keys assert result.exit_code == 0