From c0730ff968a86c7f045786992f26f53af3902ef9 Mon Sep 17 00:00:00 2001 From: Ch3LL Date: Fri, 3 Aug 2018 14:57:15 -0400 Subject: [PATCH] fix test_runas integration test for macosx --- tests/integration/modules/test_cmdmod.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/integration/modules/test_cmdmod.py b/tests/integration/modules/test_cmdmod.py index 45cb9b6ba7..98e09cbc8f 100644 --- a/tests/integration/modules/test_cmdmod.py +++ b/tests/integration/modules/test_cmdmod.py @@ -38,6 +38,21 @@ class CMDModuleTest(ModuleCase): ''' Validate the cmd module ''' + def setUp(self): + if self._testMethodName == 'test_runas': + # only need to manage this user for the test_runas test + self.runas_usr = 'nobody' + if salt.utils.platform.is_darwin(): + self.runas_usr = 'macsalttest' + if self.runas_usr not in self.run_function('user.info', [self.runas_usr]).values(): + self.run_function('user.add', [self.runas_usr]) + + def tearDown(self): + if self._testMethodName == 'test_runas': + if salt.utils.platform.is_darwin(): + if self.runas_usr in self.run_function('user.info', [self.runas_usr]).values(): + self.run_function('user.delete', [self.runas_usr], remove=True) + def test_run(self): ''' cmd.run @@ -266,12 +281,13 @@ class CMDModuleTest(ModuleCase): @skipIf(salt.utils.platform.is_windows(), 'minion is windows') @skip_if_not_root + @destructiveTest def test_runas(self): ''' Ensure that the env is the runas user's ''' - out = self.run_function('cmd.run', ['env'], runas='nobody').splitlines() - self.assertIn('USER=nobody', out) + out = self.run_function('cmd.run', ['env'], runas=self.runas_usr).splitlines() + self.assertIn('USER={0}'.format(self.runas_usr), out) def test_timeout(self): '''