diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-06-13 02:42:26 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-06-13 02:42:26 +0100 |
commit | d8025ff93d66ec1ff7a6ffd90783e877e9eaafff (patch) | |
tree | 2ca815e4ffb42430acbe290858f859157356336e /test/testdb-postgresql.cpp | |
parent | Create and drop PostgreSQL mock DBs as needed (diff) | |
download | mygrate-d8025ff93d66ec1ff7a6ffd90783e877e9eaafff.tar.bz2 mygrate-d8025ff93d66ec1ff7a6ffd90783e877e9eaafff.tar.xz mygrate-d8025ff93d66ec1ff7a6ffd90783e877e9eaafff.zip |
Support creating a PostgreSQL mock DB and filling it with a schema script
Diffstat (limited to 'test/testdb-postgresql.cpp')
-rw-r--r-- | test/testdb-postgresql.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/test/testdb-postgresql.cpp b/test/testdb-postgresql.cpp index 55f163f..c59640a 100644 --- a/test/testdb-postgresql.cpp +++ b/test/testdb-postgresql.cpp @@ -1,6 +1,7 @@ #include "testdb-postgresql.h" #include <compileTimeFormatter.h> #include <cstdlib> +#include <fstream> #include <helpers.h> #include <output/pq/pqConn.h> @@ -15,6 +16,16 @@ namespace MyGrate { query(("CREATE DATABASE " + mockname).c_str()); } + PqConnDB::PqConnDB(const std::string & schemaFile) : PqConnDB() + { + auto mdb = mock(); + + std::stringstream buffer; + buffer << std::ifstream(schemaFile).rdbuf(); + + mdb.query(buffer.str().c_str()); + } + PqConnDB::~PqConnDB() { query(("DROP DATABASE IF EXISTS " + mockname).c_str()); |