2 # Copyright 2020 Canonical Ltd.
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
16 # For those usages not covered by the Apache License, Version 2.0 please
17 # contact: legal@canonical.com
19 # To get in touch with the maintainers, please contact:
20 # osm-charmers@lists.launchpad.net
24 from typing
import NoReturn
27 from charm
import PrometheusCharm
28 from ops
.model
import ActiveStatus
29 from ops
.testing
import Harness
32 class TestCharm(unittest
.TestCase
):
33 """Prometheus Charm unit tests."""
35 def setUp(self
) -> NoReturn
:
37 self
.image_info
= sys
.modules
["oci_image"].OCIImageResource().fetch()
38 self
.harness
= Harness(PrometheusCharm
)
39 self
.harness
.set_leader(is_leader
=True)
45 "ingress_whitelist_source_range": "",
46 "tls_secret_name": "",
47 "site_url": "https://prometheus.192.168.100.100.nip.io",
48 "cluster_issuer": "vault-issuer",
49 "enable_web_admin_api": False,
51 self
.harness
.update_config(self
.config
)
53 def test_config_changed(
56 """Test ingress resources without HTTP."""
58 self
.harness
.charm
.on
.config_changed
.emit()
61 self
.assertIsInstance(self
.harness
.charm
.unit
.status
, ActiveStatus
)
63 def test_config_changed_non_leader(
66 """Test ingress resources without HTTP."""
67 self
.harness
.set_leader(is_leader
=False)
68 self
.harness
.charm
.on
.config_changed
.emit()
71 self
.assertIsInstance(self
.harness
.charm
.unit
.status
, ActiveStatus
)
73 def test_publish_prometheus_info(
76 """Test to see if prometheus relation is updated."""
78 "hostname": "prometheus",
82 relation_id
= self
.harness
.add_relation("prometheus", "mon")
83 self
.harness
.add_relation_unit(relation_id
, "mon/0")
84 relation_data
= self
.harness
.get_relation_data(relation_id
, "prometheus")
86 self
.assertDictEqual(expected_result
, relation_data
)
88 def test_publish_prometheus_info_non_leader(
91 """Test to see if prometheus relation is updated."""
94 self
.harness
.set_leader(is_leader
=False)
95 relation_id
= self
.harness
.add_relation("prometheus", "mon")
96 self
.harness
.add_relation_unit(relation_id
, "mon/0")
97 relation_data
= self
.harness
.get_relation_data(relation_id
, "prometheus")
99 self
.assertDictEqual(expected_result
, relation_data
)
102 if __name__
== "__main__":