mirror of
https://github.com/parchlinux/calamares.git
synced 2025-02-24 19:05:46 -05:00
[libcalamares] Add tests for file-overwrite
This commit is contained in:
parent
f89951716e
commit
862b7e34df
1 changed files with 88 additions and 16 deletions
|
@ -49,6 +49,8 @@ private Q_SLOTS:
|
|||
void testCreationResult();
|
||||
void testTargetPath();
|
||||
void testCreateTarget();
|
||||
void testCreateTargetExists();
|
||||
void testCreateTargetOverwrite();
|
||||
void testCreateTargetBasedirs();
|
||||
|
||||
private:
|
||||
|
@ -96,7 +98,8 @@ TestPaths::init()
|
|||
m_gs->insert( "rootMountPoint", "/tmp" );
|
||||
}
|
||||
|
||||
void TestPaths::testCreationResult()
|
||||
void
|
||||
TestPaths::testCreationResult()
|
||||
{
|
||||
using Code = CalamaresUtils::CreationResult::Code;
|
||||
|
||||
|
@ -168,6 +171,75 @@ TestPaths::testCreateTarget()
|
|||
QVERIFY( !fi2.exists() );
|
||||
}
|
||||
|
||||
struct GSRollback
|
||||
{
|
||||
GSRollback( const QString& key )
|
||||
: m_key( key )
|
||||
, m_value( Calamares::JobQueue::instance()->globalStorage()->value( key ) )
|
||||
{
|
||||
}
|
||||
~GSRollback() { Calamares::JobQueue::instance()->globalStorage()->insert( m_key, m_value ); }
|
||||
QString m_key;
|
||||
QVariant m_value;
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
TestPaths::testCreateTargetExists()
|
||||
{
|
||||
static const char ltestFile[] = "cala-test-world";
|
||||
GSRollback g( QStringLiteral( "rootMountPoint" ) );
|
||||
|
||||
QTemporaryDir d;
|
||||
d.setAutoRemove( true );
|
||||
Calamares::JobQueue::instance()->globalStorage()->insert( QStringLiteral( "rootMountPoint" ), d.path() );
|
||||
|
||||
QVERIFY( QFileInfo( d.path() ).exists() );
|
||||
auto r = m_system->createTargetFile( ltestFile, "Hello" );
|
||||
QVERIFY( r );
|
||||
QVERIFY( r.path().endsWith( QString( ltestFile ) ) );
|
||||
QCOMPARE( QFileInfo( d.filePath( QString( ltestFile ) ) ).size(), 5 );
|
||||
|
||||
r = m_system->createTargetFile( ltestFile, "Goodbye" );
|
||||
QVERIFY( !r.failed() ); // It didn't fail!
|
||||
QVERIFY( !r ); // But not unqualified success, either
|
||||
|
||||
QVERIFY( r.path().isEmpty() );
|
||||
QCOMPARE( QFileInfo( d.filePath( QString( ltestFile ) ) ).size(), 5 ); // Unchanged!
|
||||
}
|
||||
|
||||
void
|
||||
TestPaths::testCreateTargetOverwrite()
|
||||
{
|
||||
static const char ltestFile[] = "cala-test-world";
|
||||
GSRollback g( QStringLiteral( "rootMountPoint" ) );
|
||||
|
||||
QTemporaryDir d;
|
||||
d.setAutoRemove( true );
|
||||
Calamares::JobQueue::instance()->globalStorage()->insert( QStringLiteral( "rootMountPoint" ), d.path() );
|
||||
|
||||
QVERIFY( QFileInfo( d.path() ).exists() );
|
||||
auto r = m_system->createTargetFile( ltestFile, "Hello" );
|
||||
QVERIFY( r );
|
||||
QVERIFY( r.path().endsWith( QString( ltestFile ) ) );
|
||||
QCOMPARE( QFileInfo( d.filePath( QString( ltestFile ) ) ).size(), 5 );
|
||||
|
||||
r = m_system->createTargetFile( ltestFile, "Goodbye", CalamaresUtils::System::WriteMode::KeepExisting );
|
||||
QVERIFY( !r.failed() ); // It didn't fail!
|
||||
QVERIFY( !r ); // But not unqualified success, either
|
||||
|
||||
QVERIFY( r.path().isEmpty() );
|
||||
QCOMPARE( QFileInfo( d.filePath( QString( ltestFile ) ) ).size(), 5 ); // Unchanged!
|
||||
|
||||
r = m_system->createTargetFile( ltestFile, "Goodbye", CalamaresUtils::System::WriteMode::Overwrite );
|
||||
QVERIFY( !r.failed() ); // It didn't fail!
|
||||
QVERIFY( r ); // Total success
|
||||
|
||||
QVERIFY( r.path().endsWith( QString( ltestFile ) ) );
|
||||
QCOMPARE( QFileInfo( d.filePath( QString( ltestFile ) ) ).size(), 7 );
|
||||
}
|
||||
|
||||
|
||||
struct DirRemover
|
||||
{
|
||||
DirRemover( const QString& base, const QString& dir )
|
||||
|
|
Loading…
Add table
Reference in a new issue