From c470d92366d7c3c239a689f0a10d6d0d9daafbff Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 18 May 2020 11:55:54 +0200 Subject: Allow prefix to be a complete filename for GetTempFile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Our testcases had their own implementation of GetTempFile with the feature of a temporary file with a choosen suffix. Merging this into GetTempFile lets us drop this duplicate and hence test more our code rather than testing our helpers for test implementation. And then hashsums_test had another implementation… and extracttar wasn't even trying to use a real tempfile… one GetTempFile to rule them all! That also ensures that these tempfiles are created in a temporary directory rather than the current directory which is a nice touch and tries a little harder to clean up those tempfiles. --- test/libapt/cdrom_test.cc | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'test/libapt/cdrom_test.cc') diff --git a/test/libapt/cdrom_test.cc b/test/libapt/cdrom_test.cc index b21492cb7..e2ec05ab8 100644 --- a/test/libapt/cdrom_test.cc +++ b/test/libapt/cdrom_test.cc @@ -91,16 +91,14 @@ TEST(CDROMTest,ReduceSourcelist) } TEST(CDROMTest, FindMountPointForDevice) { - std::string tempfile; - FileFd fd; - createTemporaryFile("mountpoints", fd, &tempfile, + auto const file = createTemporaryFile("mountpoints", "rootfs / rootfs rw 0 0\n" "sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0\n" "sysfs0 /sys0 sysfs rw,nosuid,nodev,noexec,relatime 0 0\n" "/dev/disk/by-uuid/fadcbc52-6284-4874-aaaa-dcee1f05fe21 / ext4 rw,relatime,errors=remount-ro,data=ordered 0 0\n" "/dev/sda1 /boot/efi vfat rw,nosuid,nodev,noexec,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=437,iocharset=utf8,shortname=lower,quiet,utf8,errors=remount-ro,rw,nosuid,nodev,noexec,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=437,iocharset=utf8,shortname=lower,quiet,utf8,errors=remount-ro,rw,nosuid,nodev,noexec,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=437,iocharset=utf8,shortname=lower,quiet,utf8,errors=remount-ro,rw,nosuid,nodev,noexec,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=437,iocharset=utf8,shortname=lower,quiet,utf8,errors=remount-ro 0 0\n" "tmpfs /tmp tmpfs rw,nosuid,nodev,relatime 0 0\n"); - _config->Set("Dir::state::Mountpoints", tempfile); + _config->Set("Dir::state::Mountpoints", file.Name()); EXPECT_EQ("/", FindMountPointForDevice("rootfs")); EXPECT_EQ("/", FindMountPointForDevice("/dev/disk/by-uuid/fadcbc52-6284-4874-aaaa-dcee1f05fe21")); @@ -108,7 +106,4 @@ TEST(CDROMTest, FindMountPointForDevice) EXPECT_EQ("/sys0", FindMountPointForDevice("sysfs0")); EXPECT_EQ("/boot/efi", FindMountPointForDevice("/dev/sda1")); EXPECT_EQ("/tmp", FindMountPointForDevice("tmpfs")); - - if (tempfile.empty() == false) - unlink(tempfile.c_str()); } -- cgit v1.2.3-70-g09d2