Hi,
On Thu, 09 Mar 2017 19:56:47 +0100 Benjamin Drung
<benjamin.dr...@profitbricks.com> wrote:
> While developing the patch for #570623, I added shunit2-based tests.
> shunit2 is available as Debian package and can be easily integrated
> in the package build. Patches for some smoke tests are attached (in
> case you consider using shunit2).
attached the current version of the basic shunit2 tests.
--
Benjamin Drung
System Developer
Debian & Ubuntu Developer
ProfitBricks GmbH
Greifswalder Str. 207
D - 10405 Berlin
Email: benjamin.dr...@profitbricks.com
URL: http://www.profitbricks.com
Sitz der Gesellschaft: Berlin.
Registergericht: Amtsgericht Charlottenburg, HRB 125506B.
Geschäftsführer: Andreas Gauger, Achim Weiss.
From 6123d145779b461865e5ef9b470ee3e8080c1c05 Mon Sep 17 00:00:00 2001
From: Benjamin Drung <benjamin.dr...@profitbricks.com>
Date: Mon, 6 Feb 2017 17:47:38 +0100
Subject: [PATCH 01/58] [testsuite] Use dpkg-source format 1.0
To silence dpkg-source, use source format 1.0
---
tests/genpackage.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/genpackage.sh b/tests/genpackage.sh
index ac8ffec..ee21890 100755
--- a/tests/genpackage.sh
+++ b/tests/genpackage.sh
@@ -39,7 +39,7 @@ $PACKAGE ($EPOCH$VERSION$REVISION) $DISTRI; urgency=critical
-- me <guess@who> Mon, 01 Jan 1980 01:02:02 +0000
END
-dpkg-source -b "$DIR"
+dpkg-source --format=1.0 -b "$DIR"
mkdir -p "$DIR"/debian/tmp/DEBIAN
touch "$DIR"/debian/tmp/x
mkdir "$DIR"/debian/tmp/a
--
2.9.3
From aa30c40b40a1c05d87c6802f2d3c7055d2e2f4f6 Mon Sep 17 00:00:00 2001
From: Benjamin Drung <benjamin.dr...@profitbricks.com>
Date: Mon, 6 Feb 2017 17:49:07 +0100
Subject: [PATCH 02/58] [testsuite] Use the host architecture by default
To be able to build packages for the tests, use the host architecture
(to avoid requiring a cross-compiler).
---
tests/genpackage.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/genpackage.sh b/tests/genpackage.sh
index ee21890..ff18103 100755
--- a/tests/genpackage.sh
+++ b/tests/genpackage.sh
@@ -19,7 +19,7 @@ Maintainer: me <guess@who>
Standards-Version: 0.0
Package: $PACKAGE
-Architecture: abacus
+Architecture: ${ARCH:-$(dpkg-architecture -qDEB_HOST_ARCH)}
Description: bla
blub
--
2.9.3
From b7c896010057f3107e947efcf038c8caa98fdb9b Mon Sep 17 00:00:00 2001
From: Benjamin Drung <benjamin.dr...@profitbricks.com>
Date: Tue, 28 Mar 2017 15:10:10 +0200
Subject: [PATCH 03/58] [testsuite] Use existing priority
Using the non-existing priority 'superfluous' causes warning messages.
---
tests/genpackage.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/genpackage.sh b/tests/genpackage.sh
index ff18103..b237e86 100755
--- a/tests/genpackage.sh
+++ b/tests/genpackage.sh
@@ -14,7 +14,7 @@ mkdir "$DIR"/debian
cat >"$DIR"/debian/control <<END
Source: $PACKAGE
Section: $SECTION
-Priority: superfluous
+Priority: optional
Maintainer: me <guess@who>
Standards-Version: 0.0
--
2.9.3
From fa0ecef0449c80489b86454e2d9a304ba9e76789 Mon Sep 17 00:00:00 2001
From: Benjamin Drung <benjamin.dr...@profitbricks.com>
Date: Tue, 28 Mar 2017 15:15:22 +0200
Subject: [PATCH 04/58] [testsuite] genpackage.sh: Silence output
---
tests/genpackage.sh | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/genpackage.sh b/tests/genpackage.sh
index b237e86..df294f4 100755
--- a/tests/genpackage.sh
+++ b/tests/genpackage.sh
@@ -39,7 +39,7 @@ $PACKAGE ($EPOCH$VERSION$REVISION) $DISTRI; urgency=critical
-- me <guess@who> Mon, 01 Jan 1980 01:02:02 +0000
END
-dpkg-source --format=1.0 -b "$DIR"
+dpkg-source --format=1.0 -b "$DIR" > /dev/null
mkdir -p "$DIR"/debian/tmp/DEBIAN
touch "$DIR"/debian/tmp/x
mkdir "$DIR"/debian/tmp/a
@@ -56,9 +56,9 @@ for pkg in `grep '^Package: ' debian/control | sed -e 's/^Package: //'` ; do
else
dpkg-gencontrol -p$pkg
fi
- dpkg --build debian/tmp ..
+ dpkg --build debian/tmp .. > /dev/null
done
-dpkg-genchanges "$@" > "$OUTPUT".pre
+dpkg-genchanges -q "$@" > "$OUTPUT".pre
# simulate dpkg-genchanges behaviour currently in sid so the testsuite runs for backports, too
awk 'BEGIN{inheader=0} /^Files:/ || (inheader && /^ /) {inheader = 1; next} {inheader = 0 ; print}' "$OUTPUT".pre | sed -e 's/ \+$//' >../"$OUTPUT"
echo "Files:" >> ../"$OUTPUT"
--
2.9.3
From b63bdbb47941aa3da97c8c6c3d29ecba31cd79c1 Mon Sep 17 00:00:00 2001
From: Benjamin Drung <benjamin.dr...@profitbricks.com>
Date: Mon, 6 Feb 2017 17:44:16 +0100
Subject: [PATCH 05/58] [testsuite] Add basic shunit2 based tests
Closes: #857302
Signed-off-by: Benjamin Drung <benjamin.dr...@profitbricks.com>
---
tests/Makefile.am | 10 ++++-
tests/basic.sh | 78 +++++++++++++++++++++++++++++++++++++++
tests/shunit2-helper-functions.sh | 61 ++++++++++++++++++++++++++++++
3 files changed, 148 insertions(+), 1 deletion(-)
create mode 100755 tests/basic.sh
create mode 100644 tests/shunit2-helper-functions.sh
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 901b302..78cb38a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -45,5 +45,13 @@ good.key \
revoked.key \
revoked.pkey \
withsubkeys.key \
-withsubkeys-works.key
+withsubkeys-works.key \
+basic.sh \
+shunit2-helper-functions.sh
MAINTAINERCLEANFILES = $(srcdir)/Makefile.in
+
+check:
+ ./basic.sh
+
+clean-local:
+ rm -rf testrepo testpkgs
diff --git a/tests/basic.sh b/tests/basic.sh
new file mode 100755
index 0000000..e7c562e
--- /dev/null
+++ b/tests/basic.sh
@@ -0,0 +1,78 @@
+#!/bin/sh
+set -u
+
+# Copyright (C) 2017, Benjamin Drung <benjamin.dr...@profitbricks.com>
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+. "${0%/*}/shunit2-helper-functions.sh"
+
+setUp() {
+ create_repo
+}
+
+test_empty() {
+ $REPREPRO -b $REPO export
+ call $REPREPRO -b $REPO list buster
+ assertEquals "" "$($REPREPRO -b $REPO list buster)"
+}
+
+test_list() {
+ (cd $PKGS && PACKAGE=hello SECTION=main DISTRI=buster VERSION=1.0 REVISION=-1 ../genpackage.sh)
+ call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedeb buster $PKGS/hello_1.0-1_${ARCH}.deb
+ assertEquals "buster|main|$ARCH: hello 1.0-1" "$($REPREPRO -b $REPO list buster)"
+}
+
+test_ls() {
+ (cd $PKGS && PACKAGE=hello SECTION=main DISTRI=buster EPOCH="1:" VERSION=2.5 REVISION=-3 ../genpackage.sh)
+ call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedeb buster $PKGS/hello_2.5-3_${ARCH}.deb
+ assertEquals "hello | 1:2.5-3 | buster | $ARCH" "$($REPREPRO -b $REPO ls hello)"
+}
+
+test_copy() {
+ (cd $PKGS && PACKAGE=hello SECTION=main DISTRI=buster EPOCH="1:" VERSION=2.5 REVISION=-3 ../genpackage.sh)
+ call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedeb buster $PKGS/hello_2.5-3_${ARCH}.deb
+ assertEquals "hello | 1:2.5-3 | buster | $ARCH" "$($REPREPRO -b $REPO ls hello)"
+ add_distro bullseye
+ call $REPREPRO $VERBOSE_ARGS -b $REPO copy bullseye buster hello
+ assertEquals "bullseye|main|$ARCH: hello 1:2.5-3" "$($REPREPRO -b $REPO list bullseye)"
+}
+
+test_include_changes() {
+ (cd $PKGS && PACKAGE=sl SECTION=main DISTRI=buster EPOCH="" VERSION=3.03 REVISION=-1 ../genpackage.sh)
+ call $REPREPRO $VERBOSE_ARGS -b $REPO -C main include buster $PKGS/test.changes
+ assertEquals "\
+buster|main|$ARCH: sl 3.03-1
+buster|main|$ARCH: sl-addons 3.03-1
+buster|main|source: sl 3.03-1" "$($REPREPRO -b $REPO list buster)"
+}
+
+test_include_old() {
+ # Test including an old package version. Expected output:
+ # Skipping inclusion of 'hello' '2.9-1' in 'buster|main|amd64', as it has already '2.9-2'.
+ (cd $PKGS && PACKAGE=hello SECTION=main DISTRI=buster VERSION=2.9 REVISION=-1 ../genpackage.sh)
+ (cd $PKGS && PACKAGE=hello SECTION=main DISTRI=buster VERSION=2.9 REVISION=-2 ../genpackage.sh)
+ call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedeb buster $PKGS/hello_2.9-2_${ARCH}.deb
+ call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedeb buster $PKGS/hello_2.9-1_${ARCH}.deb
+ assertEquals "buster|main|amd64: hello 2.9-2" "$($REPREPRO -b $REPO list buster)"
+}
+
+test_include_twice() {
+ (cd $PKGS && PACKAGE=hello SECTION=main DISTRI=buster VERSION=2.9 REVISION=-1 ../genpackage.sh)
+ (cd $PKGS && PACKAGE=hello SECTION=main DISTRI=buster VERSION=2.9 REVISION=-2 ../genpackage.sh)
+ call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedeb buster $PKGS/hello_2.9-1_${ARCH}.deb
+ call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedeb buster $PKGS/hello_2.9-2_${ARCH}.deb
+ assertEquals "buster|main|amd64: hello 2.9-2" "$($REPREPRO -b $REPO list buster)"
+}
+
+. shunit2
diff --git a/tests/shunit2-helper-functions.sh b/tests/shunit2-helper-functions.sh
new file mode 100644
index 0000000..5d23816
--- /dev/null
+++ b/tests/shunit2-helper-functions.sh
@@ -0,0 +1,61 @@
+# Copyright (C) 2017, Benjamin Drung <benjamin.dr...@profitbricks.com>
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+REPO="${0%/*}/testrepo"
+PKGS="${0%/*}/testpkgs"
+ARCH=${ARCH:-$(dpkg-architecture -qDEB_HOST_ARCH)}
+REPREPRO=$(realpath -m "${0%/*}/.." --relative-base=.)/reprepro
+VERBOSE_ARGS="${VERBOSE_ARGS-}"
+
+call() {
+ command="$@"
+ echo "I: Calling $@"
+ "$@" || fail "Command '$command' failed with exit code $?."
+}
+
+add_distro() {
+ local name="$1"
+ if test -e $REPO/conf/distributions; then
+ echo >> $REPO/conf/distributions
+ fi
+ cat >> $REPO/conf/distributions <<EOF
+Codename: $name
+Architectures: $ARCH source
+Components: main non-free
+EOF
+ if test -n "${2-}"; then
+ echo "$2" >> $REPO/conf/distributions
+ fi
+}
+
+clear_distro() {
+ rm -f $REPO/conf/distributions
+}
+
+create_repo() {
+ rm -rf $REPO
+ mkdir -p $REPO/conf
+ add_distro buster
+ mkdir -p $PKGS
+ $REPREPRO -b $REPO export
+}
+
+# See https://github.com/wting/shunit2/issues/23
+if test -n "${TEST_CASES-}"; then
+ suite() {
+ for testcase in "${TEST_CASES}" ; do
+ suite_addTest $testcase
+ done
+ }
+fi
--
2.9.3