mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #50580 from garethgreenaway/50155_artificatory_download_state_test_true
[2018.3] Adding test=True to artifactory.download.
This commit is contained in:
commit
735c9f431b
2 changed files with 43 additions and 6 deletions
|
@ -84,12 +84,18 @@ def downloaded(name, artifact, target_dir='/tmp', target_file=None, use_literal_
|
|||
'changes': {},
|
||||
'comment': ''}
|
||||
|
||||
try:
|
||||
fetch_result = __fetch_from_artifactory(artifact, target_dir, target_file, use_literal_group_id)
|
||||
except Exception as exc:
|
||||
ret['result'] = False
|
||||
ret['comment'] = six.text_type(exc)
|
||||
return ret
|
||||
if 'test' in __opts__ and __opts__['test'] is True:
|
||||
fetch_result = {}
|
||||
fetch_result['status'] = True
|
||||
fetch_result['comment'] = 'Artifact would be downloaded from URL: {0}'.format(artifact['artifactory_url'])
|
||||
fetch_result['changes'] = {}
|
||||
else:
|
||||
try:
|
||||
fetch_result = __fetch_from_artifactory(artifact, target_dir, target_file, use_literal_group_id)
|
||||
except Exception as exc:
|
||||
ret['result'] = False
|
||||
ret['comment'] = six.text_type(exc)
|
||||
return ret
|
||||
|
||||
log.debug('fetch_result = %s', fetch_result)
|
||||
|
||||
|
|
|
@ -55,3 +55,34 @@ class ArtifactoryTestCase(TestCase, LoaderModuleMockMixin):
|
|||
ret = artifactory.downloaded(name, artifact)
|
||||
self.assertEqual(ret['result'], False)
|
||||
self.assertEqual(ret['comment'], 'error')
|
||||
|
||||
# 'downloaded test=True' function tests: 1
|
||||
|
||||
def test_downloaded_test_true(self):
|
||||
'''
|
||||
Test to ensures that the artifact from artifactory exists at
|
||||
given location.
|
||||
'''
|
||||
name = 'jboss'
|
||||
arti_url = 'http://artifactory.intranet.example.com/artifactory'
|
||||
artifact = {'artifactory_url': arti_url, 'artifact_id': 'module',
|
||||
'repository': 'libs-release-local', 'packaging': 'jar',
|
||||
'group_id': 'com.company.module', 'classifier': 'sources',
|
||||
'version': '1.0'}
|
||||
|
||||
ret = {'name': name,
|
||||
'result': True,
|
||||
'changes': {},
|
||||
'comment': 'Artifact would be downloaded from URL: http://artifactory.intranet.example.com/artifactory'}
|
||||
|
||||
mck = MagicMock(return_value={'status': False, 'changes': {},
|
||||
'comment': ''})
|
||||
with patch.dict(artifactory.__salt__, {'artifactory.get_release': mck}):
|
||||
with patch.dict(artifactory.__opts__, {'test': True}):
|
||||
self.assertDictEqual(artifactory.downloaded(name, artifact), ret)
|
||||
|
||||
with patch.object(artifactory, '__fetch_from_artifactory',
|
||||
MagicMock(side_effect=Exception('error'))):
|
||||
ret = artifactory.downloaded(name, artifact)
|
||||
self.assertEqual(ret['result'], False)
|
||||
self.assertEqual(ret['comment'], 'error')
|
||||
|
|
Loading…
Add table
Reference in a new issue