Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

add gcp image list command to CLI #37

Merged
merged 3 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ jobs:
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS}}

- name: Run pytest with offline tests only
if: env.SECRET_CHECK == null
Expand Down
6 changes: 6 additions & 0 deletions src/rhelocator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ def aws_regions() -> None:
regions = update_images.get_aws_regions()
click.echo(json.dumps(regions, indent=2))

@click.command()
def gcp_images() -> None:
"""Dump GCP images for all regions in JSON format"""
images = update_images.get_google_images()
click.echo(json.dumps(images, indent=2))

@click.command()
def azure_images() -> None:
Expand All @@ -53,3 +58,4 @@ def azure_images() -> None:
cli.add_command(aws_hourly_images)
cli.add_command(aws_regions)
cli.add_command(azure_images)
cli.add_command(gcp_images)
13 changes: 13 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
"9.0.2022090601",
]

MOCKED_GCP_IMAGE_LIST = [
{"status": "READY"},
miyunari marked this conversation as resolved.
Show resolved Hide resolved
{"status": "DEPRECATED"},
]


def pytest_configure(config: any) -> None:
config.addinivalue_line("markers", "e2e: mark as end-to-end test.")
Expand Down Expand Up @@ -53,3 +58,11 @@ def mock_azure_image_versions_latest(mocker):
mock = mocker.patch("rhelocator.update_images.get_azure_image_versions")
mock.return_value = [MOCKED_AZURE_IMAGE_VERSION_LIST[0]]
return mock


@pytest.fixture
def mock_gcp_images(mocker):
"""Provide an offline result for calls to get_google_images."""
mock = mocker.patch("rhelocator.update_images.get_google_images")
mock.return_value = MOCKED_GCP_IMAGE_LIST
return mock
25 changes: 24 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def test_aws_regions_offline(mock_aws_regions, runner):
assert "us-east-1" in parsed
assert result.exit_code == 0


@pytest.mark.e2e
def test_azure_images_live(runner):
"""Run a live test against the Azure API to get images via CLI."""
Expand Down Expand Up @@ -115,3 +114,27 @@ def test_azure_images_offline(mock_azure_image_versions, runner):
assert list(image.keys()) == expected_keys

assert result.exit_code == 0

@pytest.mark.e2e
def test_gcp_images_live(runner):
"""Run a live test against the Google Cloud API to get images via CLI."""
result = runner.invoke(cli.gcp_images)
parsed = json.loads(result.output)

assert isinstance(parsed, list)

assert {image["status"] for image in parsed} != "DEPRECATED"

assert result.exit_code == 0


def test_gcp_images_offline(mock_gcp_images, runner):
"""Run a live test against the Google Cloud API to get images via CLI."""
result = runner.invoke(cli.gcp_images)
parsed = json.loads(result.output)

assert isinstance(parsed, list)

assert {image["status"] for image in parsed} != "DEPRECATED"

assert result.exit_code == 0