test/builder: add handler factory helper

Add a new helper method that can be used to create an instance of
OSBuildImage. Optionally, the session and options can be passed
in as well as a custom config data, otherwise the default session
and object are used. If custom configuration data was specified,
a temporary configuration file with the config data is created
and set plugin-wide so it is picked up by the object constructor.
This commit is contained in:
Christian Kellner 2020-09-28 14:05:51 +02:00 committed by Tom Gundersen
parent 7ecf7447e4
commit d9c0f9e316

View file

@ -254,6 +254,31 @@ class TestBuilderPlugin(PluginTest):
)
return options
def make_handler(self, *, config=None, session=None, options=None):
if not session:
session = self.mock_session()
if not options:
options = self.mock_options()
def creator():
return self.plugin.OSBuildImage(1,
"osbuildImage",
"params",
session,
options)
if not config:
return creator()
with tempfile.TemporaryDirectory() as tmp:
cfgfile = os.path.abspath(os.path.join(tmp, "ko.cfg"))
with open(cfgfile, 'w') as f:
config.write(f)
self.plugin.DEFAULT_CONFIG_FILES = [cfgfile]
return creator()
def test_plugin_config(self):
session = flexmock()
options = self.mock_options()