[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
main
Adriaan de Groot 5 years ago
parent fba1bf7072
commit 8ecb364f8c

@ -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 ) );

@ -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();
};

Loading…
Cancel
Save