Merge ~barryprice/charm-k8s-bind/+git/charm-k8s-bind:master into charm-k8s-bind:master

Proposed by Barry Price
Status: Merged
Approved by: Barry Price
Approved revision: 040d5f7133739b4d61de0dc5eb6a968f81c7c5dd
Merged at revision: 2835c005267fe68a342ddf3e954b69c2c3dfed92
Proposed branch: ~barryprice/charm-k8s-bind/+git/charm-k8s-bind:master
Merge into: charm-k8s-bind:master
Diff against target: 111 lines (+69/-1)
2 files modified
src/charm.py (+1/-1)
tests/unit/test_charm.py (+68/-0)
Reviewer Review Type Date Requested Status
Tom Haddon Approve
Canonical IS Reviewers Pending
Review via email: mp+392823@code.launchpad.net

Commit message

This takes us from 90% to 100% test coverage

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Tom Haddon (mthaddon) wrote :

LGTM, thx

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 2835c005267fe68a342ddf3e954b69c2c3dfed92

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/src/charm.py b/src/charm.py
index 0faf651..14198c7 100755
--- a/src/charm.py
+++ b/src/charm.py
@@ -135,5 +135,5 @@ class BindK8sCharm(CharmBase):
135 return spec135 return spec
136136
137137
138if __name__ == "__main__":138if __name__ == "__main__": # pragma: no cover
139 main(BindK8sCharm)139 main(BindK8sCharm)
diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py
index dc53ac0..85fe103 100644
--- a/tests/unit/test_charm.py
+++ b/tests/unit/test_charm.py
@@ -38,6 +38,16 @@ CONFIG_VALID = {
38 'https_proxy': '',38 'https_proxy': '',
39}39}
4040
41CONFIG_VALID_WITH_CREDS = {
42 'bind_image_path': 'secure.example.com/bind:v1',
43 'bind_image_username': 'test-user',
44 'bind_image_password': 'test-password',
45 'container_config': '',
46 'container_secrets': '',
47 'custom_config_repo': '',
48 'https_proxy': '',
49}
50
41CONFIG_VALID_WITH_CONTAINER_CONFIG = {51CONFIG_VALID_WITH_CONTAINER_CONFIG = {
42 'bind_image_path': 'example.com/bind:v1',52 'bind_image_path': 'example.com/bind:v1',
43 'bind_image_username': '',53 'bind_image_username': '',
@@ -58,6 +68,16 @@ CONFIG_VALID_WITH_CONTAINER_CONFIG_AND_SECRETS = {
58 'https_proxy': '',68 'https_proxy': '',
59}69}
6070
71CONFIG_VALID_WITH_CUSTOM_CONFIG_REPO_AND_PROXY = {
72 'bind_image_path': 'example.com/bind:v1',
73 'bind_image_username': '',
74 'bind_image_password': '',
75 'container_config': '',
76 'container_secrets': '',
77 'custom_config_repo': 'https://git.example.com/example-bind-config.git',
78 'https_proxy': 'http://webproxy.example.com:3128/',
79}
80
6181
62class TestBindK8s(unittest.TestCase):82class TestBindK8s(unittest.TestCase):
63 maxDiff = None83 maxDiff = None
@@ -110,6 +130,30 @@ class TestBindK8s(unittest.TestCase):
110 }130 }
111 self.assertEqual(self.harness.charm.make_pod_spec(), expected)131 self.assertEqual(self.harness.charm.make_pod_spec(), expected)
112132
133 def test_make_pod_spec_with_creds(self):
134 """Confirm that we generate the expected pod spec from config containing credentials."""
135 self.harness.update_config(CONFIG_VALID_WITH_CREDS)
136 expected = {
137 'version': 2,
138 'containers': [
139 {
140 'name': 'bind',
141 'imageDetails': {
142 'imagePath': 'secure.example.com/bind:v1',
143 'username': 'test-user',
144 'password': 'test-password',
145 },
146 'ports': [
147 {'containerPort': 53, 'name': 'domain-tcp', 'protocol': 'TCP'},
148 {'containerPort': 53, 'name': 'domain-udp', 'protocol': 'UDP'},
149 ],
150 'config': {},
151 'kubernetes': {'readinessProbe': {'exec': {'command': ['/usr/local/bin/dns-check.sh']}}},
152 }
153 ],
154 }
155 self.assertEqual(self.harness.charm.make_pod_spec(), expected)
156
113 def test_make_pod_spec_with_extra_config(self):157 def test_make_pod_spec_with_extra_config(self):
114 """Confirm that we generate the expected pod spec from a more involved valid config."""158 """Confirm that we generate the expected pod spec from a more involved valid config."""
115 self.harness.update_config(CONFIG_VALID_WITH_CONTAINER_CONFIG)159 self.harness.update_config(CONFIG_VALID_WITH_CONTAINER_CONFIG)
@@ -150,6 +194,30 @@ class TestBindK8s(unittest.TestCase):
150 }194 }
151 self.assertEqual(self.harness.charm.make_pod_spec(), expected)195 self.assertEqual(self.harness.charm.make_pod_spec(), expected)
152196
197 def test_make_pod_spec_with_custom_config_repo(self):
198 """Confirm that we generate the expected pod spec from a config that includes a custom repo."""
199 self.harness.update_config(CONFIG_VALID_WITH_CUSTOM_CONFIG_REPO_AND_PROXY)
200 expected = {
201 'version': 2,
202 'containers': [
203 {
204 'name': 'bind',
205 'imageDetails': {'imagePath': 'example.com/bind:v1'},
206 'ports': [
207 {'containerPort': 53, 'name': 'domain-tcp', 'protocol': 'TCP'},
208 {'containerPort': 53, 'name': 'domain-udp', 'protocol': 'UDP'},
209 ],
210 'config': {
211 'CUSTOM_CONFIG_REPO': 'https://git.example.com/example-bind-config.git',
212 'http_proxy': 'http://webproxy.example.com:3128/',
213 'https_proxy': 'http://webproxy.example.com:3128/',
214 },
215 'kubernetes': {'readinessProbe': {'exec': {'command': ['/usr/local/bin/dns-check.sh']}}},
216 }
217 ],
218 }
219 self.assertEqual(self.harness.charm.make_pod_spec(), expected)
220
153 def test_configure_pod_as_leader(self):221 def test_configure_pod_as_leader(self):
154 """Confirm that our status is set correctly when we're the leader."""222 """Confirm that our status is set correctly when we're the leader."""
155 self.harness.enable_hooks()223 self.harness.enable_hooks()

Subscribers

People subscribed via source and target branches

to all changes: