From dbe5ffe7c9f46a3d8843e3ed69a2c8ec0a2a0383 Mon Sep 17 00:00:00 2001 From: rsuplina Date: Thu, 11 Jan 2024 16:20:59 +0000 Subject: [PATCH] Add pytest for CM Service module Signed-off-by: rsuplina --- .../modules/cm_service/test_cm_service.py | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/unit/plugins/modules/cm_service/test_cm_service.py diff --git a/tests/unit/plugins/modules/cm_service/test_cm_service.py b/tests/unit/plugins/modules/cm_service/test_cm_service.py new file mode 100644 index 00000000..0b175cd7 --- /dev/null +++ b/tests/unit/plugins/modules/cm_service/test_cm_service.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- + +# Copyright 2024 Cloudera, Inc. All Rights Reserved. +# +# 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. + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type +import os +import logging +import pytest + +from ansible_collections.cloudera.cluster.plugins.modules import cm_service +from ansible_collections.cloudera.cluster.tests.unit import AnsibleExitJson, AnsibleFailJson + +LOG = logging.getLogger(__name__) + +def test_pytest_cm_service(module_args): + module_args( + { + "username": os.getenv('CM_USERNAME'), + "password": os.getenv('CM_PASSWORD'), + "host": os.getenv('CM_HOST'), + "port": "7180", + "verify_tls": "no", + "debug": "yes", + "state": "started", + "role" : [ "SERVICEMONITOR" , "HOSTMONITOR", "EVENTSERVER", "ALERTPUBLISHER" ] + } + ) + + # with pytest.raises(AnsibleFailJson, match=r"boom") as e: + with pytest.raises(AnsibleExitJson) as e: + cm_service.main() + + # LOG.info(str(e.value)) + LOG.info(str(e.value.cloudera_manager))