Skip to content

Commit

Permalink
test: increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Gu1nness committed Sep 23, 2024
1 parent ed8a941 commit c7d3be1
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion tests/unit/test_upgrade.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.
import unittest
from unittest.mock import Mock, PropertyMock, patch
from unittest.mock import MagicMock, Mock, PropertyMock, patch

import httpx
import pytest
Expand Down Expand Up @@ -123,6 +123,23 @@ def test__get_unit_healthy_status(
assert isinstance(status, ActiveStatus)
assert ("(outdated)" in status.message) == outdated_in_status

@patch("charm.k8s_upgrade.lightkube.Client.list")
def test_unit_workload_container_version(self, mock_list):
mock_pod = MagicMock()
mock_pod.metadata.name = "mongodb-k8s-0"
mock_pod.metadata.labels = {"controller-revision-hash": "deadbeef"}
mock_list.return_value = (mock_pod,)
versions = self.harness.charm.upgrade._upgrade._unit_workload_container_versions
assert versions == {"mongodb-k8s/0": "deadbeef"}

@patch("charm.k8s_upgrade.lightkube.Client.get")
def test_app_workload_container_revision(self, mock_get):
mock_stateful_set = MagicMock()
mock_stateful_set.status.updateRevision = "deadbeef"
mock_get.return_value = mock_stateful_set
version = self.harness.charm.upgrade._upgrade._app_workload_container_version
assert version == "deadbeef"

@parameterized.expand(
[
[None, True, ActiveStatus(), "restarting", False],
Expand Down

0 comments on commit c7d3be1

Please sign in to comment.