From 285d2c80b9c9573aaa087d33fdff373dc16e1964 Mon Sep 17 00:00:00 2001 From: Axel Beckert Date: Sun, 20 Dec 2020 08:32:12 +0100 Subject: [PATCH] Use regexp to check for $dist/updates vs $dist-security If the security repo will be enabled or not currently depends on the host's sources.list. So the resulting files differ depending on the host where the test is run. Add a TODO item to break with that "feature". Also mention in the TODO list that a repo on archive.debian.org should be used instead security.debian.org if the release is EoL. Currently the security mirror is hardcoded into the hook. --- 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 | 89 +++++++++++++++++------------------- 6 files changed, 43 insertions(+), 126 deletions(-) delete mode 100644 t/data/sources.list.bookworm delete mode 100644 t/data/sources.list.bullseye delete mode 100644 t/data/sources.list.buster delete mode 100644 t/data/sources.list.sid delete mode 100644 t/data/sources.list.stretch diff --git a/t/data/sources.list.bookworm b/t/data/sources.list.bookworm deleted file mode 100644 index 12252e7..0000000 --- a/t/data/sources.list.bookworm +++ /dev/null @@ -1,16 +0,0 @@ -# -# /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 deleted file mode 100644 index e2a214e..0000000 --- a/t/data/sources.list.bullseye +++ /dev/null @@ -1,16 +0,0 @@ -# -# /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 deleted file mode 100644 index 370da88..0000000 --- a/t/data/sources.list.buster +++ /dev/null @@ -1,16 +0,0 @@ -# -# /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 deleted file mode 100644 index 8521dd3..0000000 --- a/t/data/sources.list.sid +++ /dev/null @@ -1,16 +0,0 @@ -# -# /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 deleted file mode 100644 index ea1db4a..0000000 --- a/t/data/sources.list.stretch +++ /dev/null @@ -1,16 +0,0 @@ -# -# /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 index 3479cb8..e13075b 100755 --- a/t/hook-apt.t +++ b/t/hook-apt.t @@ -13,7 +13,6 @@ 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)) { @@ -25,7 +24,6 @@ done_testing(); sub testHook { my ( $dist ) = ( @_ ); - my $dasl = "$asl.$dist"; my $ea = 'etc/apt'; my $easl = "$ea/sources.list"; my $hook = "$hook_dir/" . @@ -36,57 +34,56 @@ sub testHook ) . '/20-setup-apt'; # - # Check that the according sample sources.list exists. + # Create a temporary directory to use as prefix # - if (-e $dasl) { + 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"; - # - # 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]" ); - # - # 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 ); - # 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]" ); - 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); - 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'; - # - # 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"); - # - # 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"); + ok( -e "$dir/$easl", "A sources.list file has been created. [$dist]" ); + if ($dist =~ /stretch|buster/) { + file_contents_like( "$dir/$easl", qr(\b${dist}/updates\b), + "sources.list contains $dist/updates"); + file_contents_unlike( "$dir/$easl", qr(\b${dist}-security\b), + "sources.list doesn't contain $dist-security"); + } else { + file_contents_like( "$dir/$easl", qr(\b${dist}-security\b), + "sources.list contains $dist-security"); + file_contents_unlike( "$dir/$easl", qr(\b${dist}/updates\b), + "sources.list doesn't contain $dist/updates"); } }