pkg tests fix for macos

This commit is contained in:
Tyler Johnson 2019-10-09 16:17:56 -06:00
parent 61c77a3802
commit 761ef7b848
No known key found for this signature in database
GPG Key ID: 691E31397E27D004

View File

@ -3,6 +3,7 @@
# Import Python libs # Import Python libs
from __future__ import absolute_import, print_function, unicode_literals from __future__ import absolute_import, print_function, unicode_literals
import os import os
import pwd
import pprint import pprint
# Import Salt Testing libs # Import Salt Testing libs
@ -16,6 +17,7 @@ from tests.support.helpers import (
# Import Salt libs # Import Salt libs
from salt.utils import six from salt.utils import six
import salt.utils.path
import salt.utils.pkg import salt.utils.pkg
import salt.utils.platform import salt.utils.platform
@ -224,8 +226,6 @@ class PkgModuleTest(ModuleCase, SaltReturnAssertsMixin):
if not isinstance(ret, dict): if not isinstance(ret, dict):
self.skipTest('Upstream repo did not return coherent results. Skipping test.') self.skipTest('Upstream repo did not return coherent results. Skipping test.')
self.assertNotEqual(ret, {}) self.assertNotEqual(ret, {})
elif grains['os_family'] == 'Suse':
self.assertNotEqual(ret, {})
for source, state in ret.items(): for source, state in ret.items():
self.assertIn(state, (True, False, None)) self.assertIn(state, (True, False, None))
@ -254,6 +254,11 @@ class PkgModuleTest(ModuleCase, SaltReturnAssertsMixin):
keys = ret.keys() keys = ret.keys()
self.assertIn('less', keys) self.assertIn('less', keys)
self.assertIn('zypper', keys) self.assertIn('zypper', keys)
else:
ret = self.run_function(func, [self.pkg, 'python'])
keys = ret.keys()
self.assertIn('pip', keys)
self.assertIn('python', keys)
@destructiveTest @destructiveTest
@requires_network() @requires_network()
@ -346,8 +351,9 @@ class PkgModuleTest(ModuleCase, SaltReturnAssertsMixin):
elif grains['os_family'] == 'Suse': elif grains['os_family'] == 'Suse':
cmd_pkg = self.run_function('cmd.run', ['zypper info {0}'.format(self.pkg)]) cmd_pkg = self.run_function('cmd.run', ['zypper info {0}'.format(self.pkg)])
elif grains['os_family'] == 'MacOS': elif grains['os_family'] == 'MacOS':
self.skipTest('TODO the following command needs to be run as a non-root user') brew_bin = salt.utils.path.which('brew')
#cmd_pkg = self.run_function('cmd.run', ['brew info {0}'.format(self.pkg)]) mac_user = pwd.getpwuid(os.stat(brew_bin).st_uid).pw_name
cmd_pkg = self.run_function('cmd.run', ['brew info {0}'.format(self.pkg)], run_as=mac_user)
else: else:
self.skipTest('TODO: test not configured for {}'.format(grains['os_family'])) self.skipTest('TODO: test not configured for {}'.format(grains['os_family']))
pkg_latest = self.run_function('pkg.latest_version', [self.pkg]) pkg_latest = self.run_function('pkg.latest_version', [self.pkg])