mirror of
https://github.com/monero-project/monero.git
synced 2025-09-30 01:28:30 -04:00
tests: Fix tools::is_hdd unit tests
Correct the unit tests for tools::is_hdd to avoid making assumptions about the configuration of a particular device based solely on the value of the __GLIBC__ preprocessor flag. Instead, rely on the test invoker to provide paths for devices of specific types via the process environment, thereby avoiding faulty assumptions and improving the specificity of test assertions. To ensure appropriate devices exist, add a script, tests/create_test_disks.sh, which configures loopback devices mirroring relevant configurations.
This commit is contained in:
parent
c0f3a1c1db
commit
f48a73d919
3 changed files with 121 additions and 9 deletions
|
@ -1,17 +1,29 @@
|
|||
#include "common/util.h"
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <gtest/gtest.h>
|
||||
#include <boost/optional/optional_io.hpp> /* required to output boost::optional in assertions */
|
||||
|
||||
#if defined(__GLIBC__)
|
||||
TEST(is_hdd, linux_os_root)
|
||||
{
|
||||
std::string path = "/";
|
||||
EXPECT_TRUE(tools::is_hdd(path.c_str()) != boost::none);
|
||||
TEST(is_hdd, rotational_drive) {
|
||||
const char *hdd = std::getenv("MONERO_TEST_DEVICE_HDD");
|
||||
if (hdd == nullptr)
|
||||
GTEST_SKIP() << "No rotational disk device configured";
|
||||
EXPECT_EQ(tools::is_hdd(hdd), boost::optional<bool>(true));
|
||||
}
|
||||
#else
|
||||
TEST(is_hdd, unknown_os)
|
||||
{
|
||||
std::string path = "";
|
||||
EXPECT_FALSE(tools::is_hdd(path.c_str()) != boost::none);
|
||||
|
||||
TEST(is_hdd, ssd) {
|
||||
const char *ssd = std::getenv("MONERO_TEST_DEVICE_SSD");
|
||||
if (ssd == nullptr)
|
||||
GTEST_SKIP() << "No SSD device configured";
|
||||
EXPECT_EQ(tools::is_hdd(ssd), boost::optional<bool>(false));
|
||||
}
|
||||
|
||||
TEST(is_hdd, unknown_attrs) {
|
||||
EXPECT_EQ(tools::is_hdd("/dev/null"), boost::none);
|
||||
}
|
||||
#endif
|
||||
TEST(is_hdd, stability)
|
||||
{
|
||||
EXPECT_NO_THROW(tools::is_hdd(""));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue