From f07e31de29300289e0b445d3e78e69ffdd4e64f1 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 12 Nov 2023 22:28:27 +0100 Subject: [PATCH] [partition] Test for basic legacy configuration --- src/modules/partition/tests/1a-legacy.conf | 2 + src/modules/partition/tests/1b-legacy.conf | 2 + src/modules/partition/tests/ConfigTests.cpp | 47 ++++++++++++++++++--- 3 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 src/modules/partition/tests/1a-legacy.conf create mode 100644 src/modules/partition/tests/1b-legacy.conf diff --git a/src/modules/partition/tests/1a-legacy.conf b/src/modules/partition/tests/1a-legacy.conf new file mode 100644 index 000000000..f3435a262 --- /dev/null +++ b/src/modules/partition/tests/1a-legacy.conf @@ -0,0 +1,2 @@ +--- +efiSystemPartitionSize: 100MiB diff --git a/src/modules/partition/tests/1b-legacy.conf b/src/modules/partition/tests/1b-legacy.conf new file mode 100644 index 000000000..9792e8155 --- /dev/null +++ b/src/modules/partition/tests/1b-legacy.conf @@ -0,0 +1,2 @@ +--- +efiSystemPartitionSize: 100MB diff --git a/src/modules/partition/tests/ConfigTests.cpp b/src/modules/partition/tests/ConfigTests.cpp index 9ef30d720..4353d5f8f 100644 --- a/src/modules/partition/tests/ConfigTests.cpp +++ b/src/modules/partition/tests/ConfigTests.cpp @@ -9,12 +9,13 @@ #include "Config.h" +#include "core/PartUtils.h" + #include "GlobalStorage.h" #include "JobQueue.h" #include "utils/Logger.h" #include "utils/System.h" - -#include "core/PartUtils.h" +#include "utils/Yaml.h" #include #include @@ -31,6 +32,7 @@ public: private Q_SLOTS: void initTestCase(); void testEmptyConfig(); + void testLegacySize(); }; ConfigTests::ConfigTests() = default; @@ -38,7 +40,7 @@ ConfigTests::ConfigTests() = default; void ConfigTests::initTestCase() { - Logger::setupLogLevel( Logger::LOGDEBUG ); + Logger::setupLogLevel( Logger::LOGVERBOSE ); // Ensure we have a system object, expect it to be a "bogus" one Calamares::System* system = Calamares::System::instance(); @@ -60,8 +62,6 @@ ConfigTests::initTestCase() void ConfigTests::testEmptyConfig() { - Logger::setupLogLevel( Logger::LOGVERBOSE ); - Config c( nullptr ); c.setConfigurationMap( {} ); @@ -79,6 +79,43 @@ ConfigTests::testEmptyConfig() QCOMPARE( gs->value( "efiSystemPartition" ).toString(), "/boot/efi" ); // Default } +void +ConfigTests::testLegacySize() +{ + Config c( nullptr ); + + const auto* gs = Calamares::JobQueue::instanceGlobalStorage(); + QVERIFY( gs ); + + + // Config with just one legacy key + { + const auto file = QStringLiteral( BUILD_AS_TEST "/1a-legacy.conf" ); + bool ok = false; + c.setConfigurationMap( Calamares::YAML::load( file, &ok ) ); + + cDebug() << "Tried to load" << file << "success?" << ok; + + QVERIFY( ok ); + + QVERIFY( gs->value( PartUtils::efiFilesystemRecommendedSizeGSKey() ).isValid() ); // Something was filled in + QCOMPARE( PartUtils::efiFilesystemRecommendedSize(), 100_MiB ); // From config + QCOMPARE( PartUtils::efiFilesystemMinimumSize(), 100_MiB ); // Taken from config + } + + // Different legacy key value + { + bool ok = false; + c.setConfigurationMap( Calamares::YAML::load( QStringLiteral( BUILD_AS_TEST "/1b-legacy.conf" ), &ok ) ); + + QVERIFY( ok ); + + QCOMPARE( PartUtils::efiFilesystemRecommendedSize(), 100000000 ); // From config, MB + QCOMPARE( PartUtils::efiFilesystemMinimumSize(), 100000000 ); // Taken from config + } +} + + QTEST_GUILESS_MAIN( ConfigTests ) #include "utils/moc-warnings.h"