def test_state_powershell(self): s_man = StateManager() command, suffix, env = s_man.set_state_handlers( 'ps', os.getuid(), os.getgid(), '/tmp', 'print 1', {'ENV_PARAM': 'VALUE'}) self.assertContains(command, '$env:ENV_PARAM="VALUE"') self.assertEqual(suffix, '.ps1')
def test_state_ruby(self): s_man = StateManager() command, suffix, env = s_man.set_state_handlers( 'ruby', os.getuid(), os.getgid(), '/tmp', '#!/usr/bin/ruby\nprint 1', {'ENV_PARAM': 'VALUE'}) self.assertContains(command, 'ENV["ENV_PARAM"]="VALUE"') self.assertEqual(suffix, '.rb')
def test_state_python(self): s_man = StateManager() command, suffix, env = s_man.set_state_handlers( 'python', os.getuid(), os.getgid(), '/tmp', '#!/usr/bin/python\nprint 1', {'ENV_PARAM': 'VALUE'}) self.assertContains(command, '"ENV_PARAM": "VALUE"') self.assertEqual(suffix, '.py')
def test_state_powershell(self): s_man = StateManager() command, suffix, env = s_man.set_state_handlers('ps', os.getuid(), os.getgid(), '/tmp', 'print 1', {'ENV_PARAM': 'VALUE'}) self.assertContains(command, '$env:ENV_PARAM="VALUE"') self.assertEqual(suffix, '.ps1')
def test_state_ruby(self): s_man = StateManager() command, suffix, env = s_man.set_state_handlers('ruby', os.getuid(), os.getgid(), '/tmp', '#!/usr/bin/ruby\nprint 1', {'ENV_PARAM': 'VALUE'}) self.assertContains(command, 'ENV["ENV_PARAM"]="VALUE"') self.assertEqual(suffix, '.rb')
def test_state_python(self): s_man = StateManager() command, suffix, env = s_man.set_state_handlers('python', os.getuid(), os.getgid(), '/tmp', '#!/usr/bin/python\nprint 1', {'ENV_PARAM': 'VALUE'}) self.assertContains(command, '"ENV_PARAM": "VALUE"') self.assertEqual(suffix, '.py')
def test_state_bash(self): s_man = StateManager() command, suffix, env = s_man.set_state_handlers( 'bash', os.getuid(), os.getgid(), '/tmp', '#!/bin/bash\necho 1', { 'ENV_PARAM': 'VALUE', 'INV-PARAM': 'some value', 'LIST_VAL': ["1", "2"] }) self.assertContains(command, 'ENV_PARAM="VALUE"') self.assertContains(command, 'LIST_VAL[0]="1"') self.assertContains(command, 'LIST_VAL[1]="2"') self.assertContainsNot(command, 'INV-PARAM=') self.assertEqual(suffix, '.sh')
def test_state_bash(self): s_man = StateManager() command, suffix, env = s_man.set_state_handlers('bash', os.getuid(), os.getgid(), '/tmp', '#!/bin/bash\necho 1', {'ENV_PARAM': 'VALUE', 'INV-PARAM': 'some value', 'LIST_VAL': ["1", "2"] }) self.assertContains(command, 'ENV_PARAM="VALUE"') self.assertContains(command, 'LIST_VAL[0]="1"') self.assertContains(command, 'LIST_VAL[1]="2"') self.assertContainsNot(command, 'INV-PARAM=') self.assertEqual(suffix, '.sh')
def __init__(self, as_user, work_dir=cloudrunner.TMP_DIR): self.state_manager = StateManager() self.as_user = as_user self.session_cwd = os.path.join(work_dir, uuid.uuid4().hex) os.makedirs(self.session_cwd) self.executor = Executor(as_user)