test speadup
This commit is contained in:
parent
44833e2096
commit
0d351b4daa
@ -6,18 +6,14 @@
|
||||
#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);
|
||||
// }
|
||||
db.native()->execute("SET client_min_messages=WARNING;");
|
||||
db.native()->execute(filebuf);
|
||||
|
||||
std::cerr.clear();
|
||||
}
|
||||
} // namespace eedb::db
|
||||
|
||||
@ -53,7 +53,7 @@ class PgAuthTokensTest : public DbTestBase< PgAuthTokensTest > {
|
||||
.front()
|
||||
.id;
|
||||
|
||||
ON_CALL(user, uid()).WillByDefault(testing::Return(authInfoId));
|
||||
EXPECT_CALL(user, uid()).WillRepeatedly(testing::Return(authInfoId));
|
||||
sut = std::make_unique< eedb::PgAuthTokens >(db(), &user);
|
||||
}
|
||||
|
||||
|
||||
42
tests/unit/db/test_eedb_data_PgUser.cpp
Normal file
42
tests/unit/db/test_eedb_data_PgUser.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include <eedb/db/data/PgUser.hpp>
|
||||
|
||||
#include <eedb/data/AuthIdentity.hpp>
|
||||
#include <eedb/data/AuthInfo.hpp>
|
||||
|
||||
#include <eedb/db/model/auth_identity.h>
|
||||
#include <eedb/db/model/auth_info.h>
|
||||
#include <eedb/db/model/auth_token.h>
|
||||
#include <eedb/db/model/user_action.h>
|
||||
#include <eedb/db/model/user_audit.h>
|
||||
#include <sqlpp11/sqlpp11.h>
|
||||
|
||||
#include <utils/DbTestBase.hpp>
|
||||
|
||||
constexpr eedb::user_audit t_user_audit;
|
||||
constexpr eedb::user_action t_user_action;
|
||||
constexpr eedb::auth_identity t_auth_identity;
|
||||
constexpr eedb::auth_info t_auth_info;
|
||||
constexpr eedb::auth_token t_auth_token;
|
||||
|
||||
class PgUserTest : public DbTestBase< PgUserTest > {
|
||||
public:
|
||||
PgUserTest() {
|
||||
db().native()->start_transaction();
|
||||
}
|
||||
|
||||
~PgUserTest() {
|
||||
db().native()->rollback_transaction(false);
|
||||
}
|
||||
|
||||
protected:
|
||||
std::unique_ptr< eedb::PgUser > sut;
|
||||
};
|
||||
|
||||
template <>
|
||||
std::unique_ptr< PgTestDatabasePrepare > DbTestBase< PgUserTest >::_test_db = {};
|
||||
|
||||
using namespace sqlpp;
|
||||
|
||||
TEST_F(PgUserTest, initial) {
|
||||
|
||||
}
|
||||
@ -6,30 +6,59 @@
|
||||
#include <sqlpp11/postgresql/exception.h>
|
||||
|
||||
#include <boost/process.hpp>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <thread>
|
||||
|
||||
class DockerRunner {
|
||||
enum class Status { Running, Exited, Missing };
|
||||
|
||||
public:
|
||||
DockerRunner(std::string name) : _name{std::move(name)} {
|
||||
using namespace boost::process;
|
||||
auto p = search_path("docker");
|
||||
// clang-format off
|
||||
system(p,
|
||||
"run", "--detach",
|
||||
"--name", _name,
|
||||
"-p", "5432:5432",
|
||||
"-e", "POSTGRES_PASSWORD=postgres",
|
||||
"-e", "POSTGRES_DB=eedb",
|
||||
"postgres:9.5-alpine");
|
||||
// clang-format on
|
||||
|
||||
auto getStatus = [this]() {
|
||||
ipstream is; // reading pipe-stream
|
||||
auto status = system(search_path("docker"), "inspect", _name, std_out > is);
|
||||
|
||||
if(!status) {
|
||||
std::string statusBuf, line;
|
||||
statusBuf.reserve(10240);
|
||||
|
||||
while(std::getline(is, line) && !line.empty())
|
||||
statusBuf.append(line);
|
||||
|
||||
auto status = nlohmann::json::parse(std::move(statusBuf))[0]["State"]["Status"];
|
||||
|
||||
if(status == "running") {
|
||||
return Status::Running;
|
||||
} else if(status == "exited") {
|
||||
return Status::Exited;
|
||||
}
|
||||
}
|
||||
return Status::Missing;
|
||||
};
|
||||
|
||||
auto status = getStatus();
|
||||
if(status == Status::Exited) {
|
||||
system(search_path("docker"), "start", _name);
|
||||
} else if(status == Status::Missing) {
|
||||
system(search_path("docker"),
|
||||
"run --detach",
|
||||
"--name",
|
||||
_name,
|
||||
"-p 5432:5432",
|
||||
"-e POSTGRES_PASSWORD=postgres",
|
||||
"-e POSTGRES_DB=eedb",
|
||||
"postgres:9.5-alpine");
|
||||
}
|
||||
}
|
||||
|
||||
~DockerRunner() {
|
||||
using namespace boost::process;
|
||||
auto p = search_path("docker");
|
||||
system(p, "stop", _name);
|
||||
system(p, "rm", "-v", _name);
|
||||
// using namespace boost::process;
|
||||
// auto p = search_path("docker");
|
||||
// system(p, "stop", _name);
|
||||
// system(p, "rm", "-v", _name);
|
||||
}
|
||||
|
||||
private:
|
||||
@ -75,12 +104,11 @@ class PgTestDatabasePrepare {
|
||||
std::unique_ptr< eedb::db::PgConnection > _db;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
template < typename T >
|
||||
class DbTestBase : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase() {
|
||||
_test_db = std::make_unique< PgTestDatabasePrepare >();
|
||||
|
||||
eedb::db::exec_file(_test_db->db(), "/home/bwieczor/src/eedb/sql/schema.sql");
|
||||
}
|
||||
|
||||
@ -88,7 +116,7 @@ class DbTestBase : public testing::Test {
|
||||
_test_db.reset();
|
||||
}
|
||||
|
||||
eedb::db::PgConnection & db(){
|
||||
eedb::db::PgConnection & db() {
|
||||
return _test_db->db();
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user