Files
moloapp/tests/example/support/DoosHome.hpp
T

31 lines
916 B
C++
Raw Normal View History

#pragma once
// Scratch DOOS_HOME for the /doos route tests: a unique dir under the system
// temp root (the example suite points TMPDIR at build/example/tmp), exported
// before the Fixture builds the app, removed on teardown.
#include <unistd.h>
#include <cstdlib>
#include <filesystem>
namespace molo::example::test {
struct ScratchDoosHome {
std::filesystem::path dir;
explicit ScratchDoosHome(const std::string& tag) {
static int seq = 0;
dir = std::filesystem::temp_directory_path() /
("molo-doos-route-" + tag + "-" + std::to_string(::getpid()) + "-" +
std::to_string(seq++));
std::error_code ec;
std::filesystem::remove_all(dir, ec);
std::filesystem::create_directories(dir, ec);
::setenv("DOOS_HOME", dir.c_str(), 1);
}
~ScratchDoosHome() {
std::error_code ec;
std::filesystem::remove_all(dir, ec);
}
};
} // namespace molo::example::test