summaryrefslogtreecommitdiff
path: root/test/units/galaxy/test_collection.py
diff options
context:
space:
mode:
authorJordan Borean <jborean93@gmail.com>2019-11-14 05:02:58 +1000
committerGitHub <noreply@github.com>2019-11-14 05:02:58 +1000
commitf8f76628500052ad3521fbec16c073ae7f99d287 (patch)
tree81c6dc4750458b8bf1b305d727d2cf13f1d90560 /test/units/galaxy/test_collection.py
parentbf190606835d67998232140541bf848a51510c5c (diff)
downloadansible-f8f76628500052ad3521fbec16c073ae7f99d287.tar.gz
Add the ability to ignore files and collection build (#64688)
Diffstat (limited to 'test/units/galaxy/test_collection.py')
-rw-r--r--test/units/galaxy/test_collection.py83
1 files changed, 75 insertions, 8 deletions
diff --git a/test/units/galaxy/test_collection.py b/test/units/galaxy/test_collection.py
index 18df8bbdcd..3efd47d5d8 100644
--- a/test/units/galaxy/test_collection.py
+++ b/test/units/galaxy/test_collection.py
@@ -248,24 +248,37 @@ def test_build_ignore_files_and_folders(collection_input, monkeypatch):
git_folder = os.path.join(input_dir, '.git')
retry_file = os.path.join(input_dir, 'ansible.retry')
+ tests_folder = os.path.join(input_dir, 'tests', 'output')
+ tests_output_file = os.path.join(tests_folder, 'result.txt')
+
os.makedirs(git_folder)
+ os.makedirs(tests_folder)
+
with open(retry_file, 'w+') as ignore_file:
ignore_file.write('random')
ignore_file.flush()
- actual = collection._build_files_manifest(to_bytes(input_dir), 'namespace', 'collection')
+ with open(tests_output_file, 'w+') as tests_file:
+ tests_file.write('random')
+ tests_file.flush()
+
+ actual = collection._build_files_manifest(to_bytes(input_dir), 'namespace', 'collection', [])
assert actual['format'] == 1
for manifest_entry in actual['files']:
- assert manifest_entry['name'] not in ['.git', 'ansible.retry', 'galaxy.yml']
+ assert manifest_entry['name'] not in ['.git', 'ansible.retry', 'galaxy.yml', 'tests/output', 'tests/output/result.txt']
expected_msgs = [
+ "Skipping '%s/galaxy.yml' for collection build" % to_text(input_dir),
"Skipping '%s' for collection build" % to_text(retry_file),
"Skipping '%s' for collection build" % to_text(git_folder),
+ "Skipping '%s' for collection build" % to_text(tests_folder),
]
- assert mock_display.call_count == 2
+ assert mock_display.call_count == 4
assert mock_display.mock_calls[0][1][0] in expected_msgs
assert mock_display.mock_calls[1][1][0] in expected_msgs
+ assert mock_display.mock_calls[2][1][0] in expected_msgs
+ assert mock_display.mock_calls[3][1][0] in expected_msgs
def test_build_ignore_older_release_in_root(collection_input, monkeypatch):
@@ -285,7 +298,7 @@ def test_build_ignore_older_release_in_root(collection_input, monkeypatch):
file_obj.write('random')
file_obj.flush()
- actual = collection._build_files_manifest(to_bytes(input_dir), 'namespace', 'collection')
+ actual = collection._build_files_manifest(to_bytes(input_dir), 'namespace', 'collection', [])
assert actual['format'] == 1
plugin_release_found = False
@@ -296,8 +309,62 @@ def test_build_ignore_older_release_in_root(collection_input, monkeypatch):
assert plugin_release_found
- assert mock_display.call_count == 1
- assert mock_display.mock_calls[0][1][0] == "Skipping '%s' for collection build" % to_text(release_file)
+ expected_msgs = [
+ "Skipping '%s/galaxy.yml' for collection build" % to_text(input_dir),
+ "Skipping '%s' for collection build" % to_text(release_file)
+ ]
+ assert mock_display.call_count == 2
+ assert mock_display.mock_calls[0][1][0] in expected_msgs
+ assert mock_display.mock_calls[1][1][0] in expected_msgs
+
+
+def test_build_ignore_patterns(collection_input, monkeypatch):
+ input_dir = collection_input[0]
+
+ mock_display = MagicMock()
+ monkeypatch.setattr(Display, 'vvv', mock_display)
+
+ actual = collection._build_files_manifest(to_bytes(input_dir), 'namespace', 'collection',
+ ['*.md', 'plugins/action', 'playbooks/*.j2'])
+ assert actual['format'] == 1
+
+ expected_missing = [
+ 'README.md',
+ 'docs/My Collection.md',
+ 'plugins/action',
+ 'playbooks/templates/test.conf.j2',
+ 'playbooks/templates/subfolder/test.conf.j2',
+ ]
+
+ # Files or dirs that are close to a match but are not, make sure they are present
+ expected_present = [
+ 'docs',
+ 'roles/common/templates/test.conf.j2',
+ 'roles/common/templates/subfolder/test.conf.j2',
+ ]
+
+ actual_files = [e['name'] for e in actual['files']]
+ for m in expected_missing:
+ assert m not in actual_files
+
+ for p in expected_present:
+ assert p in actual_files
+
+ expected_msgs = [
+ "Skipping '%s/galaxy.yml' for collection build" % to_text(input_dir),
+ "Skipping '%s/README.md' for collection build" % to_text(input_dir),
+ "Skipping '%s/docs/My Collection.md' for collection build" % to_text(input_dir),
+ "Skipping '%s/plugins/action' for collection build" % to_text(input_dir),
+ "Skipping '%s/playbooks/templates/test.conf.j2' for collection build" % to_text(input_dir),
+ "Skipping '%s/playbooks/templates/subfolder/test.conf.j2' for collection build" % to_text(input_dir),
+ ]
+ assert mock_display.call_count == len(expected_msgs)
+ assert mock_display.mock_calls[0][1][0] in expected_msgs
+ assert mock_display.mock_calls[1][1][0] in expected_msgs
+ assert mock_display.mock_calls[2][1][0] in expected_msgs
+ assert mock_display.mock_calls[3][1][0] in expected_msgs
+ assert mock_display.mock_calls[4][1][0] in expected_msgs
+ assert mock_display.mock_calls[5][1][0] in expected_msgs
def test_build_ignore_symlink_target_outside_collection(collection_input, monkeypatch):
@@ -309,7 +376,7 @@ def test_build_ignore_symlink_target_outside_collection(collection_input, monkey
link_path = os.path.join(input_dir, 'plugins', 'connection')
os.symlink(outside_dir, link_path)
- actual = collection._build_files_manifest(to_bytes(input_dir), 'namespace', 'collection')
+ actual = collection._build_files_manifest(to_bytes(input_dir), 'namespace', 'collection', [])
for manifest_entry in actual['files']:
assert manifest_entry['name'] != 'plugins/connection'
@@ -333,7 +400,7 @@ def test_build_copy_symlink_target_inside_collection(collection_input):
os.symlink(roles_target, roles_link)
- actual = collection._build_files_manifest(to_bytes(input_dir), 'namespace', 'collection')
+ actual = collection._build_files_manifest(to_bytes(input_dir), 'namespace', 'collection', [])
linked_entries = [e for e in actual['files'] if e['name'].startswith('playbooks/roles/linked')]
assert len(linked_entries) == 3