Skip to content

Commit

Permalink
Adding test for osfullname under FreeBSD.
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgreenaway committed Jan 5, 2020
1 parent 27473ff commit f083822
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions tests/unit/grains/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1430,3 +1430,58 @@ def test_osdata_virtual_key_win(self):

self.assertIn('virtual', osdata_grains)
self.assertNotEqual(osdata_grains['virtual'], 'physical')

@skipIf(salt.utils.platform.is_windows(), 'System is Windows')
def test_bsd_osfullname(self):
'''
Test to ensure osfullname exists on *BSD systems
'''
_path_exists_map = {}
_path_isfile_map = {}
_cmd_run_map = {
'freebsd-version -u': '10.3-RELEASE',
'/sbin/sysctl -n hw.physmem': '2121781248',
'/sbin/sysctl -n vm.swap_total': '419430400'
}

path_exists_mock = MagicMock(side_effect=lambda x: _path_exists_map[x])
path_isfile_mock = MagicMock(
side_effect=lambda x: _path_isfile_map.get(x, False)
)
cmd_run_mock = MagicMock(
side_effect=lambda x: _cmd_run_map[x]
)
empty_mock = MagicMock(return_value={})

mock_freebsd_uname = ('FreeBSD',
'freebsd10.3-hostname-8148',
'10.3-RELEASE',
'FreeBSD 10.3-RELEASE #0 r297264: Fri Mar 25 02:10:02 UTC 2016 root@releng1.nyi.freebsd.org:/usr/obj/usr/src/sys/GENERIC',
'amd64',
'amd64')

with patch('platform.uname',
MagicMock(return_value=mock_freebsd_uname)):
with patch.object(salt.utils.platform, 'is_linux',
MagicMock(return_value=False)):
with patch.object(salt.utils.platform, 'is_freebsd',
MagicMock(return_value=True)):
# Skip the first if statement
with patch.object(salt.utils.platform, 'is_proxy',
MagicMock(return_value=False)):
# Skip the init grain compilation (not pertinent)
with patch.object(os.path, 'exists', path_exists_mock):
with patch('salt.utils.path.which') as mock:
mock.return_value = '/sbin/sysctl'
# Make a bunch of functions return empty dicts,
# we don't care about these grains for the
# purposes of this test.
with patch.object(core, '_bsd_cpudata', empty_mock), \
patch.object(core, '_hw_data', empty_mock), \
patch.object(core, '_virtual', empty_mock), \
patch.object(core, '_ps', empty_mock), \
patch.dict(core.__salt__, {'cmd.run': cmd_run_mock}):
os_grains = core.os_data()

self.assertIn('osfullname', os_grains)
self.assertEqual(os_grains.get('osfullname'), 'FreeBSD')

0 comments on commit f083822

Please sign in to comment.