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.
This commit is contained in:
Christian Kellner 2020-09-13 18:50:36 +02:00
parent c39f1d6d59
commit d8107f2347

86
test/unit/test_builder.py Normal file
View file

@ -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"))