mirror of
https://github.com/parchlinux/calamares.git
synced 2025-06-30 10:55:37 -04:00
[libcalamares] Test the packages service API
- check that the variant and the string-list version of the API do the same thing, check independence of settings for different instance keys.
This commit is contained in:
parent
e400f79673
commit
049b9f9c74
1 changed files with 171 additions and 22 deletions
|
@ -24,7 +24,15 @@ private Q_SLOTS:
|
||||||
void initTestCase();
|
void initTestCase();
|
||||||
|
|
||||||
void testEmpty();
|
void testEmpty();
|
||||||
|
void testAdd_data();
|
||||||
|
/** @brief Test various add calls, for a "clean" GS
|
||||||
|
*
|
||||||
|
* Check that adding through the variant- and the stringlist-API
|
||||||
|
* does the same thing.
|
||||||
|
*/
|
||||||
void testAdd();
|
void testAdd();
|
||||||
|
/// Test replacement and mixing string-list with variant calls
|
||||||
|
void testAddMixed();
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -46,38 +54,179 @@ PackagesTests::testEmpty()
|
||||||
// Adding nothing at all does nothing
|
// Adding nothing at all does nothing
|
||||||
QVERIFY( !CalamaresUtils::Packages::setGSPackageAdditions( &gs, k, QVariantList(), QVariantList() ) );
|
QVERIFY( !CalamaresUtils::Packages::setGSPackageAdditions( &gs, k, QVariantList(), QVariantList() ) );
|
||||||
QVERIFY( !gs.contains( topKey ) );
|
QVERIFY( !gs.contains( topKey ) );
|
||||||
|
|
||||||
|
QVERIFY( !CalamaresUtils::Packages::setGSPackageAdditions( &gs, k, QStringList() ) );
|
||||||
|
QVERIFY( !gs.contains( topKey ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PackagesTests::testAdd_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn< QStringList >( "packages" );
|
||||||
|
|
||||||
|
QTest::newRow( "one" ) << QStringList { QString( "vim" ) };
|
||||||
|
QTest::newRow( "two" ) << QStringList { QString( "vim" ), QString( "emacs" ) };
|
||||||
|
QTest::newRow( "one-again" ) << QStringList { QString( "nano" ) };
|
||||||
|
QTest::newRow( "six" ) << QStringList { QString( "vim" ), QString( "emacs" ), QString( "nano" ),
|
||||||
|
QString( "kate" ), QString( "gedit" ), QString( "sublime" ) };
|
||||||
|
// There is no "de-duplication" so this will insert "cim" twice
|
||||||
|
QTest::newRow( "dups" ) << QStringList { QString( "cim" ), QString( "vim" ), QString( "cim" ) };
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PackagesTests::testAdd()
|
PackagesTests::testAdd()
|
||||||
{
|
{
|
||||||
Calamares::GlobalStorage gs;
|
Calamares::GlobalStorage gs;
|
||||||
|
|
||||||
|
const QString extraEditor( "notepad++" );
|
||||||
const QString topKey( "packageOperations" );
|
const QString topKey( "packageOperations" );
|
||||||
Calamares::ModuleSystem::InstanceKey k( "this", "that" );
|
Calamares::ModuleSystem::InstanceKey k( "this", "that" );
|
||||||
|
Calamares::ModuleSystem::InstanceKey otherInstance( "this", "other" );
|
||||||
|
|
||||||
QVERIFY( !gs.contains( topKey ) );
|
QFETCH( QStringList, packages );
|
||||||
QVERIFY(
|
QVERIFY( !packages.contains( extraEditor ) );
|
||||||
CalamaresUtils::Packages::setGSPackageAdditions( &gs, k, QVariantList { QString( "vim" ) }, QVariantList() ) );
|
|
||||||
QVERIFY( gs.contains( topKey ) );
|
|
||||||
auto actionList = gs.value( topKey ).toList();
|
|
||||||
QCOMPARE( actionList.length(), 1 );
|
|
||||||
auto action = actionList[ 0 ].toMap();
|
|
||||||
QVERIFY( action.contains( "install" ) );
|
|
||||||
auto op = action[ "install" ].toList();
|
|
||||||
QCOMPARE( op.length(), 1 );
|
|
||||||
cDebug() << op;
|
|
||||||
|
|
||||||
QVERIFY( CalamaresUtils::Packages::setGSPackageAdditions(
|
{
|
||||||
&gs, k, QVariantList { QString( "vim" ), QString( "emacs" ) }, QVariantList() ) );
|
QVERIFY( !gs.contains( topKey ) );
|
||||||
QVERIFY( gs.contains( topKey ) );
|
QVERIFY(
|
||||||
actionList = gs.value( topKey ).toList();
|
CalamaresUtils::Packages::setGSPackageAdditions( &gs, k, QVariant( packages ).toList(), QVariantList() ) );
|
||||||
QCOMPARE( actionList.length(), 1 );
|
QVERIFY( gs.contains( topKey ) );
|
||||||
action = actionList[ 0 ].toMap();
|
auto actionList = gs.value( topKey ).toList();
|
||||||
QVERIFY( action.contains( "install" ) );
|
QCOMPARE( actionList.length(), 1 );
|
||||||
op = action[ "install" ].toList();
|
auto action = actionList[ 0 ].toMap();
|
||||||
QCOMPARE( op.length(), 2 );
|
QVERIFY( action.contains( "install" ) );
|
||||||
QCOMPARE( action[ "source" ].toString(), k.toString() );
|
auto op = action[ "install" ].toList();
|
||||||
cDebug() << op;
|
QCOMPARE( op.length(), packages.length() );
|
||||||
|
for ( const auto& s : qAsConst( packages ) )
|
||||||
|
{
|
||||||
|
QVERIFY( op.contains( s ) );
|
||||||
|
}
|
||||||
|
cDebug() << op;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
QVERIFY( CalamaresUtils::Packages::setGSPackageAdditions( &gs, otherInstance, packages ) );
|
||||||
|
QVERIFY( gs.contains( topKey ) );
|
||||||
|
auto actionList = gs.value( topKey ).toList();
|
||||||
|
QCOMPARE( actionList.length(), 2 ); // One for each instance key!
|
||||||
|
auto action = actionList[ 0 ].toMap();
|
||||||
|
auto secondaction = actionList[ 1 ].toMap();
|
||||||
|
auto op = action[ "install" ].toList();
|
||||||
|
auto secondop = secondaction[ "install" ].toList();
|
||||||
|
QCOMPARE( op, secondop );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Replace one and expect differences
|
||||||
|
packages << extraEditor;
|
||||||
|
QVERIFY( CalamaresUtils::Packages::setGSPackageAdditions( &gs, otherInstance, packages ) );
|
||||||
|
QVERIFY( gs.contains( topKey ) );
|
||||||
|
auto actionList = gs.value( topKey ).toList();
|
||||||
|
QCOMPARE( actionList.length(), 2 ); // One for each instance key!
|
||||||
|
for ( const auto& actionVariant : qAsConst( actionList ) )
|
||||||
|
{
|
||||||
|
auto action = actionVariant.toMap();
|
||||||
|
QVERIFY( action.contains( "install" ) );
|
||||||
|
QVERIFY( action.contains( "source" ) );
|
||||||
|
if ( action[ "source" ].toString() == otherInstance.toString() )
|
||||||
|
{
|
||||||
|
auto op = action[ "install" ].toList();
|
||||||
|
QCOMPARE( op.length(), packages.length() ); // changed from original length, though
|
||||||
|
for ( const auto& s : qAsConst( packages ) )
|
||||||
|
{
|
||||||
|
QVERIFY( op.contains( s ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// This is the "original" instance, so it's missing extraEditor
|
||||||
|
auto op = action[ "install" ].toList();
|
||||||
|
QCOMPARE( op.length(), packages.length()-1 ); // changed from original length
|
||||||
|
QVERIFY( !op.contains( extraEditor ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PackagesTests::testAddMixed()
|
||||||
|
{
|
||||||
|
Calamares::GlobalStorage gs;
|
||||||
|
|
||||||
|
const QString extraEditor( "notepad++" );
|
||||||
|
const QString topKey( "packageOperations" );
|
||||||
|
Calamares::ModuleSystem::InstanceKey k( "this", "that" );
|
||||||
|
Calamares::ModuleSystem::InstanceKey otherInstance( "this", "other" );
|
||||||
|
|
||||||
|
// Just one
|
||||||
|
{
|
||||||
|
QVERIFY( !gs.contains( topKey ) );
|
||||||
|
QVERIFY( CalamaresUtils::Packages::setGSPackageAdditions(
|
||||||
|
&gs, k, QVariantList { QString( "vim" ) }, QVariantList() ) );
|
||||||
|
QVERIFY( gs.contains( topKey ) );
|
||||||
|
auto actionList = gs.value( topKey ).toList();
|
||||||
|
QCOMPARE( actionList.length(), 1 );
|
||||||
|
auto action = actionList[ 0 ].toMap();
|
||||||
|
QVERIFY( action.contains( "install" ) );
|
||||||
|
auto op = action[ "install" ].toList();
|
||||||
|
QCOMPARE( op.length(), 1 );
|
||||||
|
QCOMPARE( op[ 0 ], QString( "vim" ) );
|
||||||
|
cDebug() << op;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace with two packages
|
||||||
|
{
|
||||||
|
QVERIFY( CalamaresUtils::Packages::setGSPackageAdditions(
|
||||||
|
&gs, k, QVariantList { QString( "vim" ), QString( "emacs" ) }, QVariantList() ) );
|
||||||
|
QVERIFY( gs.contains( topKey ) );
|
||||||
|
auto actionList = gs.value( topKey ).toList();
|
||||||
|
QCOMPARE( actionList.length(), 1 );
|
||||||
|
auto action = actionList[ 0 ].toMap();
|
||||||
|
QVERIFY( action.contains( "install" ) );
|
||||||
|
auto op = action[ "install" ].toList();
|
||||||
|
QCOMPARE( op.length(), 2 );
|
||||||
|
QCOMPARE( action[ "source" ].toString(), k.toString() );
|
||||||
|
QVERIFY( op.contains( QString( "vim" ) ) );
|
||||||
|
QVERIFY( op.contains( QString( "emacs" ) ) );
|
||||||
|
cDebug() << op;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace with one (different) package
|
||||||
|
{
|
||||||
|
QVERIFY( CalamaresUtils::Packages::setGSPackageAdditions(
|
||||||
|
&gs, k, QVariantList { QString( "nano" ) }, QVariantList() ) );
|
||||||
|
QVERIFY( gs.contains( topKey ) );
|
||||||
|
auto actionList = gs.value( topKey ).toList();
|
||||||
|
QCOMPARE( actionList.length(), 1 );
|
||||||
|
auto action = actionList[ 0 ].toMap();
|
||||||
|
QVERIFY( action.contains( "install" ) );
|
||||||
|
auto op = action[ "install" ].toList();
|
||||||
|
QCOMPARE( op.length(), 1 );
|
||||||
|
QCOMPARE( action[ "source" ].toString(), k.toString() );
|
||||||
|
QCOMPARE( op[ 0 ], QString( "nano" ) );
|
||||||
|
cDebug() << op;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now we have two sources
|
||||||
|
{
|
||||||
|
QVERIFY( CalamaresUtils::Packages::setGSPackageAdditions( &gs, otherInstance, QStringList( extraEditor ) ) );
|
||||||
|
QVERIFY( gs.contains( topKey ) );
|
||||||
|
auto actionList = gs.value( topKey ).toList();
|
||||||
|
QCOMPARE( actionList.length(), 2 );
|
||||||
|
|
||||||
|
for ( const auto& actionVariant : qAsConst( actionList ) )
|
||||||
|
{
|
||||||
|
auto action = actionVariant.toMap();
|
||||||
|
QVERIFY( action.contains( "install" ) );
|
||||||
|
QVERIFY( action.contains( "source" ) );
|
||||||
|
if ( action[ "source" ].toString() == otherInstance.toString() )
|
||||||
|
{
|
||||||
|
auto op = action[ "install" ].toList();
|
||||||
|
QCOMPARE( op.length(), 1 );
|
||||||
|
QVERIFY(
|
||||||
|
op.contains( action[ "source" ] == otherInstance.toString() ? extraEditor : QString( "nano" ) ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue