Merge ~mthaddon/charm-k8s-mattermost/+git/charm-k8s-mattermost:tests into charm-k8s-mattermost:master

Proposed by Tom Haddon
Status: Merged
Approved by: Tom Haddon
Approved revision: 8c23ef87c9c237f0d000f7601402b2393f559c1e
Merged at revision: cda8e5377822ee813691ec45405662f9b0214642
Proposed branch: ~mthaddon/charm-k8s-mattermost/+git/charm-k8s-mattermost:tests
Merge into: charm-k8s-mattermost:master
Diff against target: 62 lines (+38/-2)
2 files modified
src/charm.py (+1/-2)
tests/unit/test_charm.py (+37/-0)
Reviewer Review Type Date Requested Status
Paul Collins Approve
Haw Loeung +1 Approve
Review via email: mp+391372@code.launchpad.net

Commit message

Add some more tests for ingress conditions, remove conditional for annotations, which is always True in _update_pod_spec_for_k8s_ingress

Description of the change

Add some more tests for ingress conditions, remove conditional for annotations, which is always True in _update_pod_spec_for_k8s_ingress.

Takes overall test coverage from 60% to 61%...

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
Haw Loeung (hloeung) wrote :

LGTM

review: Approve (+1)
Revision history for this message
Paul Collins (pjdc) wrote :

lgtm re annotations

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

Change successfully merged at revision cda8e5377822ee813691ec45405662f9b0214642

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 34f8922..c3f2eda 100755
3--- a/src/charm.py
4+++ b/src/charm.py
5@@ -311,8 +311,7 @@ class MattermostK8sCharm(CharmBase):
6 if ingress_whitelist_source_range:
7 annotations['nginx.ingress.kubernetes.io/whitelist-source-range'] = ingress_whitelist_source_range
8
9- if annotations:
10- ingress['annotations'] = annotations
11+ ingress['annotations'] = annotations
12
13 # Due to https://github.com/canonical/operator/issues/293 we
14 # can't use pod.set_spec's k8s_resources argument.
15diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py
16index f1a5da1..5295dce 100644
17--- a/tests/unit/test_charm.py
18+++ b/tests/unit/test_charm.py
19@@ -292,6 +292,43 @@ class TestMattermostK8sCharmHooksDisabled(unittest.TestCase):
20 pod_spec = {}
21 self.harness.charm._update_pod_spec_for_k8s_ingress(pod_spec)
22 self.assertEqual(pod_spec, expected)
23+ # And now test with an ingress_whitelist_source_range, and an http
24+ # rather than https site_url to test a few more ingress conditions.
25+ self.harness.update_config(
26+ {'ingress_whitelist_source_range': '10.10.10.10/24', 'site_url': 'http://chat.example.com'}
27+ )
28+ expected = {
29+ 'kubernetesResources': {
30+ 'ingressResources': [
31+ {
32+ 'name': ingress_name,
33+ 'spec': {
34+ 'rules': [
35+ {
36+ 'host': 'chat.example.com',
37+ 'http': {
38+ 'paths': [
39+ {
40+ 'path': '/',
41+ 'backend': {'serviceName': 'mattermost', 'servicePort': 8065},
42+ }
43+ ]
44+ },
45+ }
46+ ],
47+ },
48+ 'annotations': {
49+ 'nginx.ingress.kubernetes.io/proxy-body-size': '5m',
50+ 'nginx.ingress.kubernetes.io/ssl-redirect': 'false',
51+ 'nginx.ingress.kubernetes.io/whitelist-source-range': '10.10.10.10/24',
52+ },
53+ }
54+ ]
55+ }
56+ }
57+ pod_spec = {}
58+ self.harness.charm._update_pod_spec_for_k8s_ingress(pod_spec)
59+ self.assertEqual(pod_spec, expected)
60
61 def test_update_pod_spec_for_performance_monitoring(self):
62 """envConfig is updated, and pre-existing annotations are not clobbered."""

Subscribers

People subscribed via source and target branches