[libcalamares] Add tests for path functions (part 1)

This commit is contained in:
Adriaan de Groot 2020-02-07 11:51:13 +01:00
parent 95936549e2
commit 15bca702c1
2 changed files with 30 additions and 0 deletions

View File

@ -24,6 +24,9 @@
#include "UMask.h"
#include "Yaml.h"
#include "GlobalStorage.h"
#include "JobQueue.h"
#include <QTemporaryFile>
#include <QtTest/QtTest>
@ -221,3 +224,27 @@ LibCalamaresTests::testPrintableEntropy()
QVERIFY( c.cell() < 127 );
}
}
void
LibCalamaresTests::testTargetPath()
{
// Ensure we have a system object, expect it to be a "bogus" one
const CalamaresUtils::System* system = CalamaresUtils::System::instance();
QVERIFY( system );
QVERIFY( system->doChroot() );
// Ensure we have a system-wide GlobalStorage with /tmp as root
if ( !Calamares::JobQueue::instance() )
{
(void)new Calamares::JobQueue();
}
Calamares::GlobalStorage* gs
= Calamares::JobQueue::instance() ? Calamares::JobQueue::instance()->globalStorage() : nullptr;
QVERIFY( gs );
gs->insert( "rootMountPoint", "/tmp" );
// Paths mapped normally
QCOMPARE( system->targetPath( "/etc/calamares" ), QStringLiteral( "/tmp/etc/calamares" ) );
QCOMPARE( system->targetPath( "//etc//calamares" ), QStringLiteral( "/tmp/etc/calamares" ) ); // extra /
QCOMPARE( system->targetPath( "etc/calamares" ), QString() ); // NOT ABSOLUTE
}

View File

@ -43,6 +43,9 @@ private Q_SLOTS:
/** @brief Tests the entropy functions. */
void testEntropy();
void testPrintableEntropy();
/** @brief Tests file creation and removal. */
void testTargetPath();
};
#endif