From 8ecb364f8cedc2dc978a6a460b043234d71af0c5 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 19 Feb 2020 22:42:46 +0100 Subject: [PATCH] [initramfs] Fix up tests - These tests don't actually test anything in this specific module, they do test CalamaresUtils::System. - Wrangling System and JobQueue and GlobalStorage instances is fraught --- src/modules/initramfs/Tests.cpp | 32 ++++++++------------------------ src/modules/initramfs/Tests.h | 4 ++-- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/src/modules/initramfs/Tests.cpp b/src/modules/initramfs/Tests.cpp index 39d2abeaa..a9e0ce44c 100644 --- a/src/modules/initramfs/Tests.cpp +++ b/src/modules/initramfs/Tests.cpp @@ -45,6 +45,9 @@ void InitramfsTests::initTestCase() { Logger::setupLogLevel( Logger::LOGDEBUG ); + + auto* j = new Calamares::JobQueue(); + (void) new CalamaresUtils::System( true ); } static const char contents[] = "UMASK=0077\n"; @@ -55,40 +58,21 @@ void InitramfsTests::cleanup() QFile::remove( confFile ); } -void InitramfsTests::testCreateHostFile() -{ - - CalamaresUtils::System s( false ); // don't chroot - auto r = s.createTargetFile( confFile, QByteArray( contents ) ); - QVERIFY( !r.failed() ); - QVERIFY( r ); - QString path = r.path(); - QVERIFY( !path.isEmpty() ); - QCOMPARE( path, confFile ); // don't chroot, so path create relative to / - QVERIFY( QFile::exists( confFile ) ); - - QFileInfo fi( confFile ); - QVERIFY( fi.exists() ); - QCOMPARE( fi.size(), sizeof( contents )-1 ); // don't count trailing NUL - - QFile::remove( confFile ); -} - void InitramfsTests::testCreateTargetFile() { static const char short_confFile[] = "/calamares-safe-umask"; - CalamaresUtils::System s( true ); - auto r = s.createTargetFile( short_confFile, QByteArray( contents ) ); + auto* s = CalamaresUtils::System::instance(); + auto r = s->createTargetFile( short_confFile, QByteArray( contents ) ); QVERIFY( r.failed() ); QVERIFY( !r ); QString path = r.path(); QVERIFY( path.isEmpty() ); // because no rootmountpoint is set - Calamares::JobQueue j; - j.globalStorage()->insert( "rootMountPoint", "/tmp" ); + Calamares::JobQueue::instance()->globalStorage()->insert( "rootMountPoint", "/tmp" ); - path = s.createTargetFile( short_confFile, QByteArray( contents ) ); + path = s->createTargetFile( short_confFile, QByteArray( contents ) ).path(); + QCOMPARE( path, QString( confFile ) ); QVERIFY( path.endsWith( short_confFile ) ); // chroot, so path create relative to QVERIFY( path.startsWith( "/tmp/" ) ); QVERIFY( QFile::exists( path ) ); diff --git a/src/modules/initramfs/Tests.h b/src/modules/initramfs/Tests.h index 01394d4fa..715c90169 100644 --- a/src/modules/initramfs/Tests.h +++ b/src/modules/initramfs/Tests.h @@ -31,8 +31,8 @@ public: private Q_SLOTS: void initTestCase(); void cleanup(); - - void testCreateHostFile(); + + // TODO: this doesn't actually test any of the functionality of this job void testCreateTargetFile(); };