Debian Codegraph @

ansible_collections/community/general/tests/unit/plugins/modules/test_apk.py

raw
1 # Copyright (c) Ansible project
2 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
3 # SPDX-License-Identifier: GPL-3.0-or-later
4
5 from __future__ import annotations
6
7 import unittest
8 from unittest import mock
9
10 from ansible_collections.community.general.plugins.modules import apk
11
12
13 class TestApkQueryLatest(unittest.TestCase):
14 def setUp(self):
15 self.module_names = [
16 "bash",
17 "g++",
18 ]
19
20 @mock.patch("ansible_collections.community.general.plugins.modules.apk.AnsibleModule")
21 def test_not_latest(self, mock_module):
22 apk.APK_PATH = [""]
23 for module_name in self.module_names:
24 command_output = f"{module_name}-2.0.0-r1 < 3.0.0-r2 "
25 mock_module.run_command.return_value = (0, command_output, None)
26 command_result = apk.query_latest(mock_module, module_name)
27 self.assertFalse(command_result)
28
29 @mock.patch("ansible_collections.community.general.plugins.modules.apk.AnsibleModule")
30 def test_latest(self, mock_module):
31 apk.APK_PATH = [""]
32 for module_name in self.module_names:
33 command_output = f"{module_name}-2.0.0-r1 = 2.0.0-r1 "
34 mock_module.run_command.return_value = (0, command_output, None)
35 command_result = apk.query_latest(mock_module, module_name)
36 self.assertTrue(command_result)