diff options
author | Petr Vaněk <arkamar@atlas.cz> | 2022-11-07 09:53:28 +0100 |
---|---|---|
committer | Petr Vaněk <arkamar@atlas.cz> | 2022-11-08 09:25:00 +0100 |
commit | 0d67e64287d9c9d4824e5d1b598831f5f8ebfd1a (patch) | |
tree | f133bde7b618bf239fcf5e527f19e412ec835ce8 /src | |
parent | 78936996d6669561a9ac8c750ec78486b6b8f91b (diff) | |
download | rspamd-0d67e64287d9c9d4824e5d1b598831f5f8ebfd1a.tar.gz rspamd-0d67e64287d9c9d4824e5d1b598831f5f8ebfd1a.zip |
[Test] use TMPDIR if available for mkstemp tests
Diffstat (limited to 'src')
-rw-r--r-- | src/libutil/cxx/file_util.cxx | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/libutil/cxx/file_util.cxx b/src/libutil/cxx/file_util.cxx index f457a4cd7..e3b3a2605 100644 --- a/src/libutil/cxx/file_util.cxx +++ b/src/libutil/cxx/file_util.cxx @@ -368,13 +368,22 @@ TEST_CASE("check lock") { CHECK(serrno == ENOENT); } +auto get_tmpdir() -> const char * { + const auto *tmpdir = getenv("TMPDIR"); + if (tmpdir == nullptr) { + tmpdir = G_DIR_SEPARATOR_S "tmp"; + } + return tmpdir; +} + TEST_CASE("tempfile") { std::string tmpname; + const std::string tmpdir{get_tmpdir()}; { - auto raii_locked_file = raii_locked_file::mkstemp("/tmp//doctest-XXXXXXXX", + auto raii_locked_file = raii_locked_file::mkstemp(std::string(tmpdir + G_DIR_SEPARATOR_S + "doctest-XXXXXXXX").c_str(), O_RDONLY, 00600); CHECK(raii_locked_file.has_value()); - CHECK(raii_locked_file.value().get_dir() == "/tmp"); + CHECK(raii_locked_file.value().get_dir() == tmpdir); CHECK(access(raii_locked_file.value().get_name().data(), R_OK) == 0); auto raii_locked_file2 = raii_locked_file::open(raii_locked_file.value().get_name().data(), O_RDONLY); CHECK(!raii_locked_file2.has_value()); @@ -390,11 +399,12 @@ TEST_CASE("tempfile") { TEST_CASE("mmap") { std::string tmpname; + const std::string tmpdir{get_tmpdir()}; { - auto raii_file = raii_file::mkstemp("/tmp//doctest-XXXXXXXX", + auto raii_file = raii_file::mkstemp(std::string(tmpdir + G_DIR_SEPARATOR_S + "doctest-XXXXXXXX").c_str(), O_RDWR|O_CREAT|O_EXCL, 00600); CHECK(raii_file.has_value()); - CHECK(raii_file->get_dir() == "/tmp"); + CHECK(raii_file->get_dir() == tmpdir); CHECK(access(raii_file->get_name().data(), R_OK) == 0); tmpname = std::string{raii_file->get_name()}; char payload[] = {'1', '2', '3'}; |