Browse Source

plugins: test for option value checking and parsing

travis-debug
lisa neigut 5 years ago
committed by Rusty Russell
parent
commit
b25a8ba29d
  1. 20
      tests/plugins/options.py
  2. 50
      tests/test_plugin.py

20
tests/plugins/options.py

@ -0,0 +1,20 @@
#!/usr/bin/env python3
"""This plugin is used to check that plugin options are parsed properly.
The plugin offers 3 options, one of each supported type.
"""
from lightning import Plugin
plugin = Plugin()
@plugin.init()
def init(configuration, options, plugin):
for name, val in options.items():
plugin.log("option {} {} {}".format(name, val, type(val)))
plugin.add_option('str_opt', 'i am a string', 'an example string option')
plugin.add_option('int_opt', 7, 'an example int type option', opt_type='int')
plugin.add_option('bool_opt', True, 'an example bool type option', opt_type='bool')
plugin.run()

50
tests/test_plugin.py

@ -46,6 +46,56 @@ def test_option_passthrough(node_factory, directory):
n.stop() n.stop()
def test_option_types(node_factory):
"""Ensure that desired types of options are
respected in output """
plugin_path = os.path.join(os.getcwd(), 'tests/plugins/options.py')
n = node_factory.get_node(options={
'plugin': plugin_path,
'str_opt': 'ok',
'int_opt': 22,
'bool_opt': 1,
})
n.daemon.is_in_log(r"option str_opt ok <class 'str'>")
n.daemon.is_in_log(r"option int_opt 22 <class 'int'>")
n.daemon.is_in_log(r"option bool_opt True <class 'bool'>")
n.stop()
# A blank bool_opt should default to false
n = node_factory.get_node(options={
'plugin': plugin_path, 'str_opt': 'ok',
'int_opt': 22,
'bool_opt': '',
})
n.daemon.is_in_log(r"option bool_opt False <class 'bool'>")
n.stop()
# What happens if we give it a bad bool-option?
n = node_factory.get_node(options={
'plugin': plugin_path,
'str_opt': 'ok',
'int_opt': 22,
'bool_opt': '!',
}, expect_fail=True, may_fail=True)
# the node should fail to start, and we get a stderr msg
assert n.daemon.is_in_stderr('bool_opt: ! does not parse as type bool')
# What happens if we give it a bad int-option?
n = node_factory.get_node(options={
'plugin': plugin_path,
'str_opt': 'ok',
'int_opt': 'notok',
'bool_opt': 1,
}, may_fail=True, expect_fail=True)
# the node should fail to start, and we get a stderr msg
assert n.daemon.is_in_stderr('--int_opt: notok does not parse as type int')
def test_millisatoshi_passthrough(node_factory): def test_millisatoshi_passthrough(node_factory):
""" Ensure that Millisatoshi arguments and return work. """ Ensure that Millisatoshi arguments and return work.
""" """

Loading…
Cancel
Save