mirror of
https://github.com/ohwgiles/laminar.git
synced 2024-10-27 20:34:20 +00:00
tests: reinstantiate laminar for each unit
reinstantiate Laminar and Server classes and clean the temporary LAMINAR_HOME directory for each unit test via SetUp and TearDown.
This commit is contained in:
parent
efafda16ff
commit
4a6f99a203
@ -1,5 +1,5 @@
|
|||||||
///
|
///
|
||||||
/// Copyright 2019-2020 Oliver Giles
|
/// Copyright 2019-2022 Oliver Giles
|
||||||
///
|
///
|
||||||
/// This file is part of Laminar
|
/// This file is part of Laminar
|
||||||
///
|
///
|
||||||
@ -33,20 +33,26 @@
|
|||||||
class LaminarFixture : public ::testing::Test {
|
class LaminarFixture : public ::testing::Test {
|
||||||
public:
|
public:
|
||||||
LaminarFixture() {
|
LaminarFixture() {
|
||||||
bind_rpc = std::string("unix:/") + tmp.path.toString(true).cStr() + "/rpc.sock";
|
|
||||||
bind_http = std::string("unix:/") + tmp.path.toString(true).cStr() + "/http.sock";
|
|
||||||
home = tmp.path.toString(true).cStr();
|
home = tmp.path.toString(true).cStr();
|
||||||
tmp.fs->openSubdir(kj::Path{"cfg", "jobs"}, kj::WriteMode::CREATE | kj::WriteMode::CREATE_PARENT);
|
bind_rpc = std::string("unix:/") + home + "/rpc.sock";
|
||||||
|
bind_http = std::string("unix:/") + home + "/http.sock";
|
||||||
settings.home = home.c_str();
|
settings.home = home.c_str();
|
||||||
settings.bind_rpc = bind_rpc.c_str();
|
settings.bind_rpc = bind_rpc.c_str();
|
||||||
settings.bind_http = bind_http.c_str();
|
settings.bind_http = bind_http.c_str();
|
||||||
settings.archive_url = "/test-archive/";
|
settings.archive_url = "/test-archive/";
|
||||||
|
}
|
||||||
|
~LaminarFixture() noexcept(true) {}
|
||||||
|
|
||||||
|
void SetUp() override {
|
||||||
|
tmp.init();
|
||||||
server = new Server(*ioContext);
|
server = new Server(*ioContext);
|
||||||
laminar = new Laminar(*server, settings);
|
laminar = new Laminar(*server, settings);
|
||||||
}
|
}
|
||||||
~LaminarFixture() noexcept(true) {
|
|
||||||
|
void TearDown() override {
|
||||||
delete server;
|
delete server;
|
||||||
delete laminar;
|
delete laminar;
|
||||||
|
tmp.clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
kj::Own<EventSource> eventSource(const char* path) {
|
kj::Own<EventSource> eventSource(const char* path) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
///
|
///
|
||||||
/// Copyright 2018-2020 Oliver Giles
|
/// Copyright 2018-2022 Oliver Giles
|
||||||
///
|
///
|
||||||
/// This file is part of Laminar
|
/// This file is part of Laminar
|
||||||
///
|
///
|
||||||
@ -28,12 +28,24 @@ class TempDir {
|
|||||||
public:
|
public:
|
||||||
TempDir() :
|
TempDir() :
|
||||||
path(mkdtemp()),
|
path(mkdtemp()),
|
||||||
fs(kj::newDiskFilesystem()->getRoot().openSubdir(path, kj::WriteMode::CREATE|kj::WriteMode::MODIFY))
|
fs(kj::newDiskFilesystem()->getRoot().openSubdir(path, kj::WriteMode::MODIFY))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
~TempDir() noexcept {
|
~TempDir() noexcept {
|
||||||
kj::newDiskFilesystem()->getRoot().remove(path);
|
kj::newDiskFilesystem()->getRoot().remove(path);
|
||||||
}
|
}
|
||||||
|
void init() {
|
||||||
|
// set up empty directory structure
|
||||||
|
fs->openSubdir(kj::Path{"cfg"}, kj::WriteMode::CREATE);
|
||||||
|
fs->openSubdir(kj::Path{"cfg", "jobs"}, kj::WriteMode::CREATE);
|
||||||
|
}
|
||||||
|
void clean() {
|
||||||
|
// rm -rf in config folder
|
||||||
|
for(kj::StringPtr name : fs->listNames()) {
|
||||||
|
fs->remove(kj::Path{name});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
kj::Path path;
|
kj::Path path;
|
||||||
kj::Own<const kj::Directory> fs;
|
kj::Own<const kj::Directory> fs;
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user