Add test in npm state.

Updated nmp module to append --dry-run when executing nmp state in test mode.

Fixes #30250.
This commit is contained in:
abednarik 2016-01-10 10:29:29 -03:00
parent 08325395cd
commit 128ded881f
3 changed files with 24 additions and 2 deletions

View File

@ -66,7 +66,8 @@ def install(pkg=None,
runas=None,
registry=None,
env=None,
silent=True):
silent=True,
dry_run=False):
'''
Install an NPM package.
@ -107,6 +108,11 @@ def install(pkg=None,
.. versionadded::2015.9.0
dry_run
Wether or not to run NPM install with --dry-run flag.
.. versionadded::2015.8.4
CLI Example:
.. code-block:: bash
@ -138,6 +144,9 @@ def install(pkg=None,
if registry:
cmd.append(' --registry="{0}"'.format(registry))
if dry_run:
cmd.append('--dry-run')
if pkg:
cmd.append(pkg)
elif pkgs:

View File

@ -274,6 +274,18 @@ def bootstrap(name,
'''
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
if __opts__['test']:
try:
call = __salt__['npm.install'](dir=name, runas=user, pkg=None, dry_run=True)
except (CommandNotFoundError, CommandExecutionError) as err:
ret['result'] = False
ret['comment'] = 'Error Bootstrapping {0!r}: {1}'.format(name, err)
return ret
ret['result'] = None
ret['changes'] = {'old': [], 'new': call}
ret['comment'] = '{0} is set to be bootstrapped'.format(name)
return ret
try:
call = __salt__['npm.install'](dir=name, runas=user, pkg=None)
except (CommandNotFoundError, CommandExecutionError) as err:
@ -289,6 +301,7 @@ def bootstrap(name,
# npm.install will return a string if it can't parse a JSON result
if isinstance(call, str):
ret['result'] = False
ret['changes'] = call
ret['comment'] = 'Could not bootstrap directory'
else:
ret['result'] = True

View File

@ -22,7 +22,7 @@ ensure_in_syspath('../../')
from salt.states import npm
npm.__salt__ = {}
npm.__opts__ = {}
npm.__opts__ = {'test': False}
@skipIf(NO_MOCK, NO_MOCK_REASON)