Skip to content

Commit

Permalink
skip: remove test cases for patching
Browse files Browse the repository at this point in the history
  • Loading branch information
DnPlas committed Aug 16, 2023
1 parent fe1311d commit 9a384fd
Showing 1 changed file with 1 addition and 51 deletions.
52 changes: 1 addition & 51 deletions charms/istio-pilot/tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,6 @@ def test_xor(self, left, right, expected):
class TestCharmUpgrade:
"""Tests for charm upgrade handling."""

@patch("charm.Operator._patch_istio_validating_webhook") # Do not patch istio installs
@patch("charm._wait_for_update_rollout") # Do not wait for upgrade to finish
@patch("charm._validate_upgrade_version") # Do not validate versions
@patch("charm.Istioctl", return_value=MagicMock())
Expand All @@ -1043,7 +1042,6 @@ def test_upgrade_successful(
mocked_istioctl_class,
_mocked_validate_upgrade_version,
mocked_wait_for_update_rollout,
_mocked_patch_istio_validating_webhook,
harness,
):
"""Tests that charm.upgrade_charm works successfully when expected."""
Expand All @@ -1053,7 +1051,7 @@ def test_upgrade_successful(
mocked_istioctl = mocked_istioctl_class.return_value

# Return valid version data from istioctl.versions
mocked_istioctl.version.return_value = {"client": "1.12.5", "control_plane": "1.12.5"}
mocked_istioctl.version.return_value = {"client": "1.15.7", "control_plane": "1.15.7"}

# Simulate the upgrade
harness.begin()
Expand Down Expand Up @@ -1127,54 +1125,6 @@ def test_validate_upgrade_version(self, versions, context_raised):
with context_raised:
_validate_upgrade_version(versions)

def test_patch_istio_validating_webhook(self, harness, mocked_lightkube_client):
"""Tests that _patch_istio_validating_webhook works as expected."""
model_name = "test-model"
harness.set_model_name(model_name)
harness.begin()

mock_vwc = ValidatingWebhookConfiguration(
metadata=ObjectMeta(name="istiod-default-validator"),
webhooks=[
ValidatingWebhook(
admissionReviewVersions=[""],
name="",
sideEffects=None,
clientConfig=WebhookClientConfig(
service=ServiceReference(
name="istiod",
namespace="istio-system",
)
),
)
],
)

mocked_lightkube_client.get.return_value = mock_vwc

harness.charm._patch_istio_validating_webhook()

# Confirm we've tried to apply a patched version of the webhook
patch_call = mocked_lightkube_client.patch.call_args_list[0]
# Assert the expected webhook is being patched
assert patch_call[0][1] == "istiod-default-validator"
# Assert that we've patched to the expected model name
vwc = patch_call[0][2]
assert vwc.webhooks[0].clientConfig.service.namespace == model_name

def test_patch_istio_validating_webhook_for_webhook_does_not_exist(
self, harness, mocked_lightkube_client
):
"""Tests that charm._patch_istio_validating_webhook does not fail if webhook missing."""
harness.begin()

mocked_lightkube_client = MagicMock()
mocked_lightkube_client.get.side_effect = FakeApiError(404)

harness.charm._patch_istio_validating_webhook()

# Confirm we've not tried to apply anything
assert mocked_lightkube_client.patch.call_count == 0

@patch("charm.Istioctl", return_value=MagicMock())
def test_wait_for_update_rollout(self, mocked_istioctl_class):
Expand Down

0 comments on commit 9a384fd

Please sign in to comment.