From 85c058381940ac7c31e80bc8538fab3887b10548 Mon Sep 17 00:00:00 2001 From: Axel Beckert Date: Sun, 20 Dec 2020 06:44:12 +0100 Subject: [PATCH] Add test for $dist/updates vs $dist-security Uses Test::File::Contents, add it to .travis.yml and the according package as build-dependency in debian/control. --- .travis.yml | 2 +- debian/changelog | 1 + debian/control | 1 + t/data/sources.list.bookworm | 16 +++++++ t/data/sources.list.bullseye | 16 +++++++ t/data/sources.list.buster | 16 +++++++ t/data/sources.list.sid | 16 +++++++ t/data/sources.list.stretch | 16 +++++++ t/hook-apt.t | 92 ++++++++++++++++++++++++++++++++++++ 9 files changed, 175 insertions(+), 1 deletion(-) create mode 100644 t/data/sources.list.bookworm create mode 100644 t/data/sources.list.bullseye create mode 100644 t/data/sources.list.buster create mode 100644 t/data/sources.list.sid create mode 100644 t/data/sources.list.stretch create mode 100755 t/hook-apt.t diff --git a/.travis.yml b/.travis.yml index fce1b90..abf3090 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,7 +28,7 @@ before_install: - perl -V install: - - yes '' | cpanm --verbose --notest --skip-satisfied Data::Validate::Domain Data::Validate::IP Data::Validate::URI File::Slurp File::Which Log::Message Term::UI Test::NoTabs Test::Pod::Coverage Test::Pod Text::Template Devel::Cover::Report::Coveralls Sort::Versions + - yes '' | cpanm --verbose --notest --skip-satisfied Data::Validate::Domain Data::Validate::IP Data::Validate::URI File::Slurp File::Which Log::Message Term::UI Test::NoTabs Test::Pod::Coverage Test::Pod Text::Template Devel::Cover::Report::Coveralls Sort::Versions Test::File::Contents - export RELEASE_TESTING=1 AUTOMATED_TESTING=1 AUTHOR_TESTING=1 HARNESS_OPTIONS=j10:c HARNESS_TIMER=1 PATH=bin:${PERLBREW_PATH}:${PATH} script: diff --git a/debian/changelog b/debian/changelog index b8290b4..80b7a0e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -10,6 +10,7 @@ xen-tools (4.8.1~dev-1) UNRELEASED; urgency=medium + Distinguish between those Debian releases using $dist/updates for security updates and those who use $dist-security. Thanks Paul Wise! (Closes: #972749) + - Add test for this; needs libtest-file-contents-perl as build-dep. + Fix support for lvm_thin. Thanks to Andreas Sundstrom for the bug report and patch! (Closes: #942244) + Mount /proc and /dev before calling update-grub. Thanks to Brandon diff --git a/debian/control b/debian/control index ff3c240..d72c4b8 100644 --- a/debian/control +++ b/debian/control @@ -13,6 +13,7 @@ Build-Depends: debhelper-compat (= 13), liblog-message-perl | perl (<< 5.17.0), libterm-ui-perl | perl (<< 5.17.0), libsort-versions-perl, + libtest-file-contents-perl, libtest-notabs-perl, libtest-pod-coverage-perl, libtest-pod-perl, diff --git a/t/data/sources.list.bookworm b/t/data/sources.list.bookworm new file mode 100644 index 0000000..12252e7 --- /dev/null +++ b/t/data/sources.list.bookworm @@ -0,0 +1,16 @@ +# +# /etc/apt/sources.list +# + + +# +# bookworm +# +deb http://deb.debian.org/debian bookworm main contrib non-free +deb-src http://deb.debian.org/debian bookworm main contrib non-free + +# +# Security updates +# +deb http://security.debian.org/ bookworm-security main contrib non-free +deb-src http://security.debian.org/ bookworm-security main contrib non-free diff --git a/t/data/sources.list.bullseye b/t/data/sources.list.bullseye new file mode 100644 index 0000000..e2a214e --- /dev/null +++ b/t/data/sources.list.bullseye @@ -0,0 +1,16 @@ +# +# /etc/apt/sources.list +# + + +# +# bullseye +# +deb http://deb.debian.org/debian bullseye main contrib non-free +deb-src http://deb.debian.org/debian bullseye main contrib non-free + +# +# Security updates +# +deb http://security.debian.org/ bullseye-security main contrib non-free +deb-src http://security.debian.org/ bullseye-security main contrib non-free diff --git a/t/data/sources.list.buster b/t/data/sources.list.buster new file mode 100644 index 0000000..370da88 --- /dev/null +++ b/t/data/sources.list.buster @@ -0,0 +1,16 @@ +# +# /etc/apt/sources.list +# + + +# +# buster +# +deb http://deb.debian.org/debian buster main contrib non-free +deb-src http://deb.debian.org/debian buster main contrib non-free + +# +# Security updates +# +deb http://security.debian.org/ buster/updates main contrib non-free +deb-src http://security.debian.org/ buster/updates main contrib non-free diff --git a/t/data/sources.list.sid b/t/data/sources.list.sid new file mode 100644 index 0000000..8521dd3 --- /dev/null +++ b/t/data/sources.list.sid @@ -0,0 +1,16 @@ +# +# /etc/apt/sources.list +# + + +# +# sid +# +deb http://deb.debian.org/debian sid main contrib non-free +deb-src http://deb.debian.org/debian sid main contrib non-free + +# +# Security updates - Uncomment to enable. +# +# deb http://security.debian.org/ sid-security main contrib non-free +# deb-src http://security.debian.org/ sid-security main contrib non-free diff --git a/t/data/sources.list.stretch b/t/data/sources.list.stretch new file mode 100644 index 0000000..ea1db4a --- /dev/null +++ b/t/data/sources.list.stretch @@ -0,0 +1,16 @@ +# +# /etc/apt/sources.list +# + + +# +# stretch +# +deb http://deb.debian.org/debian stretch main contrib non-free +deb-src http://deb.debian.org/debian stretch main contrib non-free + +# +# Security updates +# +deb http://security.debian.org/ stretch/updates main contrib non-free +deb-src http://security.debian.org/ stretch/updates main contrib non-free diff --git a/t/hook-apt.t b/t/hook-apt.t new file mode 100755 index 0000000..3479cb8 --- /dev/null +++ b/t/hook-apt.t @@ -0,0 +1,92 @@ +#!perl -w +# +# Test that the /etc/inittab file is modified as we expect. +# +# Steve +# -- +# + +use strict; +use Test::More; +use Test::File::Contents; +use File::Temp; +use File::Copy; +use File::Path qw(make_path); + +my $asl = 't/data/sources.list'; +my $hook_dir = $ENV{AS_INSTALLED_TESTING} ? '/usr/share/xen-tools' : 'hooks'; + +foreach my $dist (qw(stretch buster bullseye bookworm sid)) { + testHook( $dist ); +} + +done_testing(); + +sub testHook +{ + my ( $dist ) = ( @_ ); + my $dasl = "$asl.$dist"; + my $ea = 'etc/apt'; + my $easl = "$ea/sources.list"; + my $hook = "$hook_dir/" . + ( + $ENV{AS_INSTALLED_TESTING} ? + $dist : + 'debian' + ) . '/20-setup-apt'; + + # + # Check that the according sample sources.list exists. + # + if (-e $dasl) { + + # + # Create a temporary directory to use as prefix + # + my $dir = File::Temp::tempdir( CLEANUP => 1 ); + make_path( "$dir/$ea/apt.conf.d", { chmod => 0755 }); + make_path( "$dir/bin", { chmod => 0755 }); + my $tmphook = "$dir/bin/20-setup-apt"; + + # + # Make sure that worked. + # + ok( -d $dir, "temporary directory created OK [$dist]" ); + ok( -d "$dir/bin", + "bin inside temporary directory created OK [$dist]" ); + ok( -d "$dir/$ea", + "$ea inside temporary directory created OK [$dist]" ); + + # Create a copy of the 20-setup-apt hook to be able to comment + # out the chroot + apt-get update call. + File::Copy::cp( $hook, $tmphook ); + + ok( -e "$tmphook", "hook exists in temporary directory [$dist]" ); + ok( -x "$tmphook", + "hook is executable in temporary directory [$dist]" ); + + no warnings qw(qw); + is(system(qw(sed -e s/chroot/#chroot/ -i), $tmphook) >> 8, 0, + "chroot call in hook could be deactivated [$dist]"); + use warnings qw(qw); + + # + # Set up some variables expected by the hook + # + $ENV{dist} = $dist; + $ENV{mirror} = 'http://deb.debian.org/debian'; + + # + # Call the hook + # + is(system($tmphook, $dir) >> 8, 0, + "hook for $dist exited with zero return code"); + + ok( -e "$dir/$easl", "A sources.list file has been created. [$dist]" ); + files_eq_or_diff($dasl, "$dir/$easl", + "sources.list for $dist has the expected contents") + } + else { + BAIL_OUT("$dasl not found, source distribution seems incomplete"); + } +}