test: Always create unique tmpdirs
This ensures our tests always have clear temporary directories to store
their files.
Change-Id: Ib755c4a9407b1e1925b34ae1537eb234542133b0
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/test/test_vlan_interface.cpp b/test/test_vlan_interface.cpp
index f7e6f2b..2dd78b8 100644
--- a/test/test_vlan_interface.cpp
+++ b/test/test_vlan_interface.cpp
@@ -11,6 +11,7 @@
#include <exception>
#include <filesystem>
#include <sdbusplus/bus.hpp>
+#include <stdplus/gtest/tmp.hpp>
#include <gtest/gtest.h>
@@ -21,28 +22,19 @@
namespace fs = std::filesystem;
-class TestVlanInterface : public testing::Test
+class TestVlanInterface : public stdplus::gtest::TestWithTmp
{
public:
sdbusplus::bus::bus bus;
+ std::string confDir;
MockManager manager;
EthernetInterface interface;
- std::string confDir;
TestVlanInterface() :
- bus(sdbusplus::bus::new_default()),
- manager(bus, "/xyz/openbmc_test/network", "/tmp"),
+ bus(sdbusplus::bus::new_default()), confDir(CaseTmpDir()),
+ manager(bus, "/xyz/openbmc_test/network", confDir),
interface(makeInterface(bus, manager))
{
- setConfDir();
- }
-
- ~TestVlanInterface()
- {
- if (confDir != "")
- {
- fs::remove_all(confDir);
- }
}
static EthernetInterface makeInterface(sdbusplus::bus::bus& bus,
@@ -58,13 +50,6 @@
true};
}
- void setConfDir()
- {
- char tmp[] = "/tmp/VlanInterface.XXXXXX";
- confDir = mkdtemp(tmp);
- manager.setConfDir(confDir);
- }
-
void createVlan(VlanId id)
{
std::string ifname = "test0.";