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
1diff --git a/src/charm.py b/src/charm.py
2index 0faf651..14198c7 100755
3--- a/src/charm.py
4+++ b/src/charm.py
5@@ -135,5 +135,5 @@ class BindK8sCharm(CharmBase):
6 return spec
7
8
9-if __name__ == "__main__":
10+if __name__ == "__main__": # pragma: no cover
11 main(BindK8sCharm)
12diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py
13index dc53ac0..85fe103 100644
14--- a/tests/unit/test_charm.py
15+++ b/tests/unit/test_charm.py
16@@ -38,6 +38,16 @@ CONFIG_VALID = {
17 'https_proxy': '',
18 }
19
20+CONFIG_VALID_WITH_CREDS = {
21+ 'bind_image_path': 'secure.example.com/bind:v1',
22+ 'bind_image_username': 'test-user',
23+ 'bind_image_password': 'test-password',
24+ 'container_config': '',
25+ 'container_secrets': '',
26+ 'custom_config_repo': '',
27+ 'https_proxy': '',
28+}
29+
30 CONFIG_VALID_WITH_CONTAINER_CONFIG = {
31 'bind_image_path': 'example.com/bind:v1',
32 'bind_image_username': '',
33@@ -58,6 +68,16 @@ CONFIG_VALID_WITH_CONTAINER_CONFIG_AND_SECRETS = {
34 'https_proxy': '',
35 }
36
37+CONFIG_VALID_WITH_CUSTOM_CONFIG_REPO_AND_PROXY = {
38+ 'bind_image_path': 'example.com/bind:v1',
39+ 'bind_image_username': '',
40+ 'bind_image_password': '',
41+ 'container_config': '',
42+ 'container_secrets': '',
43+ 'custom_config_repo': 'https://git.example.com/example-bind-config.git',
44+ 'https_proxy': 'http://webproxy.example.com:3128/',
45+}
46+
47
48 class TestBindK8s(unittest.TestCase):
49 maxDiff = None
50@@ -110,6 +130,30 @@ class TestBindK8s(unittest.TestCase):
51 }
52 self.assertEqual(self.harness.charm.make_pod_spec(), expected)
53
54+ def test_make_pod_spec_with_creds(self):
55+ """Confirm that we generate the expected pod spec from config containing credentials."""
56+ self.harness.update_config(CONFIG_VALID_WITH_CREDS)
57+ expected = {
58+ 'version': 2,
59+ 'containers': [
60+ {
61+ 'name': 'bind',
62+ 'imageDetails': {
63+ 'imagePath': 'secure.example.com/bind:v1',
64+ 'username': 'test-user',
65+ 'password': 'test-password',
66+ },
67+ 'ports': [
68+ {'containerPort': 53, 'name': 'domain-tcp', 'protocol': 'TCP'},
69+ {'containerPort': 53, 'name': 'domain-udp', 'protocol': 'UDP'},
70+ ],
71+ 'config': {},
72+ 'kubernetes': {'readinessProbe': {'exec': {'command': ['/usr/local/bin/dns-check.sh']}}},
73+ }
74+ ],
75+ }
76+ self.assertEqual(self.harness.charm.make_pod_spec(), expected)
77+
78 def test_make_pod_spec_with_extra_config(self):
79 """Confirm that we generate the expected pod spec from a more involved valid config."""
80 self.harness.update_config(CONFIG_VALID_WITH_CONTAINER_CONFIG)
81@@ -150,6 +194,30 @@ class TestBindK8s(unittest.TestCase):
82 }
83 self.assertEqual(self.harness.charm.make_pod_spec(), expected)
84
85+ def test_make_pod_spec_with_custom_config_repo(self):
86+ """Confirm that we generate the expected pod spec from a config that includes a custom repo."""
87+ self.harness.update_config(CONFIG_VALID_WITH_CUSTOM_CONFIG_REPO_AND_PROXY)
88+ expected = {
89+ 'version': 2,
90+ 'containers': [
91+ {
92+ 'name': 'bind',
93+ 'imageDetails': {'imagePath': 'example.com/bind:v1'},
94+ 'ports': [
95+ {'containerPort': 53, 'name': 'domain-tcp', 'protocol': 'TCP'},
96+ {'containerPort': 53, 'name': 'domain-udp', 'protocol': 'UDP'},
97+ ],
98+ 'config': {
99+ 'CUSTOM_CONFIG_REPO': 'https://git.example.com/example-bind-config.git',
100+ 'http_proxy': 'http://webproxy.example.com:3128/',
101+ 'https_proxy': 'http://webproxy.example.com:3128/',
102+ },
103+ 'kubernetes': {'readinessProbe': {'exec': {'command': ['/usr/local/bin/dns-check.sh']}}},
104+ }
105+ ],
106+ }
107+ self.assertEqual(self.harness.charm.make_pod_spec(), expected)
108+
109 def test_configure_pod_as_leader(self):
110 """Confirm that our status is set correctly when we're the leader."""
111 self.harness.enable_hooks()

Subscribers

People subscribed via source and target branches

to all changes: