From 8127ae704ca93a0fc2fb92106ea6bd456f993c17 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 2 Nov 2020 12:11:13 +0100 Subject: [PATCH] [users] Expand tests for groups a little --- src/modules/users/CMakeLists.txt | 6 ++++- src/modules/users/TestGroupInformation.cpp | 28 +++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/modules/users/CMakeLists.txt b/src/modules/users/CMakeLists.txt index f2cb011f4..8b8e87080 100644 --- a/src/modules/users/CMakeLists.txt +++ b/src/modules/users/CMakeLists.txt @@ -77,7 +77,11 @@ calamares_add_test( usersgroupstest SOURCES TestGroupInformation.cpp - MiscJobs.cpp + ${_users_src} # Build again with test-visibility + LIBRARIES + Qt5::DBus # HostName job can use DBus to systemd + ${CRYPT_LIBRARIES} # SetPassword job uses crypt() + ${USER_EXTRA_LIB} ) calamares_add_test( diff --git a/src/modules/users/TestGroupInformation.cpp b/src/modules/users/TestGroupInformation.cpp index 3b2046bda..5e8bcf9ab 100644 --- a/src/modules/users/TestGroupInformation.cpp +++ b/src/modules/users/TestGroupInformation.cpp @@ -7,11 +7,14 @@ * */ +#include "Config.h" #include "CreateUserJob.h" +#include "MiscJobs.h" #include "GlobalStorage.h" #include "JobQueue.h" #include "utils/Logger.h" +#include "utils/Yaml.h" #include #include @@ -30,6 +33,7 @@ private Q_SLOTS: void initTestCase(); void testReadGroup(); + void testCreateGroup(); }; GroupTests::GroupTests() {} @@ -43,12 +47,12 @@ GroupTests::initTestCase() { (void)new Calamares::JobQueue(); } + Calamares::JobQueue::instance()->globalStorage()->insert( "rootMountPoint", "/" ); } void GroupTests::testReadGroup() { - Calamares::JobQueue::instance()->globalStorage()->insert( "rootMountPoint", "/" ); // Get the groups in the host system QStringList groups = groupsInTargetSystem(); QVERIFY( groups.count() > 2 ); @@ -69,6 +73,28 @@ GroupTests::testReadGroup() } } +void GroupTests::testCreateGroup() +{ + Config g; + + // BUILD_AS_TEST is the source-directory path + QFile fi( QString( "%1/tests/5-issue-1523.conf" ).arg( BUILD_AS_TEST ) ); + QVERIFY( fi.exists() ); + + bool ok = false; + const auto map = CalamaresUtils::loadYaml( fi, &ok ); + QVERIFY( ok ); + QVERIFY( map.count() > 0 ); // Just that it loaded, one key *defaultGroups* + + Config c; + c.setConfigurationMap( map ); + + QCOMPARE( c.defaultGroups().count(), 4 ); + QVERIFY( c.defaultGroups().contains( QStringLiteral( "adm" ) ) ); +} + + + QTEST_GUILESS_MAIN( GroupTests ) #include "utils/moc-warnings.h"