Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: remove patching of a private ops class #347

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
28 changes: 4 additions & 24 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ def setUp(self, *unused):
patch("socket.gethostbyname", new=lambda *args: "1.2.3.4"),
k8s_resource_multipatch,
patch.object(GrafanaCharm, "grafana_version", "0.1.0"),
patch("ops.testing._TestingModelBackend.network_get"),
patch("ops.testing._TestingPebbleClient.exec", MagicMock()),
]:
p.start()
Expand Down Expand Up @@ -399,18 +398,8 @@ def setUp(self, *unused):
).hexdigest()

@patch("socket.getfqdn", lambda: "1.2.3.4")
@patch("ops.testing._TestingModelBackend.network_get")
def test_primary_sets_correct_peer_data(self, mock_unit_ip):
fake_network = {
"bind-addresses": [
{
"interface-name": "eth0",
"addresses": [{"hostname": "grafana-0", "value": "1.2.3.4"}],
}
]
}
mock_unit_ip.return_value = fake_network

@patch("ops.Network.bind_address", new="1.2.3.4")
def test_primary_sets_correct_peer_data(self):
self.harness.begin_with_initial_hooks()
self.harness.container_pebble_ready("grafana")
self.harness.container_pebble_ready("litestream")
Expand All @@ -425,17 +414,8 @@ def test_primary_sets_correct_peer_data(self, mock_unit_ip):
self.assertEqual(unit_ip, replica_address)

@patch("socket.getfqdn", lambda: "2.3.4.5")
@patch("ops.testing._TestingModelBackend.network_get")
def test_replicas_get_correct_environment_variables(self, mock_unit_ip):
fake_network = {
"bind-addresses": [
{
"interface-name": "eth0",
"addresses": [{"hostname": "grafana-0", "value": "2.3.4.5"}],
}
]
}
mock_unit_ip.return_value = fake_network
def test_replicas_get_correct_environment_variables(self):
self.harness.add_network("2.3.4.5", interface="eth0")

self.harness.begin_with_initial_hooks()
self.harness.container_pebble_ready("grafana")
Expand Down
Loading