pytest: test plugin does not register same option "name"

This commit is contained in:
Simon Vrouwe
2022-06-15 10:26:21 +03:00
committed by neil saitug
parent 2fddfe3ffc
commit 7115611249
2 changed files with 16 additions and 0 deletions

View File

@@ -22,4 +22,6 @@ plugin.add_flag_option('flag_opt', 'an example flag type option')
plugin.add_option('str_optm', None, 'an example string option', multi=True) plugin.add_option('str_optm', None, 'an example string option', multi=True)
plugin.add_option('int_optm', 7, 'an example int type option', opt_type='int', multi=True) plugin.add_option('int_optm', 7, 'an example int type option', opt_type='int', multi=True)
plugin.add_option('greeting', 7, 'option _names_ should be unique', opt_type='int', multi=True)
plugin.run() plugin.run()

View File

@@ -30,8 +30,10 @@ def test_option_passthrough(node_factory, directory):
""" Ensure that registering options works. """ Ensure that registering options works.
First attempts without the plugin and then with the plugin. First attempts without the plugin and then with the plugin.
Then a plugin tries to register the same option "name" again, fails startup.
""" """
plugin_path = os.path.join(os.getcwd(), 'contrib/plugins/helloworld.py') plugin_path = os.path.join(os.getcwd(), 'contrib/plugins/helloworld.py')
plugin_path2 = os.path.join(os.getcwd(), 'tests/plugins/options.py')
help_out = subprocess.check_output([ help_out = subprocess.check_output([
'lightningd/lightningd', 'lightningd/lightningd',
@@ -53,6 +55,18 @@ def test_option_passthrough(node_factory, directory):
n = node_factory.get_node(options={'plugin': plugin_path, 'greeting': 'Ciao'}) n = node_factory.get_node(options={'plugin': plugin_path, 'greeting': 'Ciao'})
n.stop() n.stop()
with pytest.raises(subprocess.CalledProcessError):
err_out = subprocess.run([
'lightningd/lightningd',
'--lightning-dir={}'.format(directory),
'--plugin={}'.format(plugin_path),
'--plugin={}'.format(plugin_path2),
'--help'
], capture_output=True, check=True).stderr.decode('utf-8')
# first come first serve
assert("error starting plugin '{}': option name '--greeting' is already taken".format(plugin_path2) in err_out)
def test_option_types(node_factory): def test_option_types(node_factory):
"""Ensure that desired types of options are """Ensure that desired types of options are