From 24cc85beab49be38416c47e13e20c2461e863cbb Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 13 Jun 2021 01:43:09 +0100 Subject: Create and drop PostgreSQL mock DBs as needed --- test/testdb-postgresql.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/testdb-postgresql.cpp (limited to 'test/testdb-postgresql.cpp') diff --git a/test/testdb-postgresql.cpp b/test/testdb-postgresql.cpp new file mode 100644 index 0000000..55f163f --- /dev/null +++ b/test/testdb-postgresql.cpp @@ -0,0 +1,30 @@ +#include "testdb-postgresql.h" +#include +#include +#include +#include + +namespace MyGrate { + namespace Testing { + const auto CONNSTR {MyGrate::getenv("MYGRATE_POSTGRESQL_CONNSTR", "user=postgres")}; + std::size_t PqConnDB::mocknum; + + PqConnDB::PqConnDB() : PqConn(CONNSTR), mockname {scprintf<"mygrate_test_%?_%?">(getpid(), mocknum++)} + { + query(("DROP DATABASE IF EXISTS " + mockname).c_str()); + query(("CREATE DATABASE " + mockname).c_str()); + } + + PqConnDB::~PqConnDB() + { + query(("DROP DATABASE IF EXISTS " + mockname).c_str()); + mockname.clear(); + } + + Output::Pq::PqConn + PqConnDB::mock() const + { + return PqConn {scprintf<"%? dbname=%?">(CONNSTR, mockname).c_str()}; + } + } +} -- cgit v1.2.3