[users] Test the moved setHostname Config

- document that the default for writeHostsFile is *true*
This commit is contained in:
Adriaan de Groot 2020-08-05 10:50:38 +02:00
parent 2efce1ac7a
commit fcafe5db8f
2 changed files with 37 additions and 0 deletions

View File

@ -25,6 +25,7 @@
// Implementation details // Implementation details
extern void setConfigurationDefaultGroups( const QVariantMap& map, QStringList& defaultGroups ); extern void setConfigurationDefaultGroups( const QVariantMap& map, QStringList& defaultGroups );
extern HostNameActions getHostNameActions( const QVariantMap& configurationMap );
/** @brief Test Config object methods and internals /** @brief Test Config object methods and internals
* *
@ -40,6 +41,8 @@ private Q_SLOTS:
void initTestCase(); void initTestCase();
void testDefaultGroups(); void testDefaultGroups();
void testHostActions_data();
void testHostActions();
}; };
UserTests::UserTests() {} UserTests::UserTests() {}
@ -105,6 +108,39 @@ UserTests::testDefaultGroups()
} }
} }
void
UserTests::testHostActions_data()
{
QTest::addColumn< bool >( "set" );
QTest::addColumn< QString >( "string" );
QTest::addColumn< int >( "result" );
QTest::newRow( "unset " ) << false << QString() << int( HostNameAction::EtcHostname );
QTest::newRow( "empty " ) << true << QString() << int( HostNameAction::EtcHostname );
QTest::newRow( "bad " ) << true << QString( "derp" ) << int( HostNameAction::EtcHostname );
QTest::newRow( "none " ) << true << QString( "none" ) << int( HostNameAction::None );
QTest::newRow( "systemd" ) << true << QString( "Hostnamed" ) << int( HostNameAction::SystemdHostname );
}
void
UserTests::testHostActions()
{
QFETCH( bool, set );
QFETCH( QString, string );
QFETCH( int, result );
QVariantMap m;
if ( set )
{
m.insert( "setHostname", string );
}
QCOMPARE( getHostNameActions( m ), HostNameActions( result ) | HostNameAction::WriteEtcHosts ); // write bits default to true
m.insert( "writeHostsFile", false );
QCOMPARE( getHostNameActions( m ), HostNameActions( result ) );
m.insert( "writeHostsFile", true );
QCOMPARE( getHostNameActions( m ), HostNameActions( result ) | HostNameAction::WriteEtcHosts );
}
QTEST_GUILESS_MAIN( UserTests ) QTEST_GUILESS_MAIN( UserTests )

View File

@ -138,4 +138,5 @@ setHostname: EtcFile
# Should /etc/hosts be written with a hostname for this machine # Should /etc/hosts be written with a hostname for this machine
# (also adds localhost and some ipv6 standard entries). # (also adds localhost and some ipv6 standard entries).
# Defaults to *true*.
writeHostsFile: true writeHostsFile: true