From: Marcin Siodelski Date: Tue, 12 Jul 2016 09:04:06 +0000 (+0200) Subject: [4489] Added unit test for read only mode in PgSQL backend. X-Git-Tag: trac4631_base~9^2~16 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4c07c122b28fdbfe3532c64ebf4b53b62c610936;p=thirdparty%2Fkea.git [4489] Added unit test for read only mode in PgSQL backend. --- diff --git a/src/lib/dhcpsrv/mysql_host_data_source.cc b/src/lib/dhcpsrv/mysql_host_data_source.cc index 70a9aa7a43..a45ef83567 100644 --- a/src/lib/dhcpsrv/mysql_host_data_source.cc +++ b/src/lib/dhcpsrv/mysql_host_data_source.cc @@ -1787,8 +1787,6 @@ public: /// @brief Indicates if the database is opened in read only mode. bool is_readonly_; -namespace { - }; @@ -1948,8 +1946,6 @@ TaggedStatementArray tagged_statements = { { " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 3)"}} }; -}; // end anonymouse namespace - MySqlHostDataSourceImpl:: MySqlHostDataSourceImpl(const MySqlConnection::ParameterMap& parameters) : host_exchange_(new MySqlHostWithOptionsExchange(MySqlHostWithOptionsExchange::DHCP4_ONLY)), diff --git a/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc b/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc index b58b60ee7a..2c4b13c005 100644 --- a/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc @@ -64,8 +64,13 @@ public: /// close the database. Then reopen it and delete everything created by /// the test. virtual ~PgSqlHostDataSourceTest() { - hdsptr_->rollback(); + try { + hdsptr_->rollback(); + } catch (...) { + // Rollback may fail if backend is in read only mode. That's ok. + } HostDataSourceFactory::destroy(); + hdsptr_.reset(); destroyPgSQLSchema(); } @@ -168,6 +173,12 @@ TEST(PgSqlHostDataSource, OpenDatabase) { destroyPgSQLSchema(); } + +// This test verifies that database backend can operate in Read-Only mode. +TEST_F(PgSqlHostDataSourceTest, testReadOnlyDatabase) { + testReadOnlyDatabase(PGSQL_VALID_TYPE); +} + // Test verifies if a host reservation can be added and later retrieved by IPv4 // address. Host uses hw address as identifier. TEST_F(PgSqlHostDataSourceTest, basic4HWAddr) {