Skip to content

Commit

Permalink
Refactor for ibridges 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dometto committed Aug 20, 2024
1 parent 895ded5 commit c79d2f1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.DS_Store
**/.DS_Store

tests/output/

# Editor swapfiles
*~

Expand Down
17 changes: 10 additions & 7 deletions plugins/modules/ibridges_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ def run_module():
if module.params['mode'] == 'up':
source = locations[0]
target = locations[1]
changed_paths_key = 'upload'
new_folders_key = 'create_collection'
changed_paths_func = 'upload'
new_folders_func = 'create_collection'
elif module.params['mode'] == 'down':
source = locations[1]
target = locations[0]
changed_paths_key = 'download'
new_folders_key = 'create_dir'
changed_paths_func = 'download'
new_folders_func = 'create_dir'
else:
module.fail_json(msg='Unsupported sync mode "{mode}", choose either "up" or "down".'.format(mode=module.params['mode']), changed=False)

Expand All @@ -165,14 +165,17 @@ def run_module():
except Exception as e:
module.fail_json(msg='Encountered an error when executing iBridges sync: {}'.format(repr(e)), changed=False)

changed_paths = getattr(sync_result, changed_paths_func)
new_folders = getattr(sync_result, new_folders_func)

if module.check_mode:
result['msg'] = 'Executed iBridges dry run.'
result['changed'] = False
else:
result['changed'] = False if len(sync_result[changed_paths_key]) + len(sync_result[new_folders_key]) == 0 else True
result['changed'] = False if len(changed_paths) + len(new_folders) == 0 else True

result['changed_files'] = [str(path_pair[1]) for path_pair in sync_result[changed_paths_key]]
result['new_folders'] = list(sync_result[new_folders_key])
result['changed_files'] = [str(path_pair[1]) for path_pair in changed_paths]
result['new_folders'] = list(new_folders)

result['stdout'] = ibridges_stdout.getvalue()
result['stdout_lines'] = result['stdout'].split("\n")
Expand Down
8 changes: 7 additions & 1 deletion tests/unit/plugins/modules/test_ibridges_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from plugins.modules import ibridges_sync
from pathlib import Path

from ibridges.executor import Operations

DEFAULT_ARGS = {
'irods_path': '/test',
'local_path': '/tmp/',
Expand Down Expand Up @@ -35,7 +37,11 @@ def mock_sync_result(**kwargs):
'resc_name': '',
'options': None
}
return {**defaults, **kwargs}
options = {**defaults, **kwargs}
ops = Operations(resc_name=options['resc_name'])
for k, v in options.items():
setattr(ops, k, v)
return ops


def mock_module_result(**kwargs):
Expand Down

0 comments on commit c79d2f1

Please sign in to comment.