diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-01-01 16:24:00 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-01-01 16:24:00 +0000 |
commit | 5696a849dbeb4ab4df461980c295d93cfae31585 (patch) | |
tree | fd496d14887657de2183a79b87d121b2769fb8b3 | |
parent | Correctly name mock databases (diff) | |
download | libdbpp-5696a849dbeb4ab4df461980c295d93cfae31585.tar.bz2 libdbpp-5696a849dbeb4ab4df461980c295d93cfae31585.tar.xz libdbpp-5696a849dbeb4ab4df461980c295d93cfae31585.zip |
Add utility for creating a temporary mock database via the command line
-rw-r--r-- | libdbpp/Jamfile.jam | 16 | ||||
-rw-r--r-- | libdbpp/createMockDb.cpp | 59 |
2 files changed, 72 insertions, 3 deletions
diff --git a/libdbpp/Jamfile.jam b/libdbpp/Jamfile.jam index cf116c5..9e7ad28 100644 --- a/libdbpp/Jamfile.jam +++ b/libdbpp/Jamfile.jam @@ -9,11 +9,12 @@ lib boost_date_time : : <name>boost_date_time ; lib boost_filesystem ; lib boost_system ; lib boost_thread ; +lib boost_program_options ; lib adhocutil : : : : <include>/usr/include/adhocutil ; lib boost_utf : : <name>boost_unit_test_framework ; lib dbppcore : - [ glob *.cpp *.ll : test*.cpp ] : + [ glob *.cpp *.ll : test*.cpp createMockDb.cpp ] : <library>glibmm <library>adhocutil <library>boost_system @@ -29,7 +30,7 @@ lib dbppcore : ; lib dbpptestcore : - [ glob test*.cpp ] + [ glob testCore*.cpp ] : <define>BOOST_TEST_DYN_LINK <library>dbppcore @@ -38,8 +39,17 @@ lib dbpptestcore : <include>. ; +exe createmockdb : + createMockDb.cpp + : : + <library>dbppcore + <library>boost_filesystem + <library>boost_system + <library>boost_program_options + ; + build-project unittests ; -package.install install : <install-source-root>. : : dbppcore : [ glob *.h : test*.h ] ; +package.install install : <install-source-root>. : createmockdb : dbppcore : [ glob *.h : test*.h ] ; package.install installtest : <install-source-root>. : : dbpptestcore : [ glob test*.h ] ; diff --git a/libdbpp/createMockDb.cpp b/libdbpp/createMockDb.cpp new file mode 100644 index 0000000..960f848 --- /dev/null +++ b/libdbpp/createMockDb.cpp @@ -0,0 +1,59 @@ +#include <iostream> +#include <boost/program_options.hpp> +#include <boost/filesystem/path.hpp> +#include <boost/filesystem/convenience.hpp> +#include <signal.h> +#include "mockDatabase.h" + +namespace po = boost::program_options; +namespace fs = boost::filesystem; + +void emptyHandler(int) { } + +int +main(int argc, char ** argv) +{ + po::options_description opts("LibDB++ Create Mock Database Options"); + std::vector<fs::path> scripts; + std::string connector, master, database; + bool drop; + + opts.add_options() + ("help,h", "Show this help message") + ("drop,X", po::bool_switch(&drop)->default_value(false), "Drop immediately after creation (don't wait for signal)") + ("script", po::value(&scripts)->required(), "Setup script path") + ("connector,c", po::value(&connector)->required(), "Database connector (e.g. postgresql, mysql, sqlite)") + ("master,m", po::value(&master), "Master connection string") + ("database,d", po::value(&database)->default_value("mock"), "Database name prefix to use") + ; + + po::positional_options_description p; + p.add("script", -1); + + po::variables_map vm; + po::store(po::command_line_parser(argc, argv).options(opts).positional(p).run(), vm); + + if (vm.count("help")) { + std::cout << opts << std::endl; + return 1; + } + po::notify(vm); + + std::cout << "Creating database..."; + auto mock = DB::MockDatabaseFactory::createNew(connector, master, database, scripts); + std::cout << " done." << std::endl; + + if (!drop) { + std::cout << "Done. ctrl+c to tear down and exit." << std::endl; + sigset(SIGINT, &emptyHandler); + pause(); + + std::cout << std::endl; + } + + std::cout << "Tearing down database..." << std::endl; + delete mock; + std::cout << " done." << std::endl; + return 0; +} + |