22# See LICENSE file for licensing details.
33
44import unittest
5- from unittest .mock import MagicMock , mock_open , patch
5+ from unittest .mock import MagicMock , PropertyMock , mock_open , patch
66
77from ops .testing import Harness
88
@@ -23,14 +23,25 @@ def setUp(self):
2323 )
2424 self .charm = self .harness .charm
2525
26+ @patch ("charm.MySQLOperatorCharm._on_cos_agent_relation_created" )
2627 @patch ("mysql_vm_helpers.MySQL.setup_logrotate_and_cron" )
27- def test_cos_relation_created (self , mock_setup ):
28+ @patch (
29+ "charm.MySQLOperatorCharm._is_peer_data_set" , new_callable = PropertyMock , return_value = True
30+ )
31+ def test_cos_relation_created (self , mock_is_peer_data_set , mock_setup , mock_charm_on_created ):
2832 self .harness .add_relation (COS_AGENT_RELATION_NAME , "grafana-agent" )
2933 mock_setup .assert_called_once_with (3 , self .charm .text_logs , False )
34+ mock_is_peer_data_set .assert_called_once ()
3035
36+ @patch ("charm.MySQLOperatorCharm._on_cos_agent_relation_created" )
37+ @patch (
38+ "charm.MySQLOperatorCharm._is_peer_data_set" , new_callable = PropertyMock , return_value = True
39+ )
3140 @patch ("pathlib.Path.exists" , return_value = True )
3241 @patch ("mysql_vm_helpers.MySQL.setup_logrotate_and_cron" )
33- def test_log_syncing (self , mock_setup , mock_exist ):
42+ def test_log_syncing (
43+ self , mock_setup , mock_exist , mock_is_peer_data_set , mock_charm_on_created
44+ ):
3445 self .harness .update_config ({"logs_retention_period" : "auto" })
3546 self .harness .add_relation (COS_AGENT_RELATION_NAME , "grafana-agent" )
3647 positions = (
0 commit comments