[luksbootkeyfile] Start adding tests
This commit is contained in:
parent
1752dd573b
commit
4466e360e1
@ -11,3 +11,10 @@ calamares_add_plugin( luksbootkeyfile
|
||||
SHARED_LIB
|
||||
NO_CONFIG
|
||||
)
|
||||
|
||||
calamares_add_test(
|
||||
luksbootkeyfiletest
|
||||
SOURCES
|
||||
Tests.cpp
|
||||
LuksBootKeyFileJob.cpp
|
||||
)
|
||||
|
@ -157,21 +157,21 @@ partitionsFromGlobalStorage()
|
||||
}
|
||||
|
||||
/// Checks if the partition (represented by @p map) mounts to the given @p path
|
||||
static bool
|
||||
STATICTEST bool
|
||||
hasMountPoint( const QVariantMap& map, const QString& path )
|
||||
{
|
||||
const QString mountPoint = map.value( QStringLiteral( "mountPoint" ) ).toString();
|
||||
return QDir::cleanPath( mountPoint ) == path;
|
||||
}
|
||||
|
||||
static bool
|
||||
STATICTEST bool
|
||||
isEncrypted( const QVariantMap& map )
|
||||
{
|
||||
return map.contains( QStringLiteral( "luksMapperName" ) );
|
||||
}
|
||||
|
||||
/// Checks for any partition satisfying @p pred
|
||||
static bool
|
||||
STATICTEST bool
|
||||
anyPartition( bool ( *pred )( const QVariantMap& ) )
|
||||
{
|
||||
const auto partitions = partitionsFromGlobalStorage();
|
||||
@ -181,7 +181,7 @@ anyPartition( bool ( *pred )( const QVariantMap& ) )
|
||||
!= partitions.cend();
|
||||
}
|
||||
|
||||
static bool
|
||||
STATICTEST bool
|
||||
hasUnencryptedSeparateBoot()
|
||||
{
|
||||
return anyPartition(
|
||||
@ -189,7 +189,7 @@ hasUnencryptedSeparateBoot()
|
||||
{ return hasMountPoint( partition, QStringLiteral( "/boot" ) ) && !isEncrypted( partition ); } );
|
||||
}
|
||||
|
||||
static bool
|
||||
STATICTEST bool
|
||||
hasEncryptedRoot()
|
||||
{
|
||||
return anyPartition( []( const QVariantMap& partition )
|
||||
|
83
src/modules/luksbootkeyfile/Tests.cpp
Normal file
83
src/modules/luksbootkeyfile/Tests.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
/* === This file is part of Calamares - <https://calamares.io> ===
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2022 Adriaan de Groot <groot@kde.org>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* Calamares is Free Software: see the License-Identifier above.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "JobQueue.h"
|
||||
#include "utils/Logger.h"
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
#undef STATICTEST
|
||||
#define STATICTEST extern
|
||||
|
||||
// Implementation details
|
||||
STATICTEST bool hasMountPoint( const QVariantMap& map, const QString& path );
|
||||
|
||||
STATICTEST bool isEncrypted( const QVariantMap& map );
|
||||
|
||||
STATICTEST bool anyPartition( bool ( *pred )( const QVariantMap& ) );
|
||||
|
||||
STATICTEST bool hasUnencryptedSeparateBoot();
|
||||
|
||||
STATICTEST bool hasEncryptedRoot();
|
||||
|
||||
class LuksBootKeyFileTests : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
LuksBootKeyFileTests() {}
|
||||
~LuksBootKeyFileTests() override {}
|
||||
|
||||
private Q_SLOTS:
|
||||
void initTestCase();
|
||||
|
||||
void testMountPoint();
|
||||
};
|
||||
|
||||
void
|
||||
LuksBootKeyFileTests::initTestCase()
|
||||
{
|
||||
Logger::setupLogLevel( Logger::LOGDEBUG );
|
||||
cDebug() << "LuksBootKeyFile test started.";
|
||||
|
||||
if ( !Calamares::JobQueue::instance() )
|
||||
{
|
||||
(void)new Calamares::JobQueue();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
LuksBootKeyFileTests::testMountPoint()
|
||||
{
|
||||
QVariantMap m; // As if this is a partition data
|
||||
const QString key = QStringLiteral( "mountPoint" );
|
||||
const QString boot = QStringLiteral( "/boot" );
|
||||
const QString root = QStringLiteral( "/" );
|
||||
|
||||
QVERIFY( !hasMountPoint( m, QString() ) );
|
||||
QVERIFY( !hasMountPoint( m, boot ) );
|
||||
|
||||
m.insert( key, boot );
|
||||
QVERIFY( hasMountPoint( m, boot ) );
|
||||
QVERIFY( !hasMountPoint( m, QString() ) );
|
||||
QVERIFY( !hasMountPoint( m, root ) );
|
||||
|
||||
m.insert( key, root );
|
||||
QVERIFY( !hasMountPoint( m, boot ) );
|
||||
QVERIFY( !hasMountPoint( m, QString() ) );
|
||||
QVERIFY( hasMountPoint( m, root ) );
|
||||
|
||||
m.remove( key );
|
||||
QVERIFY( !hasMountPoint( m, root ) );
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN( LuksBootKeyFileTests )
|
||||
|
||||
#include "utils/moc-warnings.h"
|
||||
|
||||
#include "Tests.moc"
|
Loading…
Reference in New Issue
Block a user