wordpress-charmers team mailing list archive
-
wordpress-charmers team
-
Mailing list archive
-
Message #00352
[Merge] ~tcuthbert/charm-k8s-wordpress/+git/charm-k8s-wordpress:tests into charm-k8s-wordpress:master
Thomas Cuthbert has proposed merging ~tcuthbert/charm-k8s-wordpress/+git/charm-k8s-wordpress:tests into charm-k8s-wordpress:master.
Commit message:
Unit tests to ensure WordPress secrets are in sync on pods
Requested reviews:
Canonical IS Reviewers (canonical-is-reviewers)
Wordpress Charmers (wordpress-charmers)
For more details, see:
https://code.launchpad.net/~tcuthbert/charm-k8s-wordpress/+git/charm-k8s-wordpress/+merge/385455
--
Your team Wordpress Charmers is requested to review the proposed merge of ~tcuthbert/charm-k8s-wordpress/+git/charm-k8s-wordpress:tests into charm-k8s-wordpress:master.
diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py
index d5772ba..2ac93e0 100644
--- a/tests/unit/test_charm.py
+++ b/tests/unit/test_charm.py
@@ -1,19 +1,31 @@
#!/usr/bin/env python3
import copy
+import mock
import unittest
import sys
sys.path.append('lib')
sys.path.append('src')
-from charm import WordpressK8sCharm
+from charm import WordpressK8sCharm, create_wordpress_secrets, gather_wordpress_secrets
+from wordpress import WORDPRESS_SECRETS
from ops import testing
from ops.model import BlockedStatus
from test_wordpress import TEST_MODEL_CONFIG
+class TestLeadershipData:
+ data = {}
+
+ def _leader_set(self, d):
+ self.data.update(d)
+
+ def _leader_get(self, k):
+ return self.data.get(k)
+
+
class TestWordpressK8sCharm(unittest.TestCase):
test_model_config = TEST_MODEL_CONFIG
@@ -54,3 +66,25 @@ class TestWordpressK8sCharm(unittest.TestCase):
self.assertIsInstance(self.harness.charm.unit.status, BlockedStatus)
self.assertEqual(self.harness.charm.unit.status.message, expected_msg)
self.assertLogs(expected_msg, level="INFO")
+
+ @mock.patch("charm._leader_set")
+ @mock.patch("charm._leader_get")
+ def test_create_wordpress_secrets(self, _leader_get_func, _leader_set_func):
+ leadership_data = TestLeadershipData()
+ _leader_set_func.side_effect = leadership_data._leader_set
+ _leader_get_func.side_effect = leadership_data._leader_get
+ create_wordpress_secrets()
+
+ self.assertEqual(list(leadership_data.data.keys()), WORDPRESS_SECRETS)
+
+ @mock.patch("charm._leader_set")
+ @mock.patch("charm._leader_get")
+ def test_gather_wordpress_secrets(self, _leader_get_func, _leader_set_func):
+ leadership_data = TestLeadershipData()
+ _leader_set_func.side_effect = leadership_data._leader_set
+ _leader_get_func.side_effect = leadership_data._leader_get
+ create_wordpress_secrets()
+ wp_secrets = gather_wordpress_secrets()
+ for key in WORDPRESS_SECRETS:
+ self.assertIsInstance(wp_secrets[key], str)
+ self.assertEqual(len(wp_secrets[key]), 64)
References