From dcf0c906a22e7f23495ee8fe5c30c2d1870f7639 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 4 Jan 2016 19:46:34 +0000 Subject: Take an extra argument to mock to allow for specifying which driver to use, etc. Move all the PostgreSQL specific bits into the unit test itself. Reference the driver library by filename thus not requiring configuration for the test to run. --- libodbcpp/odbc-mock.cpp | 8 ++++---- libodbcpp/odbc-mock.h | 4 +++- libodbcpp/unittests/testodbc.cpp | 8 +++++++- 3 files changed, 14 insertions(+), 6 deletions(-) (limited to 'libodbcpp') diff --git a/libodbcpp/odbc-mock.cpp b/libodbcpp/odbc-mock.cpp index 71c4c56..2799fb3 100644 --- a/libodbcpp/odbc-mock.cpp +++ b/libodbcpp/odbc-mock.cpp @@ -4,8 +4,9 @@ namespace ODBC { -Mock::Mock(const std::string & masterdb, const std::string & name, const std::vector & ss) : - MockServerDatabase(masterdb, name, "odbc") +Mock::Mock(const std::string & b, const std::string & masterdb, const std::string & name, const std::vector & ss) : + MockServerDatabase(b + ";" + masterdb, name, "odbc"), + base(b) { CreateNewDatabase(); PlaySchemaScripts(ss); @@ -14,7 +15,7 @@ Mock::Mock(const std::string & masterdb, const std::string & name, const std::ve DB::Connection * Mock::openConnection() const { - return new Connection(stringbf("Driver=postgresql;Database=%s;uid=postgres;servername=/run/postgresql", testDbName)); + return new Connection(stringbf("%s;Database=%s", base, testDbName)); } Mock::~Mock() @@ -24,7 +25,6 @@ Mock::~Mock() void Mock::DropDatabase() const { - master->execute("SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '" + testDbName + "'"); MockServerDatabase::DropDatabase(); } diff --git a/libodbcpp/odbc-mock.h b/libodbcpp/odbc-mock.h index d2bcbfe..f66d09d 100644 --- a/libodbcpp/odbc-mock.h +++ b/libodbcpp/odbc-mock.h @@ -9,9 +9,11 @@ namespace ODBC { class DLL_PUBLIC Mock : public DB::MockServerDatabase { public: - Mock(const std::string & master, const std::string & name, const std::vector & ss); + Mock(const std::string & base, const std::string & master, const std::string & name, const std::vector & ss); ~Mock(); + const std::string base; + protected: void DropDatabase() const override; diff --git a/libodbcpp/unittests/testodbc.cpp b/libodbcpp/unittests/testodbc.cpp index f288bf8..77f0a71 100644 --- a/libodbcpp/unittests/testodbc.cpp +++ b/libodbcpp/unittests/testodbc.cpp @@ -13,10 +13,16 @@ class StandardMockDatabase : public ODBC::Mock { public: - StandardMockDatabase() : ODBC::Mock("Driver=postgresql;Database=postgres;uid=postgres;servername=/run/postgresql", "odbcmock", { + StandardMockDatabase() : ODBC::Mock("Driver=psqlodbcw.so;uid=postgres;servername=/run/postgresql", "Database=postgres", "odbcmock", { rootDir / "odbcschema.sql" }) { } + + void DropDatabase() const override + { + master->execute("SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '" + testDbName + "'"); + ODBC::Mock::DropDatabase(); + } }; BOOST_GLOBAL_FIXTURE( StandardMockDatabase ); -- cgit v1.2.3