From b454d05acbedeff42a82c5e8bbb4f7dcf83a5173 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 1 Jan 2017 21:18:09 +0000 Subject: Force mock DB names to lower case --- libpqpp/pq-mock.cpp | 7 ++++--- libpqpp/unittests/testpq.cpp | 38 +++++++++++++++++++------------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/libpqpp/pq-mock.cpp b/libpqpp/pq-mock.cpp index f72c01f..2d081d1 100644 --- a/libpqpp/pq-mock.cpp +++ b/libpqpp/pq-mock.cpp @@ -4,6 +4,7 @@ #include #include #include +#include NAMEDFACTORY("postgresql", PQ::Mock, DB::MockDatabaseFactory); @@ -21,7 +22,7 @@ AdHocFormatter(MockConnStr, "user=postgres dbname=%?"); DB::Connection * Mock::openConnection() const { - return new Connection(MockConnStr::get(testDbName)); + return new Connection(MockConnStr::get(boost::algorithm::to_lower_copy(testDbName))); } AdHocFormatter(MockSetUnlogged, "ALTER TABLE %?.%? SET UNLOGGED"); @@ -29,7 +30,7 @@ void Mock::SetTablesToUnlogged() const { auto c = DB::ConnectionPtr(openConnection()); - auto s = c->select(R"SQL( + auto s = c->select(R"SQL( SELECT n.nspname, c.relname FROM pg_class c, pg_namespace n WHERE c.relkind = 'r' @@ -64,7 +65,7 @@ Mock::~Mock() void Mock::DropDatabase() const { - auto t = master->modify("SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = ?"); + auto t = master->modify("SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE LOWER(datname) = LOWER(?)"); t->bindParamS(0, testDbName); t->execute(); MockServerDatabase::DropDatabase(); diff --git a/libpqpp/unittests/testpq.cpp b/libpqpp/unittests/testpq.cpp index f5cb760..0d8720c 100644 --- a/libpqpp/unittests/testpq.cpp +++ b/libpqpp/unittests/testpq.cpp @@ -15,7 +15,7 @@ class StandardMockDatabase : public PQ::Mock { public: - StandardMockDatabase() : PQ::Mock("user=postgres dbname=postgres", "pqmock", { + StandardMockDatabase() : PQ::Mock("user=postgres dbname=postgres", "PQmock", { rootDir / "pqschema.sql" }) { } @@ -27,7 +27,7 @@ BOOST_FIXTURE_TEST_SUITE( Core, DB::TestCore ); BOOST_AUTO_TEST_CASE( transactions ) { - auto ro = DB::MockDatabase::openConnectionTo("pqmock"); + auto ro = DB::MockDatabase::openConnectionTo("PQmock"); BOOST_REQUIRE_EQUAL(false, ro->inTx()); ro->beginTx(); @@ -45,7 +45,7 @@ BOOST_AUTO_TEST_CASE( transactions ) BOOST_AUTO_TEST_CASE( bindAndSend ) { - auto rw = DB::MockDatabase::openConnectionTo("pqmock"); + auto rw = DB::MockDatabase::openConnectionTo("PQmock"); auto mod = rw->newModifyCommand("INSERT INTO test VALUES(?, ?, ?, ?, ?, ?)"); mod->bindParamI(0, testInt); @@ -86,7 +86,7 @@ BOOST_AUTO_TEST_CASE( bindAndSend ) BOOST_AUTO_TEST_CASE( bindAndSelect ) { - auto ro = DB::MockDatabase::openConnectionTo("pqmock"); + auto ro = DB::MockDatabase::openConnectionTo("PQmock"); auto select = ro->newSelectCommand("SELECT * FROM test WHERE id = ?"); select->bindParamI(0, testInt); @@ -108,7 +108,7 @@ BOOST_AUTO_TEST_CASE( bindAndSelect ) BOOST_AUTO_TEST_CASE( selectInTx ) { - auto db = DB::MockDatabase::openConnectionTo("pqmock"); + auto db = DB::MockDatabase::openConnectionTo("PQmock"); auto select = db->newSelectCommand("SELECT * FROM test"); while (select->fetch()) { } @@ -127,7 +127,7 @@ BOOST_AUTO_TEST_CASE( selectInTx ) BOOST_AUTO_TEST_CASE( bindAndSelectOther ) { - auto ro = DB::MockDatabase::openConnectionTo("pqmock"); + auto ro = DB::MockDatabase::openConnectionTo("PQmock"); auto select = ro->newSelectCommand("SELECT * FROM test WHERE id != ? AND id != ?"); select->bindParamI(0, testInt); @@ -150,7 +150,7 @@ BOOST_AUTO_TEST_CASE( bindAndSelectOther ) BOOST_AUTO_TEST_CASE( testP2MockScriptDir ) { - auto ro = DB::MockDatabase::openConnectionTo("pqmock"); + auto ro = DB::MockDatabase::openConnectionTo("PQmock"); auto select = ro->newSelectCommand("SELECT path FROM test2"); select->execute(); @@ -165,7 +165,7 @@ BOOST_AUTO_TEST_CASE( testP2MockScriptDir ) BOOST_AUTO_TEST_CASE( bulkload ) { - auto ro = DB::MockDatabase::openConnectionTo("pqmock"); + auto ro = DB::MockDatabase::openConnectionTo("PQmock"); auto count = ro->newSelectCommand("SELECT COUNT(*) FROM bulktest"); // Test empty @@ -189,7 +189,7 @@ BOOST_AUTO_TEST_CASE( bulkload ) BOOST_AUTO_TEST_CASE( nofetch ) { - auto ro = DB::MockDatabase::openConnectionTo("pqmock"); + auto ro = DB::MockDatabase::openConnectionTo("PQmock"); auto count = ro->newSelectCommand("SELECT * FROM bulktest"); count->execute(); delete count; @@ -198,7 +198,7 @@ BOOST_AUTO_TEST_CASE( nofetch ) BOOST_AUTO_TEST_CASE( bigIterate ) { - auto ro = DB::MockDatabase::openConnectionTo("pqmock"); + auto ro = DB::MockDatabase::openConnectionTo("PQmock"); auto count = ro->newSelectCommand("SELECT * FROM bulktest"); unsigned int rows = 0; @@ -213,7 +213,7 @@ BOOST_AUTO_TEST_CASE( bigIterate ) BOOST_AUTO_TEST_CASE( insertId ) { - auto ro = DB::MockDatabase::openConnectionTo("pqmock"); + auto ro = DB::MockDatabase::openConnectionTo("PQmock"); auto ins = ro->newModifyCommand("INSERT INTO idtest(foo) VALUES(1)"); for (int x = 1; x < 4; x++) { ins->execute(); @@ -225,8 +225,8 @@ BOOST_AUTO_TEST_CASE( insertId ) BOOST_AUTO_TEST_CASE( reconnect ) { - auto ro = DB::MockDatabase::openConnectionTo("pqmock"); - auto rok = DB::MockDatabase::openConnectionTo("pqmock"); + auto ro = DB::MockDatabase::openConnectionTo("PQmock"); + auto rok = DB::MockDatabase::openConnectionTo("PQmock"); auto pqconn = dynamic_cast(ro); int pid1 = PQbackendPID(pqconn->conn); BOOST_REQUIRE(pid1); @@ -246,8 +246,8 @@ BOOST_AUTO_TEST_CASE( reconnect ) BOOST_AUTO_TEST_CASE( reconnectInTx ) { - auto ro = DB::MockDatabase::openConnectionTo("pqmock"); - auto rok = DB::MockDatabase::openConnectionTo("pqmock"); + auto ro = DB::MockDatabase::openConnectionTo("PQmock"); + auto rok = DB::MockDatabase::openConnectionTo("PQmock"); auto pqconn = dynamic_cast(ro); int pid1 = PQbackendPID(pqconn->conn); BOOST_REQUIRE(pid1); @@ -265,7 +265,7 @@ BOOST_AUTO_TEST_CASE( reconnectInTx ) BOOST_AUTO_TEST_CASE( statementReuse ) { - auto ro = DB::MockDatabase::openConnectionTo("pqmock"); + auto ro = DB::MockDatabase::openConnectionTo("PQmock"); auto pqconn = dynamic_cast(ro); BOOST_REQUIRE_EQUAL(pqconn->preparedStatements.size(), 0); ro->modify("DELETE FROM test")->execute(); @@ -289,7 +289,7 @@ BOOST_AUTO_TEST_CASE( statementReuse ) BOOST_AUTO_TEST_CASE( bulkSelect ) { - auto ro = DB::MockDatabase::openConnectionTo("pqmock"); + auto ro = DB::MockDatabase::openConnectionTo("PQmock"); auto sel = ro->newSelectCommand("SELECT * FROM test WHERE id > ? --libdbpp:no-cursor"); sel->bindParamI(0, 1); int totalInt = 0, count = 0; @@ -305,7 +305,7 @@ BOOST_AUTO_TEST_CASE( bulkSelect ) BOOST_AUTO_TEST_CASE( insertReturning ) { - auto ro = DB::MockDatabase::openConnectionTo("pqmock"); + auto ro = DB::MockDatabase::openConnectionTo("PQmock"); auto sel = ro->newSelectCommand("INSERT INTO test(id, fl) VALUES(1, 3) RETURNING id + fl --libdbpp:no-cursor"); int totalInt = 0, count = 0; sel->forEachRow([&totalInt, &count](auto i) { @@ -320,7 +320,7 @@ BOOST_AUTO_TEST_CASE( insertReturning ) BOOST_AUTO_TEST_CASE( closeOnError ) { - auto ro = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("pqmock")); + auto ro = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("PQmock")); BOOST_REQUIRE_THROW({ ro->select("SELECT * FROM test")->forEachRow<>([&ro](){ ro->execute("nonsense"); -- cgit v1.2.3