Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_env_extension(self):
plugins = list_plugins()
env_plugin = plugins['env']
self.assertEqual(env_plugin.get_name(), 'env')
p = env_plugin()
self.assertTrue(plugin_load_parser_correctly(env_plugin))
mock_cliargs = {'env': [['ENVVARNAME=envvar_value', 'ENV2=val2'], ['ENV3=val3']]}
self.assertEqual(p.get_snippet(mock_cliargs), '')
self.assertEqual(p.get_preamble(mock_cliargs), '')
self.assertEqual(p.get_docker_args(mock_cliargs), ' -e ENVVARNAME=envvar_value -e ENV2=val2 -e ENV3=val3')
def test_user_extension(self):
plugins = list_plugins()
user_plugin = plugins['user']
self.assertEqual(user_plugin.get_name(), 'user')
p = user_plugin()
self.assertTrue(plugin_load_parser_correctly(user_plugin))
env_subs = p.get_environment_subs()
self.assertEqual(env_subs['gid'], os.getgid())
self.assertEqual(env_subs['uid'], os.getuid())
self.assertEqual(env_subs['name'], getpass.getuser())
self.assertEqual(env_subs['dir'], str(Path.home()))
self.assertEqual(env_subs['gecos'], pwd.getpwuid(os.getuid()).pw_gecos)
self.assertEqual(env_subs['shell'], pwd.getpwuid(os.getuid()).pw_shell)
mock_cliargs = {}
snippet = p.get_snippet(mock_cliargs).splitlines()
def test_return_code_multiple_extensions(self):
plugins = list_plugins()
desired_plugins = ['home', 'user']
active_extensions = [e() for e in plugins.values() if e.get_name() in desired_plugins]
dig = DockerImageGenerator(active_extensions, {}, 'ubuntu:bionic')
self.assertEqual(dig.build(), 0)
self.assertEqual(dig.run('true'), 0)
self.assertEqual(dig.run('false'), 1)
def test_list_plugins(self):
plugins_found = list_plugins()
plugin_names = plugins_found.keys()
self.assertTrue('nvidia' in plugin_names )
self.assertTrue('pulse' in plugin_names )
self.assertTrue('user' in plugin_names )
self.assertTrue('home' in plugin_names )
def test_pulse_extension(self):
plugins = list_plugins()
pulse_plugin = plugins['pulse']
self.assertEqual(pulse_plugin.get_name(), 'pulse')
p = pulse_plugin()
self.assertTrue(plugin_load_parser_correctly(pulse_plugin))
mock_cliargs = {}
snippet = p.get_snippet(mock_cliargs)
#first line
self.assertIn('RUN mkdir -p /etc/pulse', snippet)
self.assertIn('default-server = unix:/run/user/', snippet) #skipping user id that's system dependent
self.assertIn('autospawn = no', snippet)
self.assertIn('daemon-binary = /bin/true', snippet)
#last line
self.assertIn('> /etc/pulse/client.conf', snippet)
self.assertEqual(p.get_preamble(mock_cliargs), '')
def test_home_extension(self):
plugins = list_plugins()
home_plugin = plugins['home']
self.assertEqual(home_plugin.get_name(), 'home')
p = home_plugin()
self.assertTrue(plugin_load_parser_correctly(home_plugin))
mock_cliargs = {}
self.assertEqual(p.get_snippet(mock_cliargs), '')
self.assertEqual(p.get_preamble(mock_cliargs), '')
args = p.get_docker_args(mock_cliargs)
self.assertTrue('-v %s:%s' % (Path.home(), Path.home()) in args)