Skip to content

Commit

Permalink
Fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
yhaliaw committed Jul 5, 2024
1 parent 5c2919d commit 41a591d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/openstack_cloud/openstack_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def _update_image(

# Ignore the flake8 function too complex (C901). The function does not have much logic, the lint
# is likely triggered with the multiple try-excepts, which are needed.
def build_image( # noqa: C901
def build_image( # noqa: C901 pylint: disable=too-many-arguments
arch: Arch,
cloud_config: dict[str, dict],
github_client: GithubClient,
Expand Down
15 changes: 13 additions & 2 deletions tests/unit/test_openstack_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from openstack.compute.v2.server import Server

import metrics.storage
from charm_state import CharmState, ProxyConfig, RepoPolicyComplianceConfig
from charm_state import BaseImage, CharmState, ProxyConfig, RepoPolicyComplianceConfig
from errors import OpenStackError, RunnerStartError
from github_type import GitHubRunnerStatus, SelfHostedRunner
from metrics import events as metric_events
Expand Down Expand Up @@ -469,7 +469,7 @@ def test__build_image_command():
)

command = openstack_manager._build_image_command(
runner_info=test_runner_info, proxies=test_proxy_config
runner_info=test_runner_info, base_image=BaseImage.JAMMY, proxies=test_proxy_config
)
assert command == [
"/usr/bin/bash",
Expand All @@ -478,6 +478,7 @@ def test__build_image_command():
test_http_proxy,
test_https_proxy,
test_no_proxy,
"jammy",
], "Unexpected build image command."


Expand All @@ -496,6 +497,7 @@ def test_build_image_runner_binary_error():
cloud_config=MagicMock(),
github_client=mock_github_client,
path=MagicMock(),
base_image=BaseImage.JAMMY,
)

assert "Failed to fetch runner application." in str(exc)
Expand Down Expand Up @@ -523,6 +525,7 @@ def test_build_image_script_error(monkeypatch: pytest.MonkeyPatch):
cloud_config=MagicMock(),
github_client=MagicMock(),
path=MagicMock(),
base_image=BaseImage.JAMMY,
)

assert "Failed to build image." in str(exc)
Expand Down Expand Up @@ -551,6 +554,7 @@ def test_build_image_runner_arch_error(
cloud_config=MagicMock(),
github_client=mock_github_client,
path=MagicMock(),
base_image=BaseImage.JAMMY,
)

assert "Unsupported architecture" in str(exc)
Expand All @@ -577,6 +581,7 @@ def test_build_image_delete_image_error(
cloud_config=MagicMock(),
github_client=mock_github_client,
path=MagicMock(),
base_image=BaseImage.JAMMY,
)

assert "Failed to delete duplicate image on Openstack." in str(exc)
Expand All @@ -601,6 +606,7 @@ def test_build_image_create_image_error(
cloud_config=MagicMock(),
github_client=mock_github_client,
path=MagicMock(),
base_image=BaseImage.JAMMY,
proxies=None,
)

Expand All @@ -627,6 +633,7 @@ def test_build_image(
cloud_config=MagicMock(),
github_client=mock_github_client,
path=MagicMock(),
base_image=BaseImage.JAMMY,
)


Expand All @@ -649,6 +656,7 @@ def test_build_image_on_arm64(
cloud_config=MagicMock(),
github_client=mock_github_client,
path=MagicMock(),
base_image=BaseImage.JAMMY,
)


Expand All @@ -673,6 +681,7 @@ def test_build_image_on_unsupported_arch(
cloud_config=MagicMock(),
github_client=mock_github_client,
path=MagicMock(),
base_image=BaseImage.JAMMY,
)
assert str(exc.value) == "Unsupported architecture x64"

Expand Down Expand Up @@ -703,6 +712,7 @@ def test_build_image_with_proxy_config(
cloud_config=MagicMock(),
github_client=mock_github_client,
path=MagicMock(),
base_image=BaseImage.JAMMY,
proxies=test_proxy_config,
)

Expand All @@ -718,6 +728,7 @@ def test_build_image_with_proxy_config(
cloud_config=MagicMock(),
github_client=mock_github_client,
path=MagicMock(),
base_image=BaseImage.JAMMY,
proxies=test_proxy_config,
)

Expand Down

0 comments on commit 41a591d

Please sign in to comment.