[libcalamars] Improve test init and cleanup
- Test createTargetFile and removeTargetFile - Clean up afterwards - Ensure /tmp is the RMP for each test
This commit is contained in:
parent
b502d78984
commit
8b8ecf7b7b
@ -42,13 +42,20 @@ public:
|
|||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void initTestCase();
|
void initTestCase();
|
||||||
|
void init();
|
||||||
|
void cleanupTestCase();
|
||||||
|
|
||||||
void testTargetPath();
|
void testTargetPath();
|
||||||
|
void testCreateTarget();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CalamaresUtils::System* m_system; // Points to singleton instance, not owned
|
CalamaresUtils::System* m_system = nullptr; // Points to singleton instance, not owned
|
||||||
|
Calamares::GlobalStorage* m_gs = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const char testFile[] = "/calamares-testcreate";
|
||||||
|
static const char absFile[] = "/tmp/calamares-testcreate"; // With rootMountPoint prepended
|
||||||
|
|
||||||
void
|
void
|
||||||
TestPaths::initTestCase()
|
TestPaths::initTestCase()
|
||||||
{
|
{
|
||||||
@ -62,14 +69,28 @@ TestPaths::initTestCase()
|
|||||||
// Ensure we have a system-wide GlobalStorage with /tmp as root
|
// Ensure we have a system-wide GlobalStorage with /tmp as root
|
||||||
if ( !Calamares::JobQueue::instance() )
|
if ( !Calamares::JobQueue::instance() )
|
||||||
{
|
{
|
||||||
|
cDebug() << "Creating new JobQueue";
|
||||||
(void)new Calamares::JobQueue();
|
(void)new Calamares::JobQueue();
|
||||||
}
|
}
|
||||||
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" );
|
|
||||||
|
|
||||||
m_system = system;
|
m_system = system;
|
||||||
|
m_gs = gs;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TestPaths::cleanupTestCase()
|
||||||
|
{
|
||||||
|
QFile::remove( absFile );
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TestPaths::init()
|
||||||
|
{
|
||||||
|
cDebug() << "Setting rootMountPoint";
|
||||||
|
m_gs->insert( "rootMountPoint", "/tmp" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -78,17 +99,33 @@ TestPaths::testTargetPath()
|
|||||||
{
|
{
|
||||||
// Paths mapped normally
|
// Paths mapped normally
|
||||||
QCOMPARE( m_system->targetPath( "/etc/calamares" ), QStringLiteral( "/tmp/etc/calamares" ) );
|
QCOMPARE( m_system->targetPath( "/etc/calamares" ), QStringLiteral( "/tmp/etc/calamares" ) );
|
||||||
QCOMPARE( m_system->targetPath( "//etc//calamares" ), QStringLiteral( "/tmp//etc//calamares" ) ); // extra / are not cleaned up
|
QCOMPARE( m_system->targetPath( "//etc//calamares" ),
|
||||||
|
QStringLiteral( "/tmp//etc//calamares" ) ); // extra / are not cleaned up
|
||||||
QCOMPARE( m_system->targetPath( "etc/calamares" ), QStringLiteral( "/tmp/etc/calamares" ) ); // relative to root
|
QCOMPARE( m_system->targetPath( "etc/calamares" ), QStringLiteral( "/tmp/etc/calamares" ) ); // relative to root
|
||||||
|
|
||||||
// Weird Paths
|
// Weird Paths
|
||||||
QCOMPARE( m_system->targetPath( QString() ), QStringLiteral( "/tmp/" ) );
|
QCOMPARE( m_system->targetPath( QString() ), QStringLiteral( "/tmp/" ) );
|
||||||
|
|
||||||
// Now break GS
|
// Now break GS
|
||||||
Calamares::JobQueue::instance()->globalStorage()->remove( "rootMountPoint" );
|
m_gs->remove( "rootMountPoint" );
|
||||||
QCOMPARE( m_system->targetPath( QString() ), QString() ); // Without root, no path
|
QCOMPARE( m_system->targetPath( QString() ), QString() ); // Without root, no path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TestPaths::testCreateTarget()
|
||||||
|
{
|
||||||
|
QCOMPARE( m_system->createTargetFile( testFile, "Hello" ), QString( absFile ) ); // Success
|
||||||
|
|
||||||
|
QFileInfo fi( absFile );
|
||||||
|
QVERIFY( fi.exists() );
|
||||||
|
QCOMPARE( fi.size(), 5 );
|
||||||
|
|
||||||
|
m_system->removeTargetFile( testFile );
|
||||||
|
QFileInfo fi2( absFile ); // fi caches information
|
||||||
|
QVERIFY( !fi2.exists() );
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_GUILESS_MAIN( TestPaths )
|
QTEST_GUILESS_MAIN( TestPaths )
|
||||||
|
|
||||||
#include "utils/moc-warnings.h"
|
#include "utils/moc-warnings.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user