From 07d5f8922454d99e546f479d8d01af0cd215b4d9 Mon Sep 17 00:00:00 2001
From: Liam Young <liam.young@canonical.com>
Date: Thu, 3 Feb 2022 18:51:13 +0000
Subject: [PATCH] Base unit test

---
 charms/ovn-central-k8s/unit_tests/__init__.py |  0
 .../unit_tests/test_ovn_central_charm.py      | 74 +++++++++++++++++++
 2 files changed, 74 insertions(+)
 create mode 100644 charms/ovn-central-k8s/unit_tests/__init__.py
 create mode 100644 charms/ovn-central-k8s/unit_tests/test_ovn_central_charm.py

diff --git a/charms/ovn-central-k8s/unit_tests/__init__.py b/charms/ovn-central-k8s/unit_tests/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/charms/ovn-central-k8s/unit_tests/test_ovn_central_charm.py b/charms/ovn-central-k8s/unit_tests/test_ovn_central_charm.py
new file mode 100644
index 00000000..3fa3ddd8
--- /dev/null
+++ b/charms/ovn-central-k8s/unit_tests/test_ovn_central_charm.py
@@ -0,0 +1,74 @@
+#!/usr/bin/env python3
+
+# Copyright 2021 Canonical Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import sys
+
+sys.path.append('lib')  # noqa
+sys.path.append('src')  # noqa
+
+import charm
+import advanced_sunbeam_openstack.test_utils as test_utils
+
+
+class _OVNCentralWallabyOperatorCharm(charm.OVNCentralWallabyOperatorCharm):
+
+    def __init__(self, framework):
+        self.seen_events = []
+        self.render_calls = []
+        super().__init__(framework)
+
+    def _log_event(self, event):
+        self.seen_events.append(type(event).__name__)
+
+    def renderer(self, containers, container_configs, template_dir,
+                 openstack_release, adapters):
+        self.render_calls.append(
+            (
+                containers,
+                container_configs,
+                template_dir,
+                openstack_release,
+                adapters))
+
+    def configure_charm(self, event):
+        super().configure_charm(event)
+        self._log_event(event)
+
+
+class TestOVNCentralWallabyOperatorCharm(test_utils.CharmTestCase):
+
+    PATCHES = [
+        'KubernetesServicePatch',
+    ]
+
+    def setUp(self):
+        self.container_calls = {
+            'push': {},
+            'pull': [],
+            'remove_path': []}
+        super().setUp(charm, self.PATCHES)
+        self.harness = test_utils.get_harness(
+            _OVNCentralWallabyOperatorCharm,
+            container_calls=self.container_calls)
+        self.addCleanup(self.harness.cleanup)
+        self.harness.begin()
+
+    def test_pebble_ready_handler(self):
+        self.assertEqual(self.harness.charm.seen_events, [])
+        self.harness.container_pebble_ready('ovn-sb-db-server')
+        self.harness.container_pebble_ready('ovn-nb-db-server')
+        self.harness.container_pebble_ready('ovn-northd')
+        self.assertEqual(len(self.harness.charm.seen_events), 3)