From f1446736f817a482ff26562aa968cb370a1e85b9 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 16 Mar 2021 14:37:13 +0100 Subject: [PATCH] [libcalamares] Expand tests a little - do some additions and check they work - drop the ";add" annotation on the source, this is not needed in the current situation with only adds available. --- src/libcalamares/packages/Globals.cpp | 2 +- src/libcalamares/packages/Tests.cpp | 33 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/libcalamares/packages/Globals.cpp b/src/libcalamares/packages/Globals.cpp index 6cd07bc4a..c5e882436 100644 --- a/src/libcalamares/packages/Globals.cpp +++ b/src/libcalamares/packages/Globals.cpp @@ -25,7 +25,7 @@ CalamaresUtils::Packages::setGSPackageAdditions( Calamares::GlobalStorage* gs, QVariantList packageOperations = gs->contains( PACKAGEOP ) ? gs->value( PACKAGEOP ).toList() : QVariantList(); cDebug() << "Existing package operations length" << packageOperations.length(); - const QString key = module.toString() + QStringLiteral( ";add" ); + const QString key = module.toString(); // Clear out existing operations for this module, going backwards: // Sometimes we remove an item, and we don't want the index to diff --git a/src/libcalamares/packages/Tests.cpp b/src/libcalamares/packages/Tests.cpp index aaff227a9..0a9be3a20 100644 --- a/src/libcalamares/packages/Tests.cpp +++ b/src/libcalamares/packages/Tests.cpp @@ -24,6 +24,7 @@ private Q_SLOTS: void initTestCase(); void testEmpty(); + void testAdd(); }; void @@ -47,6 +48,38 @@ PackagesTests::testEmpty() QVERIFY( !gs.contains( topKey ) ); } +void +PackagesTests::testAdd() +{ + Calamares::GlobalStorage gs; + const QString topKey( "packageOperations" ); + Calamares::ModuleSystem::InstanceKey k( "this", "that" ); + + 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 ); + cDebug() << op; + + QVERIFY( CalamaresUtils::Packages::setGSPackageAdditions( + &gs, k, QVariantList { QString( "vim" ), QString( "emacs" ) }, QVariantList() ) ); + QVERIFY( gs.contains( topKey ) ); + actionList = gs.value( topKey ).toList(); + QCOMPARE( actionList.length(), 1 ); + action = actionList[ 0 ].toMap(); + QVERIFY( action.contains( "install" ) ); + op = action[ "install" ].toList(); + QCOMPARE( op.length(), 2 ); + QCOMPARE( action[ "source" ].toString(), k.toString() ); + cDebug() << op; +} + QTEST_GUILESS_MAIN( PackagesTests )