diff --git a/src/modules/netinstall/CMakeLists.txt b/src/modules/netinstall/CMakeLists.txt index ec926c9d3..6b7270db1 100644 --- a/src/modules/netinstall/CMakeLists.txt +++ b/src/modules/netinstall/CMakeLists.txt @@ -26,6 +26,8 @@ calamares_add_test( netinstalltest SOURCES Tests.cpp + Config.cpp + LoaderQueue.cpp PackageTreeItem.cpp PackageModel.cpp LIBRARIES diff --git a/src/modules/netinstall/Tests.cpp b/src/modules/netinstall/Tests.cpp index 0b59658c1..b8826c6be 100644 --- a/src/modules/netinstall/Tests.cpp +++ b/src/modules/netinstall/Tests.cpp @@ -7,13 +7,17 @@ * */ +#include "Config.h" #include "PackageModel.h" #include "PackageTreeItem.h" #include "utils/Logger.h" +#include "utils/NamedEnum.h" #include "utils/Variant.h" #include "utils/Yaml.h" +#include + #include class ItemTests : public QObject @@ -40,6 +44,9 @@ private Q_SLOTS: void testCompare(); void testModel(); void testExampleFiles(); + + void testUrlFallback_data(); + void testUrlFallback(); }; ItemTests::ItemTests() {} @@ -326,6 +333,68 @@ ItemTests::testExampleFiles() } } +void +ItemTests::testUrlFallback_data() +{ + QTest::addColumn< QString >( "filename" ); + QTest::addColumn< int >( "status" ); + QTest::addColumn< int >( "count" ); + + using S = Config::Status; + + QTest::newRow( "first" ) << "tests/1a-single-bad.conf" << smash( S::FailedNoData ) << 0; + QTest::newRow( "second" ) << "tests/1b-single-small.conf" << smash( S::Ok ) << 2; +} + +void +ItemTests::testUrlFallback() +{ + Logger::setupLogLevel( Logger::LOGDEBUG ); + QFETCH( QString, filename ); + QFETCH( int, status ); + QFETCH( int, count ); + + cDebug() << "Loading" << filename; + + // BUILD_AS_TEST is the source-directory path + QFile fi( QString( "%1/%2" ).arg( BUILD_AS_TEST, filename ) ); + QVERIFY( fi.exists() ); + + Config c; + + QFile yamlFile( fi.fileName() ); + if ( yamlFile.exists() && yamlFile.open( QFile::ReadOnly | QFile::Text ) ) + { + QString ba( yamlFile.readAll() ); + QVERIFY( ba.length() > 0 ); + QHash< QString, QString > replace; + replace.insert( "TESTDIR", BUILD_AS_TEST ); + QString correctedDocument = KMacroExpander::expandMacros( ba, replace, '$' ); + + try + { + YAML::Node yamldoc = YAML::Load( correctedDocument.toUtf8() ); + auto map = CalamaresUtils::yamlToVariant( yamldoc ).toMap(); + QVERIFY( map.count() > 0 ); + c.setConfigurationMap( map ); + } + catch ( YAML::Exception& e ) + { + bool badYaml = true; + QVERIFY( !badYaml ); + } + } + else + { + QCOMPARE( QStringLiteral( "not found" ), fi.fileName() ); + } + + // Each of the configs sets required to **true**, which is not the default + QVERIFY( c.required() ); + QCOMPARE( smash( c.statusCode() ), status ); + QCOMPARE( c.model()->rowCount(), count ); +} + QTEST_GUILESS_MAIN( ItemTests ) diff --git a/src/modules/netinstall/tests/1a-single-bad.conf b/src/modules/netinstall/tests/1a-single-bad.conf new file mode 100644 index 000000000..c08d3870c --- /dev/null +++ b/src/modules/netinstall/tests/1a-single-bad.conf @@ -0,0 +1,7 @@ +# SPDX-FileCopyrightText: no +# SPDX-License-Identifier: CC0-1.0 +# +--- +required: true +groupsUrl: + - file://$TESTDIR/bad.yaml diff --git a/src/modules/netinstall/tests/1b-single-small.conf b/src/modules/netinstall/tests/1b-single-small.conf new file mode 100644 index 000000000..2de9b4db2 --- /dev/null +++ b/src/modules/netinstall/tests/1b-single-small.conf @@ -0,0 +1,7 @@ +# SPDX-FileCopyrightText: no +# SPDX-License-Identifier: CC0-1.0 +# +--- +required: true +groupsUrl: + - file://$TESTDIR/data-small.yaml diff --git a/src/modules/netinstall/tests/data-small.yaml b/src/modules/netinstall/tests/data-small.yaml new file mode 100644 index 000000000..8e92736b2 --- /dev/null +++ b/src/modules/netinstall/tests/data-small.yaml @@ -0,0 +1,12 @@ +# SPDX-FileCopyrightText: no +# SPDX-License-Identifier: CC0-1.0 +# +--- +- name: "Default" + description: "Default group" + hidden: true + selected: true + critical: false + packages: + - base + - chakra-live-skel