mirror of
https://github.com/parchlinux/calamares.git
synced 2025-02-24 10:55:46 -05:00
[machineid] Add tests
- Testing some of the functionality that's been added just now: - copyfile fails, buggy implementation - poolsize fails, buggy implementation - removefile not tested
This commit is contained in:
parent
10e5995144
commit
2b9e1d6231
5 changed files with 125 additions and 8 deletions
|
@ -8,3 +8,17 @@ calamares_add_plugin( machineid
|
|||
calamares
|
||||
SHARED_LIB
|
||||
)
|
||||
|
||||
if ( ECM_FOUND AND BUILD_TESTING )
|
||||
ecm_add_test(
|
||||
Tests.cpp
|
||||
Workers.cpp
|
||||
TEST_NAME
|
||||
machineidtest
|
||||
LINK_LIBRARIES
|
||||
calamares
|
||||
Qt5::Core
|
||||
Qt5::Test
|
||||
)
|
||||
calamares_automoc( machineidtest )
|
||||
endif()
|
||||
|
|
|
@ -85,8 +85,10 @@ MachineIdJob::exec()
|
|||
//Create new files
|
||||
if ( m_entropy )
|
||||
{
|
||||
auto r = MachineId::createEntropy(
|
||||
m_entropy_copy ? MachineId::EntropyGeneration::CopyFromHost : MachineId::EntropyGeneration::New, root, target_entropy_file );
|
||||
auto r = MachineId::createEntropy( m_entropy_copy ? MachineId::EntropyGeneration::CopyFromHost
|
||||
: MachineId::EntropyGeneration::New,
|
||||
root,
|
||||
target_entropy_file );
|
||||
if ( !r )
|
||||
{
|
||||
return r;
|
||||
|
@ -102,9 +104,10 @@ MachineIdJob::exec()
|
|||
}
|
||||
if ( m_dbus )
|
||||
{
|
||||
auto r = MachineId::createDBusMachineId( m_dbus_symlink ? MachineId::DBusGeneration::SymlinkFromSystemD : MachineId::DBusGeneration::New,
|
||||
root,
|
||||
target_dbus_machineid_file );
|
||||
auto r = MachineId::createDBusMachineId( m_dbus_symlink ? MachineId::DBusGeneration::SymlinkFromSystemD
|
||||
: MachineId::DBusGeneration::New,
|
||||
root,
|
||||
target_dbus_machineid_file );
|
||||
if ( !r )
|
||||
{
|
||||
return r;
|
||||
|
|
99
src/modules/machineid/Tests.cpp
Normal file
99
src/modules/machineid/Tests.cpp
Normal file
|
@ -0,0 +1,99 @@
|
|||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||
*
|
||||
* Calamares is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Calamares is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Workers.h"
|
||||
|
||||
#include "utils/Logger.h"
|
||||
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
class MachineIdTests : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MachineIdTests() {}
|
||||
virtual ~MachineIdTests() {}
|
||||
|
||||
private Q_SLOTS:
|
||||
void initTestCase();
|
||||
|
||||
void testRemoveFile();
|
||||
void testCopyFile();
|
||||
|
||||
void testPoolSize();
|
||||
};
|
||||
|
||||
void
|
||||
MachineIdTests::initTestCase()
|
||||
{
|
||||
Logger::setupLogLevel( Logger::LOGDEBUG );
|
||||
}
|
||||
|
||||
void
|
||||
MachineIdTests::testCopyFile()
|
||||
{
|
||||
QTemporaryDir d( QDir::tempPath() + QStringLiteral( "/test-XXXXXX" ) );
|
||||
cDebug() << "Temporary files as" << QDir::tempPath();
|
||||
cDebug() << "Temp dir file at " << d.path();
|
||||
QVERIFY( !d.path().isEmpty() );
|
||||
|
||||
QFile source( d.filePath( "example" ) );
|
||||
QVERIFY( !source.exists() );
|
||||
source.open( QIODevice::WriteOnly );
|
||||
source.write( "Derp" );
|
||||
source.close();
|
||||
QCOMPARE( source.size(), 4 );
|
||||
QVERIFY( source.exists() );
|
||||
|
||||
// This should fail since "example" isn't standard in our test directory
|
||||
auto r0 = MachineId::copyFile( d.path(), "example" );
|
||||
QVERIFY( !r0 );
|
||||
|
||||
if ( QFile::exists( "CMakeCache.txt" ) )
|
||||
{
|
||||
auto r1 = MachineId::copyFile( d.path(), "CMakeCache.txt" );
|
||||
QVERIFY( r1 );
|
||||
QVERIFY( QFile::exists( d.filePath( "CMakeCache.txt" ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MachineIdTests::testRemoveFile()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
MachineIdTests::testPoolSize()
|
||||
{
|
||||
#ifdef Q_OS_FREEBSD
|
||||
// It hardly makes sense, but also the /proc entry is missing
|
||||
QCOMPARE( MachineId::getUrandomPoolSize(), 512 );
|
||||
#else
|
||||
// Based on a sample size of 1, Netrunner
|
||||
QCOMPARE( MachineId::getUrandomPoolSize(), 4096 );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
QTEST_GUILESS_MAIN( MachineIdTests )
|
||||
|
||||
#include "Tests.moc"
|
||||
#include "utils/moc-warnings.h"
|
|
@ -151,4 +151,4 @@ createDBusMachineId( DBusGeneration kind, const QString& rootMountPoint, const Q
|
|||
return Calamares::JobResult::internalError( QObject::tr( "Internal Error" ), QObject::tr( "Not implemented" ), 0 );
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace MachineId
|
||||
|
|
|
@ -58,7 +58,8 @@ int getUrandomPoolSize();
|
|||
Calamares::JobResult createNewEntropy( int poolSize, const QString& rootMountPoint, const QString& fileName );
|
||||
|
||||
/// @brief Create an entropy file @p fileName in the target system at @p rootMountPoint
|
||||
Calamares::JobResult createEntropy( const EntropyGeneration kind, const QString& rootMountPoint, const QString& fileName );
|
||||
Calamares::JobResult
|
||||
createEntropy( const EntropyGeneration kind, const QString& rootMountPoint, const QString& fileName );
|
||||
|
||||
|
||||
/** @brief MachineID functions
|
||||
|
@ -78,6 +79,6 @@ Calamares::JobResult createDBusMachineId( DBusGeneration kind, const QString& ro
|
|||
Calamares::JobResult createSystemdMachineId( const QString& rootMountPoint, const QString& fileName );
|
||||
|
||||
|
||||
}
|
||||
} // namespace MachineId
|
||||
|
||||
#endif // WORKERS_H
|
||||
|
|
Loading…
Add table
Reference in a new issue