summaryrefslogtreecommitdiff
path: root/test/http/file_test_utilities.hpp
blob: 073a0747a430060f3b1bdd0d2f051900a145a562 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#pragma once
#include <filesystem>
#include <string>
#include <string_view>

#include <gtest/gtest.h>

inline std::string makeFile(std::string_view sampleData)
{
    std::filesystem::path path = std::filesystem::temp_directory_path();
    path /= "bmcweb_http_response_test_XXXXXXXXXXX";
    std::string stringPath = path.string();
    int fd = mkstemp(stringPath.data());
    EXPECT_GT(fd, 0);
    EXPECT_EQ(write(fd, sampleData.data(), sampleData.size()),
              sampleData.size());
    close(fd);
    return stringPath;
}