From 7115611249e636d9de081da55446d162538571e4 Mon Sep 17 00:00:00 2001 From: Simon Vrouwe Date: Wed, 15 Jun 2022 10:26:21 +0300 Subject: [PATCH] pytest: test plugin does not register same option "name" --- tests/plugins/options.py | 2 ++ tests/test_plugin.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/tests/plugins/options.py b/tests/plugins/options.py index d1376a6f8..14c00dd97 100755 --- a/tests/plugins/options.py +++ b/tests/plugins/options.py @@ -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('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() diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 649544b1f..2e8a417b8 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -30,8 +30,10 @@ def test_option_passthrough(node_factory, directory): """ Ensure that registering options works. 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_path2 = os.path.join(os.getcwd(), 'tests/plugins/options.py') help_out = subprocess.check_output([ '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.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): """Ensure that desired types of options are