# Copyright (c) 2017 Ansible Project # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) # SPDX-License-Identifier: GPL-3.0-or-later from __future__ import annotations import pytest from ansible.module_utils import basic from ansible_collections.community.general.plugins.modules import maven_artifact pytestmark = pytest.mark.usefixtures("patch_ansible_module") maven_metadata_example = b""" junit junit 4.13-beta-2 4.13-beta-2 3.7 3.8 3.8.1 3.8.2 4.0 4.1 4.2 4.3 4.3.1 4.4 4.5 4.6 4.7 4.8 4.8.1 4.8.2 4.9 4.10 4.11-beta-1 4.11 4.12-beta-1 4.12-beta-2 4.12-beta-3 4.12 4.13-beta-1 4.13-beta-2 20190202141051 """ @pytest.mark.parametrize( "patch_ansible_module, version_by_spec, version_choosed", [ (None, "(,3.9]", "3.8.2"), (None, "3.0", "3.8.2"), (None, "[3.7]", "3.7"), (None, "[4.10, 4.12]", "4.12"), (None, "[4.10, 4.12)", "4.11"), (None, "[2.0,)", "4.13-beta-2"), ], ) def test_find_version_by_spec(mocker, version_by_spec, version_choosed): _getContent = mocker.patch( "ansible_collections.community.general.plugins.modules.maven_artifact.MavenDownloader._getContent" ) _getContent.return_value = maven_metadata_example artifact = maven_artifact.Artifact("junit", "junit", None, version_by_spec, "jar") mvn_downloader = maven_artifact.MavenDownloader(basic.AnsibleModule, "https://repo1.maven.org/maven2") assert mvn_downloader.find_version_by_spec(artifact) == version_choosed