Skip to content

Commit

Permalink
register Hostname plugin and add basic tests (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
tfoote authored May 5, 2023
1 parent 4716db7 commit 9304066
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
'git = rocker.git_extension:Git',
'group_add = rocker.extensions:GroupAdd',
'home = rocker.extensions:HomeDir',
'hostname = rocker.extensions:Hostname',
'name = rocker.extensions:Name',
'network = rocker.extensions:Network',
'nvidia = rocker.nvidia_extension:Nvidia',
Expand Down
31 changes: 31 additions & 0 deletions test/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,37 @@ def test_name_extension(self):
args = p.get_docker_args(mock_cliargs)
self.assertTrue('--name docker_name' in args)

class HostnameExtensionTest(unittest.TestCase):

def setUp(self):
# Work around interference between empy Interpreter
# stdout proxy and test runner. empy installs a proxy on stdout
# to be able to capture the information.
# And the test runner creates a new stdout object for each test.
# This breaks empy as it assumes that the proxy has persistent
# between instances of the Interpreter class
# empy will error with the exception
# "em.Error: interpreter stdout proxy lost"
em.Interpreter._wasProxyInstalled = False

def test_name_extension(self):
plugins = list_plugins()
name_plugin = plugins['hostname']
self.assertEqual(name_plugin.get_name(), 'hostname')

p = name_plugin()
self.assertTrue(plugin_load_parser_correctly(name_plugin))

mock_cliargs = {'hostname': 'none'}
self.assertEqual(p.get_snippet(mock_cliargs), '')
self.assertEqual(p.get_preamble(mock_cliargs), '')
args = p.get_docker_args(mock_cliargs)
self.assertTrue('--hostname none' in args)

mock_cliargs = {'hostname': 'docker-hostname'}
args = p.get_docker_args(mock_cliargs)
self.assertTrue('--hostname docker-hostname' in args)


class PrivilegedExtensionTest(unittest.TestCase):

Expand Down

0 comments on commit 9304066

Please sign in to comment.