New dedicated test case for checkout latest tag
@@ -81,6 +81,17 @@ def mock_is_dir_func(path):
return original_is_dir_func(path)
+def mock_get_gitref(repo, ref):
+ """
+ Mock get_gitref function which return mocked object if ref passed is
+ PACK_INDEX['test']['version']
+ """
+ if ref == 'v%s' % PACK_INDEX['test']['version']:
+ return mock.MagicMock(hexsha=PACK_INDEX['test']['version'])
+ else:
+ return None
+
+
@mock.patch.object(pack_service, 'fetch_pack_index', mock.MagicMock(return_value=(PACK_INDEX, {})))
class DownloadGitRepoActionTestCase(BaseActionTestCase):
action_cls = DownloadGitRepoAction
@@ -572,3 +583,28 @@ class DownloadGitRepoActionTestCase(BaseActionTestCase):
destination_path = os.path.join(self.repo_base, 'test4')
self.assertTrue(os.path.exists(destination_path))
self.assertTrue(os.path.exists(os.path.join(destination_path, 'pack.yaml')))
+
+ @mock.patch('st2common.util.pack_management.get_gitref', mock_get_gitref)
+ def test_run_pack_download_with_tag(self):
+ action = self.get_action_instance()
+ result = action.run(packs=['test'], abs_repo_base=self.repo_base)
+ temp_dir = hashlib.md5(PACK_INDEX['test']['repo_url'].encode()).hexdigest()
+
+ self.assertEqual(result, {'test': 'Success.'})
+ self.clone_from.assert_called_once_with(PACK_INDEX['test']['repo_url'],
+ os.path.join(os.path.expanduser('~'), temp_dir))
+ self.assertTrue(os.path.isfile(os.path.join(self.repo_base, 'test/pack.yaml')))
+
+ # Check repo.git.checkout is called three times
+ self.assertEqual(self.repo_instance.git.checkout.call_count, 3)
+
+ # Check repo.git.checkout called with latest tag or branch
+ self.assertEqual(PACK_INDEX['test']['version'],
+ self.repo_instance.git.checkout.call_args_list[1][0][0])
+
+ # Check repo.git.checkout called with head
+ self.assertEqual(self.repo_instance.head.reference,
+ self.repo_instance.git.checkout.call_args_list[2][0][0])
+
+ self.repo_instance.git.branch.assert_called_with(
+ '-f', self.repo_instance.head.reference, PACK_INDEX['test']['version'])
