123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- # -*- coding: utf-8 -*-
- '''Unit test for saltcheck execution module'''
- # Import Python libs
- from __future__ import absolute_import, unicode_literals, print_function
- import os.path
- try:
- import salt.modules.saltcheck as saltcheck
- import salt.config
- import salt.syspaths as syspaths
- except:
- raise
- # Import Salt Testing Libs
- try:
- from tests.support.mixins import LoaderModuleMockMixin
- from tests.support.unit import TestCase
- from tests.support.mock import (
- MagicMock,
- patch,
- )
- except:
- raise
- class LinuxSysctlTestCase(TestCase, LoaderModuleMockMixin):
- '''
- TestCase for salt.modules.saltcheck module
- '''
- def setup_loader_modules(self):
- # Setting the environment to be local
- local_opts = salt.config.minion_config(
- os.path.join(syspaths.CONFIG_DIR, 'minion'))
- local_opts['file_client'] = 'local'
- patcher = patch('salt.config.minion_config',
- MagicMock(return_value=local_opts))
- patcher.start()
- self.addCleanup(patcher.stop)
- return {saltcheck: {}}
- def test_call_salt_command(self):
- '''test simple test.echo module'''
- with patch.dict(saltcheck.__salt__, {'config.get': MagicMock(return_value=True),
- 'sys.list_modules': MagicMock(return_value=['module1']),
- 'cp.cache_master': MagicMock(return_value=[True])
- }):
- sc_instance = saltcheck.SaltCheck()
- returned = sc_instance.call_salt_command(fun="test.echo", args=['hello'], kwargs=None)
- self.assertEqual(returned, 'hello')
- def test_update_master_cache(self):
- '''test master cache'''
- self.assertTrue(saltcheck.update_master_cache)
- def test_call_salt_command2(self):
- '''test simple test.echo module again'''
- with patch.dict(saltcheck.__salt__, {'config.get': MagicMock(return_value=True),
- 'sys.list_modules': MagicMock(return_value=['module1']),
- 'cp.cache_master': MagicMock(return_value=[True])
- }):
- sc_instance = saltcheck.SaltCheck()
- returned = sc_instance.call_salt_command(fun="test.echo", args=['hello'], kwargs=None)
- self.assertNotEqual(returned, 'not-hello')
- def test__assert_equal1(self):
- '''test'''
- with patch.dict(saltcheck.__salt__, {'config.get': MagicMock(return_value=True),
- 'cp.cache_master': MagicMock(return_value=[True])
- }):
- sc_instance = saltcheck.SaltCheck()
- aaa = {'a': 1, 'b': 2}
- bbb = {'a': 1, 'b': 2}
- mybool = sc_instance._SaltCheck__assert_equal(aaa, bbb)
- self.assertTrue(mybool)
- def test__assert_equal2(self):
- '''test'''
- with patch.dict(saltcheck.__salt__, {'config.get': MagicMock(return_value=True),
- 'cp.cache_master': MagicMock(return_value=[True])
- }):
- sc_instance = saltcheck.SaltCheck()
- mybool = sc_instance._SaltCheck__assert_equal(False, True)
- self.assertNotEqual(mybool, True)
- def test__assert_not_equal1(self):
- '''test'''
- with patch.dict(saltcheck.__salt__, {'config.get': MagicMock(return_value=True),
- 'cp.cache_master': MagicMock(return_value=[True])
- }):
- sc_instance = saltcheck.SaltCheck()
- aaa = {'a': 1, 'b': 2}
- bbb = {'a': 1, 'b': 2, 'c': 3}
- mybool = sc_instance._SaltCheck__assert_not_equal(aaa, bbb)
- self.assertTrue(mybool)
- def test__assert_not_equal2(self):
- '''test'''
- with patch.dict(saltcheck.__salt__, {'config.get': MagicMock(return_value=True),
- 'cp.cache_master': MagicMock(return_value=[True])
- }):
- sc_instance = saltcheck.SaltCheck()
- aaa = {'a': 1, 'b': 2}
- bbb = {'a': 1, 'b': 2}
- mybool = sc_instance._SaltCheck__assert_not_equal(aaa, bbb)
- self.assertNotEqual(mybool, True)
- def test__assert_true1(self):
- '''test'''
- with patch.dict(saltcheck.__salt__, {'config.get': MagicMock(return_value=True),
- 'cp.cache_master': MagicMock(return_value=[True])
- }):
- sc_instance = saltcheck.SaltCheck()
- mybool = sc_instance._SaltCheck__assert_equal(True, True)
- self.assertTrue(mybool)
- def test__assert_true2(self):
- '''test'''
- with patch.dict(saltcheck.__salt__, {'config.get': MagicMock(return_value=True),
- 'cp.cache_master': MagicMock(return_value=[True])
- }):
- sc_instance = saltcheck.SaltCheck()
- mybool = sc_instance._SaltCheck__assert_equal(False, True)
- self.assertNotEqual(mybool, True)
- def test__assert_false1(self):
- '''test'''
- with patch.dict(saltcheck.__salt__, {'config.get': MagicMock(return_value=True),
- 'cp.cache_master': MagicMock(return_value=[True])
- }):
- sc_instance = saltcheck.SaltCheck()
- mybool = sc_instance._SaltCheck__assert_false(False)
- self.assertTrue(mybool)
- def test__assert_false2(self):
- '''test'''
- with patch.dict(saltcheck.__salt__, {'config.get': MagicMock(return_value=True),
- 'cp.cache_master': MagicMock(return_value=[True])
- }):
- sc_instance = saltcheck.SaltCheck()
- mybool = sc_instance._SaltCheck__assert_false(True)
- self.assertNotEqual(mybool, True)
- def test__assert_in1(self):
- '''test'''
- with patch.dict(saltcheck.__salt__, {'config.get': MagicMock(return_value=True),
- 'cp.cache_master': MagicMock(return_value=[True])
- }):
- sc_instance = saltcheck.SaltCheck()
- aaa = "bob"
- mylist = ['alice', 'bob', 'charles', 'dana']
- mybool = sc_instance._SaltCheck__assert_in(aaa, mylist)
- self.assertTrue(mybool, True)
- def test__assert_in2(self):
- '''test'''
- with patch.dict(saltcheck.__salt__, {'config.get': MagicMock(return_value=True),
- 'cp.cache_master': MagicMock(return_value=[True])
- }):
- sc_instance = saltcheck.SaltCheck()
- aaa = "elaine"
- mylist = ['alice', 'bob', 'charles', 'dana']
- mybool = sc_instance._SaltCheck__assert_in(aaa, mylist)
- self.assertNotEqual(mybool, True)
- def test__assert_not_in1(self):
- '''test'''
- with patch.dict(saltcheck.__salt__, {'config.get': MagicMock(return_value=True),
- 'cp.cache_master': MagicMock(return_value=[True])
- }):
- sc_instance = saltcheck.SaltCheck()
- aaa = "elaine"
- mylist = ['alice', 'bob', 'charles', 'dana']
- mybool = sc_instance._SaltCheck__assert_not_in(aaa, mylist)
- self.assertTrue(mybool, True)
- def test__assert_not_in2(self):
- '''test'''
- with patch.dict(saltcheck.__salt__, {'config.get': MagicMock(return_value=True),
- 'cp.cache_master': MagicMock(return_value=[True])
- }):
- sc_instance = saltcheck.SaltCheck()
- aaa = "bob"
- mylist = ['alice', 'bob', 'charles', 'dana']
- mybool = sc_instance._SaltCheck__assert_not_in(aaa, mylist)
- self.assertNotEqual(mybool, True)
- def test__assert_greater1(self):
- '''test'''
- with patch.dict(saltcheck.__salt__, {'config.get': MagicMock(return_value=True),
- 'cp.cache_master': MagicMock(return_value=[True])
- }):
- sc_instance = saltcheck.SaltCheck()
- aaa = 110
- bbb = 100
- mybool = sc_instance._SaltCheck__assert_greater(aaa, bbb)
- self.assertTrue(mybool, True)
- def test__assert_greater2(self):
- '''test'''
- with patch.dict(saltcheck.__salt__, {'config.get': MagicMock(return_value=True),
- 'cp.cache_master': MagicMock(return_value=[True])
- }):
- sc_instance = saltcheck.SaltCheck()
- aaa = 100
- bbb = 110
- mybool = sc_instance._SaltCheck__assert_greater(aaa, bbb)
- self.assertNotEqual(mybool, True)
- def test__assert_greater3(self):
- '''test'''
- with patch.dict(saltcheck.__salt__, {'config.get': MagicMock(return_value=True),
- 'cp.cache_master': MagicMock(return_value=[True])
- }):
- sc_instance = saltcheck.SaltCheck()
- aaa = 100
- bbb = 100
- mybool = sc_instance._SaltCheck__assert_greater(aaa, bbb)
- self.assertNotEqual(mybool, True)
- def test__assert_greater_equal1(self):
- '''test'''
- with patch.dict(saltcheck.__salt__, {'config.get': MagicMock(return_value=True),
- 'cp.cache_master': MagicMock(return_value=[True])
- }):
- sc_instance = saltcheck.SaltCheck()
- aaa = 110
- bbb = 100
- mybool = sc_instance._SaltCheck__assert_greater_equal(aaa, bbb)
- self.assertTrue(mybool, True)
- def test__assert_greater_equal2(self):
- '''test'''
- with patch.dict(saltcheck.__salt__, {'config.get': MagicMock(return_value=True),
- 'cp.cache_master': MagicMock(return_value=[True])
- }):
- sc_instance = saltcheck.SaltCheck()
- aaa = 100
- bbb = 110
- mybool = sc_instance._SaltCheck__assert_greater_equal(aaa, bbb)
- self.assertNotEqual(mybool, True)
- def test__assert_greater_equal3(self):
- '''test'''
- with patch.dict(saltcheck.__salt__, {'config.get': MagicMock(return_value=True),
- 'cp.cache_master': MagicMock(return_value=[True])
- }):
- sc_instance = saltcheck.SaltCheck()
- aaa = 100
- bbb = 100
- mybool = sc_instance._SaltCheck__assert_greater_equal(aaa, bbb)
- self.assertEqual(mybool, 'Pass')
- def test__assert_less1(self):
- '''test'''
- with patch.dict(saltcheck.__salt__, {'config.get': MagicMock(return_value=True),
- 'cp.cache_master': MagicMock(return_value=[True])
- }):
- sc_instance = saltcheck.SaltCheck()
- aaa = 99
- bbb = 100
- mybool = sc_instance._SaltCheck__assert_less(aaa, bbb)
- self.assertTrue(mybool, True)
- def test__assert_less2(self):
- '''test'''
- with patch.dict(saltcheck.__salt__, {'config.get': MagicMock(return_value=True),
- 'cp.cache_master': MagicMock(return_value=[True])
- }):
- sc_instance = saltcheck.SaltCheck()
- aaa = 110
- bbb = 99
- mybool = sc_instance._SaltCheck__assert_less(aaa, bbb)
- self.assertNotEqual(mybool, True)
- def test__assert_less3(self):
- '''test'''
- with patch.dict(saltcheck.__salt__, {'config.get': MagicMock(return_value=True),
- 'cp.cache_master': MagicMock(return_value=[True])
- }):
- sc_instance = saltcheck.SaltCheck()
- aaa = 100
- bbb = 100
- mybool = sc_instance._SaltCheck__assert_less(aaa, bbb)
- self.assertNotEqual(mybool, True)
- def test__assert_less_equal1(self):
- '''test'''
- with patch.dict(saltcheck.__salt__, {'config.get': MagicMock(return_value=True),
- 'cp.cache_master': MagicMock(return_value=[True])
- }):
- sc_instance = saltcheck.SaltCheck()
- aaa = 99
- bbb = 100
- mybool = sc_instance._SaltCheck__assert_less_equal(aaa, bbb)
- self.assertTrue(mybool, True)
- def test__assert_less_equal2(self):
- '''test'''
- with patch.dict(saltcheck.__salt__, {'config.get': MagicMock(return_value=True),
- 'cp.cache_master': MagicMock(return_value=[True])
- }):
- sc_instance = saltcheck.SaltCheck()
- aaa = 110
- bbb = 99
- mybool = sc_instance._SaltCheck__assert_less_equal(aaa, bbb)
- self.assertNotEqual(mybool, True)
- def test__assert_less_equal3(self):
- '''test'''
- with patch.dict(saltcheck.__salt__, {'config.get': MagicMock(return_value=True),
- 'cp.cache_master': MagicMock(return_value=[True])
- }):
- sc_instance = saltcheck.SaltCheck()
- aaa = 100
- bbb = 100
- mybool = sc_instance._SaltCheck__assert_less_equal(aaa, bbb)
- self.assertEqual(mybool, 'Pass')
- def test_run_test_1(self):
- '''test'''
- with patch.dict(saltcheck.__salt__, {'config.get': MagicMock(return_value=True),
- 'sys.list_modules': MagicMock(return_value=['test']),
- 'sys.list_functions': MagicMock(return_value=['test.echo']),
- 'cp.cache_master': MagicMock(return_value=[True])}):
- returned = saltcheck.run_test(test={"module_and_function": "test.echo",
- "assertion": "assertEqual",
- "expected-return": "This works!",
- "args": ["This works!"]
- })
- self.assertEqual(returned, 'Pass')
|