[netinstall] Stub of tests for fallback-loading

main
Adriaan de Groot 4 years ago
parent 3c398bd15e
commit 5af37b0be3

@ -26,6 +26,8 @@ calamares_add_test(
netinstalltest
SOURCES
Tests.cpp
Config.cpp
LoaderQueue.cpp
PackageTreeItem.cpp
PackageModel.cpp
LIBRARIES

@ -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 <KMacroExpander>
#include <QtTest/QtTest>
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 )

@ -0,0 +1,7 @@
# SPDX-FileCopyrightText: no
# SPDX-License-Identifier: CC0-1.0
#
---
required: true
groupsUrl:
- file://$TESTDIR/bad.yaml

@ -0,0 +1,7 @@
# SPDX-FileCopyrightText: no
# SPDX-License-Identifier: CC0-1.0
#
---
required: true
groupsUrl:
- file://$TESTDIR/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
Loading…
Cancel
Save