1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#include "async_resp.hpp"
#include "manager_diagnostic_data.hpp"
#include <nlohmann/json.hpp>
#include <memory>
#include <gtest/gtest.h>
namespace redfish
{
namespace
{
using json_pointer = nlohmann::json::json_pointer;
void testDataGetNoError(boost::system::error_code ec)
{
auto asyncResp = std::make_shared<bmcweb::AsyncResp>();
setBytesProperty(asyncResp,
json_pointer("/MemoryStatistics/FreeStorageSpace"), ec, 0);
EXPECT_TRUE(asyncResp->res.jsonValue.is_null());
EXPECT_EQ(asyncResp->res.result(), boost::beast::http::status::ok);
}
TEST(ManagerDiagnosticDataTest, ManagerDataGetServerUnreachable)
{
testDataGetNoError(boost::asio::error::basic_errors::host_unreachable);
}
TEST(ManagerDiagnosticDataTest, ManagerDataGetPathInvalid)
{
testDataGetNoError(boost::system::linux_error::bad_request_descriptor);
}
void verifyError(crow::Response& res)
{
EXPECT_EQ(res.result(), boost::beast::http::status::internal_server_error);
res.clear();
}
TEST(ManagerDiagnosticDataTest, ManagerDataGetFailure)
{
auto asyncResp = std::make_shared<bmcweb::AsyncResp>();
boost::system::error_code ec = boost::asio::error::operation_aborted;
setBytesProperty(asyncResp,
json_pointer("/MemoryStatistics/FreeStorageSpace"), ec, 0);
verifyError(asyncResp->res);
}
TEST(ManagerDiagnosticDataTest, ManagerDataGetNullPtr)
{
auto asyncResp = std::make_shared<bmcweb::AsyncResp>();
setPercentProperty(
asyncResp,
nlohmann::json::json_pointer("/MemoryStatistics/FreeStorageSpace"), {},
std::numeric_limits<double>::quiet_NaN());
EXPECT_EQ(asyncResp->res.jsonValue["FreeStorageSpaceKiB"], nullptr);
}
TEST(ManagerDiagnosticDataTest, ManagerDataGetSuccess)
{
auto asyncResp = std::make_shared<bmcweb::AsyncResp>();
setBytesProperty(asyncResp, json_pointer("/FreeStorageSpaceKiB"), {},
204800.0);
EXPECT_EQ(asyncResp->res.jsonValue["FreeStorageSpaceKiB"].get<int64_t>(),
200);
}
} // namespace
} // namespace redfish
|