diff --git a/.gitignore b/.gitignore index 3c562c4..2541021 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ .DS_Store **/.DS_Store +tests/output/ + # Editor swapfiles *~ diff --git a/plugins/modules/ibridges_sync.py b/plugins/modules/ibridges_sync.py index 70b400b..eb41ca2 100644 --- a/plugins/modules/ibridges_sync.py +++ b/plugins/modules/ibridges_sync.py @@ -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) @@ -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") diff --git a/tests/unit/plugins/modules/test_ibridges_sync.py b/tests/unit/plugins/modules/test_ibridges_sync.py index 56cbe4a..bf635e5 100644 --- a/tests/unit/plugins/modules/test_ibridges_sync.py +++ b/tests/unit/plugins/modules/test_ibridges_sync.py @@ -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/', @@ -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):