2
2
# See LICENSE file for licensing details.
3
3
4
4
import unittest
5
- from unittest .mock import MagicMock , mock_open , patch
5
+ from unittest .mock import MagicMock , PropertyMock , mock_open , patch
6
6
7
7
from ops .testing import Harness
8
8
@@ -23,14 +23,25 @@ def setUp(self):
23
23
)
24
24
self .charm = self .harness .charm
25
25
26
+ @patch ("charm.MySQLOperatorCharm._on_cos_agent_relation_created" )
26
27
@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 ):
28
32
self .harness .add_relation (COS_AGENT_RELATION_NAME , "grafana-agent" )
29
33
mock_setup .assert_called_once_with (3 , self .charm .text_logs , False )
34
+ mock_is_peer_data_set .assert_called_once ()
30
35
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
+ )
31
40
@patch ("pathlib.Path.exists" , return_value = True )
32
41
@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
+ ):
34
45
self .harness .update_config ({"logs_retention_period" : "auto" })
35
46
self .harness .add_relation (COS_AGENT_RELATION_NAME , "grafana-agent" )
36
47
positions = (
0 commit comments