From 6a02f2cfec9a3737d6568a3e7b2611a97ce2af51 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 21 Feb 2020 19:21:58 +0100 Subject: [PATCH] [machineid] Fix tests - Make tests more resilient: do them in a temp-dir, and clean it up after successful tests. This was prompted by tests failing because of things hanging around in /tmp. --- src/modules/machineid/Tests.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/modules/machineid/Tests.cpp b/src/modules/machineid/Tests.cpp index 4600633b0..2b6a9b1d1 100644 --- a/src/modules/machineid/Tests.cpp +++ b/src/modules/machineid/Tests.cpp @@ -108,6 +108,10 @@ MachineIdTests::testJob() { Logger::setupLogLevel( Logger::LOGDEBUG ); + QTemporaryDir tempRoot( QDir::tempPath() + QStringLiteral( "/test-job-XXXXXX" ) ); + tempRoot.setAutoRemove( false ); + cDebug() << "Temporary files as" << QDir::tempPath(); + // Ensure we have a system object, expect it to be a "bogus" one CalamaresUtils::System* system = CalamaresUtils::System::instance(); QVERIFY( system ); @@ -122,7 +126,7 @@ MachineIdTests::testJob() Calamares::GlobalStorage* gs = Calamares::JobQueue::instance() ? Calamares::JobQueue::instance()->globalStorage() : nullptr; QVERIFY( gs ); - gs->insert( "rootMountPoint", "/tmp" ); + gs->insert( "rootMountPoint", tempRoot.path() ); // Prepare part of the target filesystem { @@ -143,7 +147,7 @@ MachineIdTests::testJob() { auto r = job.exec(); QVERIFY( !r ); // It's supposed to fail, because no dbus-uuidgen executable exists - QVERIFY( QFile::exists( "/tmp/var/lib/dbus" ) ); // but the target dir exists + QVERIFY( QFile::exists( tempRoot.filePath( "var/lib/dbus" ) ) ); // but the target dir exists } config.insert( "dbus-symlink", true ); @@ -151,7 +155,7 @@ MachineIdTests::testJob() { auto r = job.exec(); QVERIFY( !r ); // It's supposed to fail, because no dbus-uuidgen executable exists - QVERIFY( QFile::exists( "/tmp/var/lib/dbus" ) ); // but the target dir exists + QVERIFY( QFile::exists( tempRoot.filePath( "var/lib/dbus" ) ) ); // but the target dir exists // These all (would) fail, because the chroot isn't viable #if 0 @@ -163,6 +167,7 @@ MachineIdTests::testJob() QCOMPARE( fi.size(), 5); #endif } + tempRoot.setAutoRemove( true ); // All tests succeeded } QTEST_GUILESS_MAIN( MachineIdTests )