diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-06-13 01:43:09 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-06-13 01:43:09 +0100 |
commit | 24cc85beab49be38416c47e13e20c2461e863cbb (patch) | |
tree | 19d0bf4f536c90a47e02cf7b502a76cb27b8b0c2 /test/testdb-postgresql.cpp | |
parent | Add a concept to differentiate streams better (diff) | |
download | mygrate-24cc85beab49be38416c47e13e20c2461e863cbb.tar.bz2 mygrate-24cc85beab49be38416c47e13e20c2461e863cbb.tar.xz mygrate-24cc85beab49be38416c47e13e20c2461e863cbb.zip |
Create and drop PostgreSQL mock DBs as needed
Diffstat (limited to 'test/testdb-postgresql.cpp')
-rw-r--r-- | test/testdb-postgresql.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
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 <compileTimeFormatter.h> +#include <cstdlib> +#include <helpers.h> +#include <output/pq/pqConn.h> + +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()}; + } + } +} |