summaryrefslogtreecommitdiffstats
path: root/test/units/galaxy/test_collection_install.py
diff options
context:
space:
mode:
authorJordan Borean <jborean93@gmail.com>2020-02-13 23:23:17 +0100
committerGitHub <noreply@github.com>2020-02-13 23:23:17 +0100
commit4881af2e7e0506ada0225fd764e874e20569d5b2 (patch)
tree61f4a33101393a283195bd0731a2bb7d23f9e453 /test/units/galaxy/test_collection_install.py
parentCloudRetry/AWSRetry : Disable catching of NotFound exceptions (#67281) (diff)
downloadansible-4881af2e7e0506ada0225fd764e874e20569d5b2.tar.xz
ansible-4881af2e7e0506ada0225fd764e874e20569d5b2.zip
galaxy - Fix collection install dep resolver for bad versions (#67405)
* Also make sure version is a string and not an int/float
Diffstat (limited to '')
-rw-r--r--test/units/galaxy/test_collection_install.py60
1 files changed, 52 insertions, 8 deletions
diff --git a/test/units/galaxy/test_collection_install.py b/test/units/galaxy/test_collection_install.py
index 3efd833b18..fc437db681 100644
--- a/test/units/galaxy/test_collection_install.py
+++ b/test/units/galaxy/test_collection_install.py
@@ -165,13 +165,14 @@ def test_build_requirement_from_path(collection_artifact):
assert actual.dependencies == {}
-def test_build_requirement_from_path_with_manifest(collection_artifact):
+@pytest.mark.parametrize('version', ['1.1.1', 1.1, 1])
+def test_build_requirement_from_path_with_manifest(version, collection_artifact):
manifest_path = os.path.join(collection_artifact[0], b'MANIFEST.json')
manifest_value = json.dumps({
'collection_info': {
'namespace': 'namespace',
'name': 'name',
- 'version': '1.1.1',
+ 'version': version,
'dependencies': {
'ansible_namespace.collection': '*'
}
@@ -188,8 +189,8 @@ def test_build_requirement_from_path_with_manifest(collection_artifact):
assert actual.b_path == collection_artifact[0]
assert actual.api is None
assert actual.skip is True
- assert actual.versions == set([u'1.1.1'])
- assert actual.latest_version == u'1.1.1'
+ assert actual.versions == set([to_text(version)])
+ assert actual.latest_version == to_text(version)
assert actual.dependencies == {'ansible_namespace.collection': '*'}
@@ -203,6 +204,42 @@ def test_build_requirement_from_path_invalid_manifest(collection_artifact):
collection.CollectionRequirement.from_path(collection_artifact[0], True)
+def test_build_requirement_from_path_no_version(collection_artifact, monkeypatch):
+ manifest_path = os.path.join(collection_artifact[0], b'MANIFEST.json')
+ manifest_value = json.dumps({
+ 'collection_info': {
+ 'namespace': 'namespace',
+ 'name': 'name',
+ 'version': '',
+ 'dependencies': {}
+ }
+ })
+ with open(manifest_path, 'wb') as manifest_obj:
+ manifest_obj.write(to_bytes(manifest_value))
+
+ mock_display = MagicMock()
+ monkeypatch.setattr(Display, 'display', mock_display)
+
+ actual = collection.CollectionRequirement.from_path(collection_artifact[0], True)
+
+ # While the folder name suggests a different collection, we treat MANIFEST.json as the source of truth.
+ assert actual.namespace == u'namespace'
+ assert actual.name == u'name'
+ assert actual.b_path == collection_artifact[0]
+ assert actual.api is None
+ assert actual.skip is True
+ assert actual.versions == set(['*'])
+ assert actual.latest_version == u'*'
+ assert actual.dependencies == {}
+
+ assert mock_display.call_count == 1
+
+ actual_warn = ' '.join(mock_display.mock_calls[0][1][0].split('\n'))
+ expected_warn = "Collection at '%s' does not have a valid version set, falling back to '*'. Found version: ''" \
+ % to_text(collection_artifact[0])
+ assert expected_warn in actual_warn
+
+
def test_build_requirement_from_tar(collection_artifact):
actual = collection.CollectionRequirement.from_tar(collection_artifact[1], True, True)
@@ -497,13 +534,20 @@ def test_add_collection_requirements(versions, requirement, expected_filter, exp
assert req.latest_version == expected_latest
-def test_add_collection_requirement_to_unknown_installed_version():
+def test_add_collection_requirement_to_unknown_installed_version(monkeypatch):
+ mock_display = MagicMock()
+ monkeypatch.setattr(Display, 'display', mock_display)
+
req = collection.CollectionRequirement('namespace', 'name', None, 'https://galaxy.com', ['*'], '*', False,
skip=True)
- expected = "Cannot meet requirement namespace.name:1.0.0 as it is already installed at version 'unknown'."
- with pytest.raises(AnsibleError, match=expected):
- req.add_requirement(str(req), '1.0.0')
+ req.add_requirement('parent.collection', '1.0.0')
+ assert req.latest_version == '*'
+
+ assert mock_display.call_count == 1
+
+ actual_warn = ' '.join(mock_display.mock_calls[0][1][0].split('\n'))
+ assert "Failed to validate the collection requirement 'namespace.name:1.0.0' for parent.collection" in actual_warn
def test_add_collection_wildcard_requirement_to_unknown_installed_version():