From dfedc0fb21f93052b8d2ecb93ebd8285737011a5 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 14 Apr 2021 12:06:33 +0200 Subject: [PATCH] [netinstall] Extend tests - add an "empty" groups file - run an event loop to give the loader the opportunity to load --- src/modules/netinstall/Tests.cpp | 17 +++++++++++++---- .../netinstall/tests/1a-single-empty.conf | 7 +++++++ src/modules/netinstall/tests/data-empty.yaml | 6 ++++++ 3 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 src/modules/netinstall/tests/1a-single-empty.conf create mode 100644 src/modules/netinstall/tests/data-empty.yaml diff --git a/src/modules/netinstall/Tests.cpp b/src/modules/netinstall/Tests.cpp index b8826c6be..090355470 100644 --- a/src/modules/netinstall/Tests.cpp +++ b/src/modules/netinstall/Tests.cpp @@ -342,8 +342,9 @@ ItemTests::testUrlFallback_data() 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; + QTest::newRow( "bad" ) << "1a-single-bad.conf" << smash( S::FailedBadData ) << 0; + QTest::newRow( "empty" ) << "1a-single-empty.conf" << smash( S::FailedNoData ) << 0; + QTest::newRow( "second" ) << "1b-single-small.conf" << smash( S::Ok ) << 2; } void @@ -357,7 +358,8 @@ ItemTests::testUrlFallback() cDebug() << "Loading" << filename; // BUILD_AS_TEST is the source-directory path - QFile fi( QString( "%1/%2" ).arg( BUILD_AS_TEST, filename ) ); + QString testdir = QString( "%1/tests" ).arg( BUILD_AS_TEST ); + QFile fi( QString( "%1/%2" ).arg( testdir, filename ) ); QVERIFY( fi.exists() ); Config c; @@ -368,7 +370,7 @@ ItemTests::testUrlFallback() QString ba( yamlFile.readAll() ); QVERIFY( ba.length() > 0 ); QHash< QString, QString > replace; - replace.insert( "TESTDIR", BUILD_AS_TEST ); + replace.insert( "TESTDIR", testdir ); QString correctedDocument = KMacroExpander::expandMacros( ba, replace, '$' ); try @@ -391,6 +393,13 @@ ItemTests::testUrlFallback() // Each of the configs sets required to **true**, which is not the default QVERIFY( c.required() ); + + // Now give the loader time to complete + QEventLoop loop; + connect( &c, &Config::statusReady, &loop, &QEventLoop::quit ); + QTimer::singleShot( std::chrono::seconds(1), &loop, &QEventLoop::quit ); + loop.exec(); + QCOMPARE( smash( c.statusCode() ), status ); QCOMPARE( c.model()->rowCount(), count ); } diff --git a/src/modules/netinstall/tests/1a-single-empty.conf b/src/modules/netinstall/tests/1a-single-empty.conf new file mode 100644 index 000000000..2444a0435 --- /dev/null +++ b/src/modules/netinstall/tests/1a-single-empty.conf @@ -0,0 +1,7 @@ +# SPDX-FileCopyrightText: no +# SPDX-License-Identifier: CC0-1.0 +# +--- +required: true +groupsUrl: + - file://$TESTDIR/data-empty.yaml diff --git a/src/modules/netinstall/tests/data-empty.yaml b/src/modules/netinstall/tests/data-empty.yaml new file mode 100644 index 000000000..065a0a067 --- /dev/null +++ b/src/modules/netinstall/tests/data-empty.yaml @@ -0,0 +1,6 @@ +# SPDX-FileCopyrightText: no +# SPDX-License-Identifier: CC0-1.0 +# +--- +bogus: true +