2013-11-27 11:19:24 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2014-11-21 19:05:13 +00:00
|
|
|
# Import Python libs
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2013-06-24 22:53:59 +00:00
|
|
|
# Import Salt Testing libs
|
2013-06-27 13:04:05 +00:00
|
|
|
from salttesting import skipIf, TestCase
|
|
|
|
from salttesting.helpers import ensure_in_syspath
|
2015-03-14 21:37:07 +00:00
|
|
|
from salttesting.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch, call
|
2013-06-27 13:04:05 +00:00
|
|
|
ensure_in_syspath('../../')
|
2013-06-24 22:53:59 +00:00
|
|
|
|
2012-05-02 07:42:01 +00:00
|
|
|
|
2013-08-26 09:58:32 +00:00
|
|
|
# Import salt libs
|
|
|
|
import salt.modules.rvm as rvm
|
2012-05-03 09:33:16 +00:00
|
|
|
|
2013-08-26 09:58:32 +00:00
|
|
|
rvm.__salt__ = {
|
|
|
|
'cmd.has_exec': MagicMock(return_value=True),
|
|
|
|
'config.option': MagicMock(return_value=None)
|
|
|
|
}
|
2012-05-02 07:42:01 +00:00
|
|
|
|
2013-08-26 09:58:32 +00:00
|
|
|
|
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
2012-05-02 07:42:01 +00:00
|
|
|
class TestRvmModule(TestCase):
|
2012-05-03 09:33:16 +00:00
|
|
|
|
2012-05-02 07:42:01 +00:00
|
|
|
def test__rvm(self):
|
2012-05-03 09:33:16 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(rvm.__salt__, {'cmd.run_all': mock}):
|
2013-06-24 22:53:59 +00:00
|
|
|
rvm._rvm('install', '1.9.3')
|
2012-06-30 20:10:34 +00:00
|
|
|
mock.assert_called_once_with(
|
2014-05-23 20:38:04 +00:00
|
|
|
'/usr/local/rvm/bin/rvm install 1.9.3', runas=None, cwd=None
|
2012-06-30 20:10:34 +00:00
|
|
|
)
|
2012-05-03 09:33:16 +00:00
|
|
|
|
|
|
|
def test__rvm_do(self):
|
2015-03-14 21:37:07 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': 'stdout'})
|
|
|
|
with patch.dict(rvm.__salt__, {'cmd.run_all': mock}):
|
2013-06-24 22:53:59 +00:00
|
|
|
rvm._rvm_do('1.9.3', 'gemset list')
|
2015-03-14 21:37:07 +00:00
|
|
|
mock.assert_called_once_with('/usr/local/rvm/bin/rvm 1.9.3 do gemset list', runas=None, cwd=None)
|
2012-05-03 09:33:16 +00:00
|
|
|
|
2012-05-02 07:42:01 +00:00
|
|
|
def test_install(self):
|
2013-07-13 16:46:46 +00:00
|
|
|
mock = MagicMock(return_value={'retcode': 0})
|
|
|
|
with patch.dict(rvm.__salt__, {'cmd.run_all': mock}):
|
2012-05-03 09:33:16 +00:00
|
|
|
rvm.install()
|
2015-03-14 21:37:07 +00:00
|
|
|
mock.assert_called_once_with('curl -Ls https://raw.githubusercontent.com/wayneeseguin/rvm/master/binscripts/rvm-installer | bash -s stable', runas=None, python_shell=True)
|
|
|
|
|
|
|
|
def test_install_ruby_nonroot(self):
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': 'stdout'})
|
|
|
|
expected = [
|
|
|
|
call('/usr/local/rvm/bin/rvm autolibs disable 2.0.0', runas='rvm', cwd=None),
|
|
|
|
call('/usr/local/rvm/bin/rvm install --disable-binary 2.0.0', runas='rvm', cwd=None)]
|
|
|
|
with patch.dict(rvm.__salt__, {'cmd.run_all': mock}):
|
|
|
|
rvm.install_ruby('2.0.0', runas='rvm')
|
|
|
|
self.assertEqual(mock.call_args_list, expected)
|
2012-05-03 09:33:16 +00:00
|
|
|
|
|
|
|
def test_list(self):
|
|
|
|
list_output = '''
|
|
|
|
rvm rubies
|
|
|
|
|
|
|
|
jruby-1.6.5.1 [ amd64 ]
|
|
|
|
ree-1.8.7-2011.03 [ x86_64 ]
|
|
|
|
ree-1.8.7-2011.12 [ x86_64 ]
|
|
|
|
=* ree-1.8.7-2012.02 [ x86_64 ]
|
|
|
|
ruby-1.9.2-p180 [ x86_64 ]
|
|
|
|
ruby-1.9.3-p125 [ x86_64 ]
|
|
|
|
ruby-head [ x86_64 ]
|
|
|
|
|
|
|
|
# => - current
|
|
|
|
# =* - current && default
|
|
|
|
# * - default
|
|
|
|
|
|
|
|
'''
|
2012-06-19 00:19:03 +00:00
|
|
|
with patch.object(rvm, '_rvm') as mock_method:
|
|
|
|
mock_method.return_value = list_output
|
2012-05-03 09:33:16 +00:00
|
|
|
self.assertEqual(
|
|
|
|
[['jruby', '1.6.5.1', False],
|
|
|
|
['ree', '1.8.7-2011.03', False],
|
|
|
|
['ree', '1.8.7-2011.12', False],
|
|
|
|
['ree', '1.8.7-2012.02', True],
|
|
|
|
['ruby', '1.9.2-p180', False],
|
|
|
|
['ruby', '1.9.3-p125', False],
|
|
|
|
['ruby', 'head', False]],
|
2013-05-29 05:54:38 +00:00
|
|
|
rvm.list_())
|
2012-05-03 09:33:16 +00:00
|
|
|
|
|
|
|
def test_gemset_list(self):
|
|
|
|
output = '''
|
|
|
|
gemsets for ree-1.8.7-2012.02 (found in /usr/local/rvm/gems/ree-1.8.7-2012.02)
|
|
|
|
global
|
|
|
|
bar
|
|
|
|
foo
|
|
|
|
|
|
|
|
'''
|
2012-06-19 00:19:03 +00:00
|
|
|
with patch.object(rvm, '_rvm_do') as mock_method:
|
|
|
|
mock_method.return_value = output
|
2012-05-03 09:33:16 +00:00
|
|
|
self.assertEqual(
|
|
|
|
['global', 'bar', 'foo'],
|
|
|
|
rvm.gemset_list())
|
|
|
|
|
|
|
|
def test_gemset_list_all(self):
|
|
|
|
output = '''
|
|
|
|
|
|
|
|
gemsets for ruby-1.9.3-p125 (found in /usr/local/rvm/gems/ruby-1.9.3-p125)
|
|
|
|
9bar
|
|
|
|
9foo
|
|
|
|
global
|
|
|
|
|
|
|
|
|
|
|
|
gemsets for ruby-head (found in /usr/local/rvm/gems/ruby-head)
|
|
|
|
global
|
|
|
|
headbar
|
|
|
|
headfoo
|
|
|
|
|
|
|
|
|
|
|
|
gemsets for jruby-1.6.5.1 (found in /usr/local/rvm/gems/jruby-1.6.5.1)
|
|
|
|
global
|
|
|
|
jbar
|
|
|
|
jfoo
|
|
|
|
|
|
|
|
|
|
|
|
gemsets for ruby-1.9.2-p180 (found in /usr/local/rvm/gems/ruby-1.9.2-p180)
|
|
|
|
global
|
|
|
|
|
|
|
|
|
|
|
|
'''
|
2012-06-19 00:19:03 +00:00
|
|
|
with patch.object(rvm, '_rvm_do') as mock_method:
|
|
|
|
mock_method.return_value = output
|
2012-05-03 09:33:16 +00:00
|
|
|
self.assertEqual(
|
|
|
|
{'jruby-1.6.5.1': ['global', 'jbar', 'jfoo'],
|
|
|
|
'ruby-1.9.2-p180': ['global'],
|
|
|
|
'ruby-1.9.3-p125': ['9bar', '9foo', 'global'],
|
|
|
|
'ruby-head': ['global', 'headbar', 'headfoo']},
|
|
|
|
rvm.gemset_list_all())
|
|
|
|
|
2013-06-24 22:53:59 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
from integration import run_tests
|
|
|
|
run_tests(TestRvmModule, needs_daemon=False)
|