diff mbox series

[unstable,linux-signed,v2,9/9] UBUNTU: [Packaging] introduce test_generate_control.py

Message ID 20241030132153.482139-10-agathe.porte@canonical.com
State New
Headers show
Series Refactor and test generate-control | expand

Commit Message

Agathe Porte Oct. 30, 2024, 1:19 p.m. UTC
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%)
diff mbox series

Patch

diff --git a/debian/scripts/generate_control.py b/debian/scripts/generate_control.py
index 8e64ff3..816f0b0 100755
--- a/debian/scripts/generate_control.py
+++ b/debian/scripts/generate_control.py
@@ -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)
diff --git a/debian/scripts/test-generate-control.sh b/debian/scripts/test-generate-control.sh
deleted file mode 100755
index ce042f3..0000000
--- a/debian/scripts/test-generate-control.sh
+++ /dev/null
@@ -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"
diff --git a/debian/scripts/generate_control.py.ref b/debian/scripts/test_generate_control.py
similarity index 61%
rename from debian/scripts/generate_control.py.ref
rename to debian/scripts/test_generate_control.py
index b5f016b..b1bc409 100644
--- a/debian/scripts/generate_control.py.ref
+++ b/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