diff --git a/ci-scripts/tests/README.md b/ci-scripts/tests/README.md new file mode 100644 index 0000000000..685a19d0cc --- /dev/null +++ b/ci-scripts/tests/README.md @@ -0,0 +1,11 @@ +In this directory and subdirectories are various CI code test cases and helper +scripts. + +# Unit test + +There are some unit tests. From the parent directory, i.e., `ci-scripts/`, +start with + + python tests/deployment.py -v + +It will indicate if all tests passed. diff --git a/ci-scripts/tests/deployment.py b/ci-scripts/tests/deployment.py new file mode 100644 index 0000000000..e4176ec79d --- /dev/null +++ b/ci-scripts/tests/deployment.py @@ -0,0 +1,47 @@ +import sys +import logging +logging.basicConfig( + level=logging.DEBUG, + stream=sys.stdout, + format="[%(asctime)s] %(levelname)8s: %(message)s" +) +import os +os.system(f'rm -rf cmake_targets') +os.system(f'mkdir -p cmake_targets/log') +import unittest + +sys.path.append('./') # to find OAI imports below +import cls_oai_html +import cls_oaicitest +import cls_containerize +import ran + +class TestDeploymentMethods(unittest.TestCase): + def setUp(self): + self.html = cls_oai_html.HTMLManagement() + self.html.testCaseId = "000000" + self.ci = cls_oaicitest.OaiCiTest() + self.cont = cls_containerize.Containerize() + self.ran = ran.RANManagement() + self.cont.yamlPath[0] = 'tests/simple-dep/' + self.cont.eNB_serverId[0] = '0' + self.cont.eNBIPAddress = 'localhost' + self.cont.eNBUserName = None + self.cont.eNBPassword = None + self.cont.eNBSourceCodePath = os.getcwd() + + def test_deploy(self): + self.cont.DeployObject(self.html) + self.assertEqual(self.cont.exitStatus, 0) + self.cont.UndeployObject(self.html, self.ran) + + def test_deployfails(self): + old = self.cont.yamlPath + self.cont.yamlPath[0] = 'tests/simple-fail/' + self.cont.DeployObject(self.html) + self.assertEqual(self.cont.exitStatus, 1) + self.cont.UndeployObject(self.html, self.ran) + self.cont.yamlPath = old + +if __name__ == '__main__': + unittest.main() diff --git a/ci-scripts/tests/simple-dep/docker-compose.yml b/ci-scripts/tests/simple-dep/docker-compose.yml new file mode 100644 index 0000000000..950e30a814 --- /dev/null +++ b/ci-scripts/tests/simple-dep/docker-compose.yml @@ -0,0 +1,12 @@ +services: + test: + image: ubuntu:jammy + container_name: test_container + cap_drop: + - ALL + entrypoint: /bin/bash -c "sleep infinity" + healthcheck: + test: /bin/bash -c "true" + interval: 1s + timeout: 1s + retries: 1 diff --git a/ci-scripts/tests/simple-fail/docker-compose.yml b/ci-scripts/tests/simple-fail/docker-compose.yml new file mode 100644 index 0000000000..c6d5a04e4a --- /dev/null +++ b/ci-scripts/tests/simple-fail/docker-compose.yml @@ -0,0 +1,12 @@ +services: + test: + image: ubuntu:jammy + container_name: test_container + cap_drop: + - ALL + entrypoint: /bin/bash -c "false" + healthcheck: + test: /bin/bash -c "true" + interval: 1s + timeout: 1s + retries: 1