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:
parent
c39f1d6d59
commit
d8107f2347
1 changed files with 86 additions and 0 deletions
86
test/unit/test_builder.py
Normal file
86
test/unit/test_builder.py
Normal 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"))
|
||||
Loading…
Add table
Add a link
Reference in a new issue