add docker run
This commit is contained in:
parent
440e1c11ab
commit
9d9e7ece7a
@ -1,4 +1,5 @@
|
|||||||
create EXTENSIon IF NOT EXISTS ltree;
|
|
||||||
|
create EXTENSIon IF NOT EXISTS ltree;
|
||||||
|
|
||||||
create OR REPLACE function perm_to_numeric ( m_owner INT, m_group INT, m_other INT )
|
create OR REPLACE function perm_to_numeric ( m_owner INT, m_group INT, m_other INT )
|
||||||
RETURNS INT AS $$
|
RETURNS INT AS $$
|
||||||
|
|||||||
@ -6,6 +6,7 @@ set(SOURCE
|
|||||||
|
|
||||||
connection.cpp
|
connection.cpp
|
||||||
config.cpp
|
config.cpp
|
||||||
|
RawSql.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
file(GLOB MODEL
|
file(GLOB MODEL
|
||||||
|
|||||||
23
src/eedb/db/RawSql.cpp
Normal file
23
src/eedb/db/RawSql.cpp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#include <eedb/db/RawSql.hpp>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#include <eedb/db/connection.hpp>
|
||||||
|
#include <sqlpp11/sqlpp11.h>
|
||||||
|
|
||||||
|
#include <boost/algorithm/string/split.hpp>
|
||||||
|
#include <boost/algorithm/string/classification.hpp>
|
||||||
|
|
||||||
|
namespace eedb::db{
|
||||||
|
void exec_file(PgConnection & db, const std::experimental::filesystem::v1::__cxx11::path & filepath) {
|
||||||
|
std::ifstream stream(filepath);
|
||||||
|
std::string filebuf{std::istreambuf_iterator< char >(stream), std::istreambuf_iterator< char >()};
|
||||||
|
std::vector< std::string > lines;
|
||||||
|
boost::algorithm::split(lines, filebuf, boost::is_any_of(";"));
|
||||||
|
|
||||||
|
// for(const auto & line : lines) {
|
||||||
|
db.native()->execute(filebuf);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
} // namespace eedb::db
|
||||||
11
src/eedb/db/RawSql.hpp
Normal file
11
src/eedb/db/RawSql.hpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <experimental/filesystem>
|
||||||
|
|
||||||
|
namespace eedb::db{
|
||||||
|
|
||||||
|
class PgConnection;
|
||||||
|
|
||||||
|
void exec_file(PgConnection &db, const std::experimental::filesystem::path &filepath );
|
||||||
|
|
||||||
|
}
|
||||||
@ -20,7 +20,7 @@
|
|||||||
#include <Wt/WVBoxLayout.h>
|
#include <Wt/WVBoxLayout.h>
|
||||||
|
|
||||||
#include <eedb/Session.hpp>
|
#include <eedb/Session.hpp>
|
||||||
#include <eedb/data/CategoriesModel.hpp>
|
#include <eedb/widgets/models/CategoriesModel.hpp>
|
||||||
#include <eedb/widgets/NavigationBar.hpp>
|
#include <eedb/widgets/NavigationBar.hpp>
|
||||||
|
|
||||||
namespace eedb {
|
namespace eedb {
|
||||||
|
|||||||
@ -18,7 +18,7 @@ include_directories( ${gmock_SOURCE_DIR}/include)
|
|||||||
INCLUDE_DIRECTORIES(${PostgreSQL_INCLUDE_DIRS})
|
INCLUDE_DIRECTORIES(${PostgreSQL_INCLUDE_DIRS})
|
||||||
add_executable( ${TEST_EXECUTABLE_NAME} ${TEST_FILES} ${MOCK_FILES} )
|
add_executable( ${TEST_EXECUTABLE_NAME} ${TEST_FILES} ${MOCK_FILES} )
|
||||||
|
|
||||||
target_link_libraries( ${TEST_EXECUTABLE_NAME} GMock::main wt wttest eedb_db auth ${Boost_LIBRARIES} )
|
target_link_libraries( ${TEST_EXECUTABLE_NAME} GMock::main wt wttest eedb_db auth ${Boost_LIBRARIES} stdc++fs)
|
||||||
|
|
||||||
add_test( ${TEST_EXECUTABLE_NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TEST_EXECUTABLE_NAME})
|
add_test( ${TEST_EXECUTABLE_NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TEST_EXECUTABLE_NAME})
|
||||||
#endif()
|
#endif()
|
||||||
|
|||||||
@ -5,28 +5,79 @@
|
|||||||
#include <eedb/db/config.hpp>
|
#include <eedb/db/config.hpp>
|
||||||
#include <eedb/db/connection.hpp>
|
#include <eedb/db/connection.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
#include <Wt/Test/WTestEnvironment.h>
|
||||||
|
#include <Wt/WServer.h>
|
||||||
|
|
||||||
|
#include <eedb/db/RawSql.hpp>
|
||||||
|
#include <boost/process.hpp>
|
||||||
|
|
||||||
|
class DockerRunner {
|
||||||
|
public:
|
||||||
|
DockerRunner(std::string name) : _name{std::move(name)} {
|
||||||
|
try {
|
||||||
|
auto p = boost::process::search_path("docker");
|
||||||
|
// clang-format off
|
||||||
|
boost::process::system(p,
|
||||||
|
"run", "--detach", "--rm",
|
||||||
|
"--name", _name,
|
||||||
|
"-p", "5432:5432",
|
||||||
|
"-e", "POSTGRES_PASSWORD=postgres",
|
||||||
|
"-e", "POSTGRES_DB=eedb",
|
||||||
|
"postgres:9.5-alpine");
|
||||||
|
|
||||||
|
|
||||||
|
// clang-format on
|
||||||
|
} catch(boost::process::process_error e) {
|
||||||
|
std::cout << e.what() << "\n";
|
||||||
|
} catch(std::exception e) {
|
||||||
|
std::cout << e.what() << "n";
|
||||||
|
} catch(...) {
|
||||||
|
std::cout << "OCHUJ!\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
~DockerRunner() {
|
||||||
|
auto p = boost::process::search_path("docker");
|
||||||
|
boost::process::system(p, "stop", _name);
|
||||||
|
boost::process::system(p, "rm", "-v", _name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string _name;
|
||||||
|
};
|
||||||
|
|
||||||
class PgCategoryTest : public testing::Test {
|
class PgCategoryTest : public testing::Test {
|
||||||
public:
|
public:
|
||||||
static void SetUpTestCase() {
|
static void SetUpTestCase() {
|
||||||
|
Wt::Test::WTestEnvironment env;
|
||||||
|
|
||||||
|
auto dbConfig = std::make_unique< eedb::db::PgConfig >(env);
|
||||||
|
dbConfig->host = "localhost";
|
||||||
|
dbConfig->port = 5432;
|
||||||
|
dbConfig->password = "postgres";
|
||||||
|
dbConfig->user = "postgres";
|
||||||
|
dbConfig->dbname = "postgres";
|
||||||
|
dbConfig->debug = false;
|
||||||
|
|
||||||
|
// _docker = std::make_unique< DockerRunner >("postgres_test");
|
||||||
|
|
||||||
|
db = std::make_unique< eedb::db::PgConnection >(std::move(dbConfig));
|
||||||
|
eedb::db::exec_file(*db, "/home/bwieczor/src/eedb/sql/schema.sql");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 1. Create test database
|
* 1. Create test database
|
||||||
* 2. create config
|
* 2. create config [/]
|
||||||
* 3. Setup needed tables in database
|
* 3. Setup needed tables in database
|
||||||
* 4. Fill tables with data
|
* 4. Fill tables with data
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
PgCategoryTest() {
|
PgCategoryTest() {
|
||||||
/*
|
|
||||||
* 1. Start transaction
|
|
||||||
*/
|
|
||||||
db->native()->start_transaction();
|
db->native()->start_transaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
~PgCategoryTest() {
|
~PgCategoryTest() {
|
||||||
/*
|
|
||||||
* 1. Revert Transaction
|
|
||||||
*/
|
|
||||||
db->native()->rollback_transaction(false);
|
db->native()->rollback_transaction(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,13 +85,17 @@ class PgCategoryTest : public testing::Test {
|
|||||||
/*
|
/*
|
||||||
* 1. Remove everything
|
* 1. Remove everything
|
||||||
*/
|
*/
|
||||||
|
db.reset();
|
||||||
|
// _docker.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static std::shared_ptr< eedb::db::PgConfig > db_config;
|
static std::unique_ptr< eedb::db::PgConnection > db;
|
||||||
std::unique_ptr< eedb::db::PgConnection > db;
|
static std::unique_ptr< DockerRunner > _docker;
|
||||||
|
|
||||||
std::unique_ptr< eedb::PgCategory > sut;
|
std::unique_ptr< eedb::PgCategory > sut;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::unique_ptr< eedb::db::PgConnection > PgCategoryTest::db = {};
|
||||||
|
std::unique_ptr< DockerRunner > PgCategoryTest::_docker = {};
|
||||||
|
|
||||||
TEST_F(PgCategoryTest, rootCategoryHasNoParent) {}
|
TEST_F(PgCategoryTest, rootCategoryHasNoParent) {}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user