Skip to content

Commit a82d40b

Browse files
committed
Add test options FBCPP_TEST_DIR and FBCPP_TEST_SERVER
1 parent ef35466 commit a82d40b

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

src/test/TestUtil.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <boost/test/unit_test.hpp>
2727

2828
#include "TestUtil.h"
29+
#include <cstdlib>
2930
#include <filesystem>
3031
#include <sstream>
3132
#include <string>
@@ -42,12 +43,25 @@ namespace fbcpp::test
4243
namespace
4344
{
4445
fs::path tempDir;
46+
bool removeTempDir = false;
47+
std::string testServerPrefix;
4548

4649
struct GlobalFixture
4750
{
4851
GlobalFixture()
4952
{
50-
fs::path prefix = fs::temp_directory_path();
53+
const char* testDirEnv = std::getenv("FBCPP_TEST_DIR");
54+
const char* testServerEnv = std::getenv("FBCPP_TEST_SERVER");
55+
if (testServerEnv && *testServerEnv)
56+
testServerPrefix = std::string(testServerEnv) + ":";
57+
58+
if (testDirEnv && *testDirEnv)
59+
{
60+
tempDir = testDirEnv;
61+
return;
62+
}
63+
64+
const fs::path prefix = fs::temp_directory_path();
5165

5266
auto now = std::chrono::system_clock::now();
5367
auto time = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
@@ -57,13 +71,17 @@ namespace fbcpp::test
5771

5872
tempDir = prefix / oss.str();
5973

60-
fs::create_directory(tempDir);
74+
if (fs::create_directory(tempDir))
75+
removeTempDir = true;
6176
}
6277

6378
~GlobalFixture()
6479
{
65-
std::error_code ec;
66-
fs::remove(tempDir, ec);
80+
if (removeTempDir)
81+
{
82+
std::error_code ec;
83+
fs::remove(tempDir, ec);
84+
}
6785

6886
CLIENT.shutdown();
6987
}
@@ -72,7 +90,7 @@ namespace fbcpp::test
7290

7391
std::string getTempFile(const std::string_view name)
7492
{
75-
return (tempDir / name).string();
93+
return testServerPrefix + (tempDir / name).string();
7694
}
7795
} // namespace fbcpp::test
7896

0 commit comments

Comments
 (0)