From f376b42c31e4befd9d87c55ac80130bfd165f492 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 26 Aug 2021 16:58:46 +0200 Subject: [PATCH] [welcome] Add a handful of tests for different URL configs --- src/modules/welcome/Tests.cpp | 37 +++++++++++++++++++ .../welcome/tests/1b-checkinternet.conf | 3 ++ .../welcome/tests/1c-checkinternet.conf | 4 ++ .../welcome/tests/1d-checkinternet.conf | 4 ++ .../welcome/tests/1e-checkinternet.conf | 4 ++ .../welcome/tests/1f-checkinternet.conf | 6 +++ .../welcome/tests/1g-checkinternet.conf | 3 ++ .../welcome/tests/1h-checkinternet.conf | 8 ++++ 8 files changed, 69 insertions(+) create mode 100644 src/modules/welcome/tests/1b-checkinternet.conf create mode 100644 src/modules/welcome/tests/1c-checkinternet.conf create mode 100644 src/modules/welcome/tests/1d-checkinternet.conf create mode 100644 src/modules/welcome/tests/1e-checkinternet.conf create mode 100644 src/modules/welcome/tests/1f-checkinternet.conf create mode 100644 src/modules/welcome/tests/1g-checkinternet.conf create mode 100644 src/modules/welcome/tests/1h-checkinternet.conf diff --git a/src/modules/welcome/Tests.cpp b/src/modules/welcome/Tests.cpp index cc2b7b873..0445433e9 100644 --- a/src/modules/welcome/Tests.cpp +++ b/src/modules/welcome/Tests.cpp @@ -29,6 +29,8 @@ private Q_SLOTS: void initTestCase(); void testOneUrl(); + void testUrls_data(); + void testUrls(); }; WelcomeTests::WelcomeTests() {} @@ -71,6 +73,41 @@ WelcomeTests::testOneUrl() QCOMPARE( CalamaresUtils::Network::Manager::instance().getCheckInternetUrls().count(), 1 ); } +void +WelcomeTests::testUrls_data() +{ + QTest::addColumn< QString >( "filename" ); + QTest::addColumn< int >( "result" ); + + QTest::newRow( "one " ) << QString( "1a-checkinternet.conf" ) << 1; + QTest::newRow( "none " ) << QString( "1b-checkinternet.conf" ) << 0; + QTest::newRow( "blank" ) << QString( "1c-checkinternet.conf" ) << 0; + QTest::newRow( "bogus" ) << QString( "1d-checkinternet.conf" ) << 0; + QTest::newRow( "[] " ) << QString( "1e-checkinternet.conf" ) << 0; + QTest::newRow( "-3 " ) << QString( "1f-checkinternet.conf" ) << 3; + QTest::newRow( "[3] " ) << QString( "1g-checkinternet.conf" ) << 3; + QTest::newRow( "some " ) << QString( "1h-checkinternet.conf" ) << 3; +} + +void +WelcomeTests::testUrls() +{ + QFETCH( QString, filename ); + QFETCH( int, result ); + + Config c; + + // BUILD_AS_TEST is the source-directory path + QFile fi( QString( "%1/tests/%2" ).arg( BUILD_AS_TEST, filename ) ); + QVERIFY( fi.exists() ); + + bool ok = false; + const auto map = CalamaresUtils::loadYaml( fi, &ok ); + QVERIFY( ok ); + + c.setConfigurationMap( map ); + QCOMPARE( CalamaresUtils::Network::Manager::instance().getCheckInternetUrls().count(), result ); +} QTEST_GUILESS_MAIN( WelcomeTests ) diff --git a/src/modules/welcome/tests/1b-checkinternet.conf b/src/modules/welcome/tests/1b-checkinternet.conf new file mode 100644 index 000000000..a1e656985 --- /dev/null +++ b/src/modules/welcome/tests/1b-checkinternet.conf @@ -0,0 +1,3 @@ +# Nothing at all +--- +bogus: 1 diff --git a/src/modules/welcome/tests/1c-checkinternet.conf b/src/modules/welcome/tests/1c-checkinternet.conf new file mode 100644 index 000000000..845e253c0 --- /dev/null +++ b/src/modules/welcome/tests/1c-checkinternet.conf @@ -0,0 +1,4 @@ +# Set to blank +--- +requirements: + internetCheckUrl: "" diff --git a/src/modules/welcome/tests/1d-checkinternet.conf b/src/modules/welcome/tests/1d-checkinternet.conf new file mode 100644 index 000000000..9a44d7c93 --- /dev/null +++ b/src/modules/welcome/tests/1d-checkinternet.conf @@ -0,0 +1,4 @@ +# Set to something broken +--- +requirements: + internetCheckUrl: false diff --git a/src/modules/welcome/tests/1e-checkinternet.conf b/src/modules/welcome/tests/1e-checkinternet.conf new file mode 100644 index 000000000..579414a79 --- /dev/null +++ b/src/modules/welcome/tests/1e-checkinternet.conf @@ -0,0 +1,4 @@ +# Empty list +--- +requirements: + internetCheckUrl: [] diff --git a/src/modules/welcome/tests/1f-checkinternet.conf b/src/modules/welcome/tests/1f-checkinternet.conf new file mode 100644 index 000000000..660760381 --- /dev/null +++ b/src/modules/welcome/tests/1f-checkinternet.conf @@ -0,0 +1,6 @@ +--- +requirements: + internetCheckUrl: + - http://example.com + - http://bogus.example.com + - http://nonexistent.example.com diff --git a/src/modules/welcome/tests/1g-checkinternet.conf b/src/modules/welcome/tests/1g-checkinternet.conf new file mode 100644 index 000000000..dd3ddae0c --- /dev/null +++ b/src/modules/welcome/tests/1g-checkinternet.conf @@ -0,0 +1,3 @@ +--- +requirements: + internetCheckUrl: [ http://example.com, http://bogus.example.com, http://nonexistent.example.com ] diff --git a/src/modules/welcome/tests/1h-checkinternet.conf b/src/modules/welcome/tests/1h-checkinternet.conf new file mode 100644 index 000000000..928360c20 --- /dev/null +++ b/src/modules/welcome/tests/1h-checkinternet.conf @@ -0,0 +1,8 @@ +# "0" is a valid URL (?) but "" is not +--- +requirements: + internetCheckUrl: + - http://example.com + - 0 + - "" + - http://nonexistent.example.com