[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.
This commit is contained in:
parent
01c9916cb9
commit
6a02f2cfec
@ -108,6 +108,10 @@ MachineIdTests::testJob()
|
|||||||
{
|
{
|
||||||
Logger::setupLogLevel( Logger::LOGDEBUG );
|
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
|
// Ensure we have a system object, expect it to be a "bogus" one
|
||||||
CalamaresUtils::System* system = CalamaresUtils::System::instance();
|
CalamaresUtils::System* system = CalamaresUtils::System::instance();
|
||||||
QVERIFY( system );
|
QVERIFY( system );
|
||||||
@ -122,7 +126,7 @@ MachineIdTests::testJob()
|
|||||||
Calamares::GlobalStorage* gs
|
Calamares::GlobalStorage* gs
|
||||||
= Calamares::JobQueue::instance() ? Calamares::JobQueue::instance()->globalStorage() : nullptr;
|
= Calamares::JobQueue::instance() ? Calamares::JobQueue::instance()->globalStorage() : nullptr;
|
||||||
QVERIFY( gs );
|
QVERIFY( gs );
|
||||||
gs->insert( "rootMountPoint", "/tmp" );
|
gs->insert( "rootMountPoint", tempRoot.path() );
|
||||||
|
|
||||||
// Prepare part of the target filesystem
|
// Prepare part of the target filesystem
|
||||||
{
|
{
|
||||||
@ -143,7 +147,7 @@ MachineIdTests::testJob()
|
|||||||
{
|
{
|
||||||
auto r = job.exec();
|
auto r = job.exec();
|
||||||
QVERIFY( !r ); // It's supposed to fail, because no dbus-uuidgen executable exists
|
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 );
|
config.insert( "dbus-symlink", true );
|
||||||
@ -151,7 +155,7 @@ MachineIdTests::testJob()
|
|||||||
{
|
{
|
||||||
auto r = job.exec();
|
auto r = job.exec();
|
||||||
QVERIFY( !r ); // It's supposed to fail, because no dbus-uuidgen executable exists
|
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
|
// These all (would) fail, because the chroot isn't viable
|
||||||
#if 0
|
#if 0
|
||||||
@ -163,6 +167,7 @@ MachineIdTests::testJob()
|
|||||||
QCOMPARE( fi.size(), 5);
|
QCOMPARE( fi.size(), 5);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
tempRoot.setAutoRemove( true ); // All tests succeeded
|
||||||
}
|
}
|
||||||
|
|
||||||
QTEST_GUILESS_MAIN( MachineIdTests )
|
QTEST_GUILESS_MAIN( MachineIdTests )
|
||||||
|
Loading…
Reference in New Issue
Block a user