@@ -191,8 +191,7 @@ def gen_dbgsym_binpkgs(signing: Signing, args: Namespace):
)
-def main(args: Namespace):
- signing = Signing.load("debian/package.config")
+def main(signing: Signing, args: Namespace):
replace_placeholders(signing, args)
gen_binpkgs(signing, args)
@@ -219,5 +218,6 @@ if __name__ == "__main__":
parser.add_argument("abi_version")
args = parser.parse_args()
+ signing = Signing.load("debian/package.config")
- main(args)
+ main(signing, args)
deleted file mode 100755
@@ -1,17 +0,0 @@
-#!/bin/dash
-
-set -eux
-
-REFERENCE_FILE=debian/scripts/generate_control.py.ref
-
-debian/scripts/generate_control.py \
- oracular \
- linux-signed \
- linux-generate \
- 6.11.0-8.8 \
- linux \
- 6.11.0-8.8 6.11.0-8 \
- < debian/control.stub | diff -u "$REFERENCE_FILE" -
-
-# Use this line instead to refresh the reference values
-# < debian/control.stub > "$REFERENCE_FILE"
similarity index 61%
rename from debian/scripts/generate_control.py.ref
rename to debian/scripts/test_generate_control.py
@@ -1,4 +1,60 @@
-Source: linux-signed
+import sys
+from argparse import Namespace
+
+import generate_control
+from config import Signing
+
+
+class SigningMock:
+ def __init__(self):
+ self.flavour_archs = {}
+ self.arch_flavour_data = {}
+
+ def package_flavour_archs(self, key):
+ return self.flavour_archs.get(key, [])
+
+
+def test_gen_depends_uci_none(capfd):
+ signing = SigningMock()
+ generate_control.gen_depends_uci(signing)
+
+ out, err = capfd.readouterr()
+ assert out == ""
+
+
+def test_gen_depends_uci_cvm(capfd):
+ signing = SigningMock()
+ signing.flavour_archs["cvm"] = (("", ["amd64"]), ("", ["arm64"]))
+ generate_control.gen_depends_uci(signing)
+
+ out, err = capfd.readouterr()
+ assert out == " ubuntu-core-initramfs [amd64 arm64] <pkg.linux-generate>,\n"
+
+
+def test_gen_depends_uci_cvm_uc(capfd):
+ signing = SigningMock()
+ signing.flavour_archs["cvm"] = (("", ["amd64"]),)
+ signing.flavour_archs["uc"] = (("", ["arm64"]),)
+ generate_control.gen_depends_uci(signing)
+
+ out, err = capfd.readouterr()
+ assert out == " ubuntu-core-initramfs [amd64 arm64] <pkg.linux-generate>,\n"
+
+
+def test_main(capfd):
+ args = Namespace()
+ args.series = "oracular"
+ args.source_name = "linux-signed"
+ args.generate_name = "linux-generate"
+ args.source_version = "6.11.0-8.8"
+ args.unsigned_name = "linux"
+ args.unsigned_version = "6.11.0-8.8"
+ args.abi_version = "6.11.0-8"
+
+ sys.stdin = open("debian/control.stub")
+ generate_control.main(Signing.load("debian/package.config"), args)
+
+ expected_output = """Source: linux-signed
Section: kernel
Priority: optional
Maintainer: Canonical Kernel Team <kernel-team@lists.ubuntu.com>
@@ -72,3 +128,7 @@ Architecture: arm64
Depends: linux-image-unsigned-6.11.0-8-generic-64k-dbgsym
Description: Signed kernel image generic-64k
A link to the debugging symbols for the generic-64k signed kernel.
+"""
+
+ out, err = capfd.readouterr()
+ assert out == expected_output
Use pytest to test the full output of the tool, as well as the output of some options. The tests now can be run with: $ python3 -m pytest The bash test script can be dropped, all of the output is now verified in this test file as well. Signed-off-by: Agathe Porte <agathe.porte@canonical.com> --- debian/scripts/generate_control.py | 6 +- debian/scripts/test-generate-control.sh | 17 ----- ...ontrol.py.ref => test_generate_control.py} | 62 ++++++++++++++++++- 3 files changed, 64 insertions(+), 21 deletions(-) delete mode 100755 debian/scripts/test-generate-control.sh rename debian/scripts/{generate_control.py.ref => test_generate_control.py} (61%)