Debian Codegraph @

ansible_collections/community/general/tests/unit/plugins/modules/test_macports.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 pytest
8
9 from ansible_collections.community.general.plugins.modules import macports
10
11 TESTED_MODULE = macports.__name__
12
13 QUERY_PORT_TEST_CASES = [
14 pytest.param("", False, False, id="Not installed"),
15 pytest.param(
16 " git @2.29.2_0+credential_osxkeychain+diff_highlight+doc+pcre+perl5_28",
17 True,
18 False,
19 id="Installed but not active",
20 ),
21 pytest.param(
22 " git @2.29.2_0+credential_osxkeychain+diff_highlight+doc+pcre+perl5_28 (active)",
23 True,
24 True,
25 id="Installed and active",
26 ),
27 pytest.param(
28 """ git @2.29.2_0+credential_osxkeychain+diff_highlight+doc+pcre+perl5_28
29 git @2.28.1_0+credential_osxkeychain+diff_highlight+doc+pcre+perl5_28
30 """,
31 True,
32 False,
33 id="2 versions installed, neither active",
34 ),
35 pytest.param(
36 """ git @2.29.2_0+credential_osxkeychain+diff_highlight+doc+pcre+perl5_28 (active)
37 git @2.28.1_0+credential_osxkeychain+diff_highlight+doc+pcre+perl5_28
38 """,
39 True,
40 True,
41 id="2 versions installed, one active",
42 ),
43 ]
44
45
46 @pytest.mark.parametrize("run_cmd_return_val, present_expected, active_expected", QUERY_PORT_TEST_CASES)
47 def test_macports_query_port(mocker, run_cmd_return_val, present_expected, active_expected):
48 module = mocker.Mock()
49 run_command = mocker.Mock()
50 run_command.return_value = (0, run_cmd_return_val, "")
51 module.run_command = run_command
52
53 assert macports.query_port(module, "port", "git", state="present") == present_expected
54 assert macports.query_port(module, "port", "git", state="active") == active_expected