From d8107f23478ca12cd376098a79c7465cc5dd12d1 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Sun, 13 Sep 2020 18:50:36 +0200 Subject: [PATCH] test/builder: add unit test skeleton Add the skeleton to run builder plugin unit tests and check that exceptions are throw for unknown build target and unsupported architectures. --- test/unit/test_builder.py | 86 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 test/unit/test_builder.py diff --git a/test/unit/test_builder.py b/test/unit/test_builder.py new file mode 100644 index 0000000..c5c3c24 --- /dev/null +++ b/test/unit/test_builder.py @@ -0,0 +1,86 @@ +# +# koji hub plugin unit tests +# + + +import unittest +import os +import imp +from flexmock import flexmock + +import koji + + +class TestHubPlugin(unittest.TestCase): + def setUp(self): + """Loads the plugin to self.plugin""" + root = os.getenv("GITHUB_WORKSPACE", os.getcwd()) + + haystack = os.path.join(root, "plugins", "builder") + + fp, path, desc = imp.find_module("osbuild", [haystack]) + try: + self.plugin = imp.load_module("osbuild", fp, path, desc) + finally: + fp.close() + + def test_unknown_build_target(self): + session = flexmock() + + session.should_receive("getBuildTarget") \ + .with_args("target", strict=True) \ + .and_return(None) + + options = flexmock(allowed_scms='pkg.osbuild.org:/*:no', + workdir="/tmp") + handler = self.plugin.OSBuildImage(1, + "osbuildImage", + "params", + session, + options) + + args = ["name", "version", "distro", + ["image_type"], + "target", + ["arches"], + {}] + + with self.assertRaises(koji.BuildError): + handler.handler(*args) + + def test_unsupported_architecture(self): + session = flexmock() + + build_target = { + "build_tag": "fedora-build", + "name": "fedora-candidate", + "dest_tag_name": "fedora-updates" + } + + session.should_receive("getBuildTarget") \ + .with_args("fedora-candidate", strict=True) \ + .and_return(build_target) \ + .once() + + session.should_receive('getBuildConfig') \ + .with_args(build_target["build_tag"]) \ + .and_return({"arches": "x86_64"}) + + options = flexmock(allowed_scms='pkg.osbuild.org:/*:no', + workdir="/tmp") + + handler = self.plugin.OSBuildImage(1, + "osbuildImage", + "params", + session, + options) + + args = ["name", "version", "distro", + ["image_type"], + "fedora-candidate", + ["s390x"], + {}] + + with self.assertRaises(koji.BuildError) as err: + handler.handler(*args) + self.assertTrue(str(err).startswith("Unsupported"))