utils: Add function to check if PSU is associated
Add a helper function to check if a PSU is in an association list, which
will be used in future commits to check if a PSU is running a software
image.
Tested: added unit test case and verify it passes.
Signed-off-by: Lei YU <mine260309@gmail.com>
Change-Id: I99b5d3d8d09f8e09a1eb42ba104a4804b7214cf1
diff --git a/test/mocked_utils.hpp b/test/mocked_utils.hpp
index cd85c3c..71aac99 100644
--- a/test/mocked_utils.hpp
+++ b/test/mocked_utils.hpp
@@ -30,6 +30,9 @@
MOCK_CONST_METHOD1(getLatestVersion,
std::string(const std::set<std::string>& versions));
+ MOCK_CONST_METHOD2(isAssociated, bool(const std::string& psuInventoryPath,
+ const AssociationList& assocs));
+
MOCK_CONST_METHOD5(getPropertyImpl,
any(sdbusplus::bus::bus& bus, const char* service,
const char* path, const char* interface,
diff --git a/test/test_utils.cpp b/test/test_utils.cpp
index a623cf5..afcbb47 100644
--- a/test/test_utils.cpp
+++ b/test/test_utils.cpp
@@ -1,3 +1,5 @@
+#include "config.h"
+
#include "utils.hpp"
#include <sdbusplus/test/sdbus_mock.hpp>
@@ -63,10 +65,23 @@
TEST(Utils, GetVersionID)
{
-
auto ret = utils::getVersionId("");
EXPECT_EQ("", ret);
ret = utils::getVersionId("some version");
EXPECT_EQ(8u, ret.size());
}
+
+TEST(Utils, IsAssociated)
+{
+ std::string path = "/com/example/chassis/powersupply0";
+ utils::AssociationList assocs = {{ACTIVATION_FWD_ASSOCIATION,
+ ACTIVATION_REV_ASSOCIATION,
+ "a-different-path"}};
+
+ EXPECT_FALSE(utils::isAssociated(path, assocs));
+
+ assocs.emplace_back(ACTIVATION_FWD_ASSOCIATION, ACTIVATION_REV_ASSOCIATION,
+ path);
+ EXPECT_TRUE(utils::isAssociated(path, assocs));
+}