dbus: Move findSensors to dbus util

Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I2ba4d3c430200eb58cb4364dcce694a080531846
diff --git a/test/dbus_util_unittest.cpp b/test/dbus_util_unittest.cpp
index b02e1d6..0780cb1 100644
--- a/test/dbus_util_unittest.cpp
+++ b/test/dbus_util_unittest.cpp
@@ -2,6 +2,9 @@
 
 #include <string>
 #include <tuple>
+#include <unordered_map>
+#include <utility>
+#include <vector>
 
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
@@ -12,6 +15,7 @@
 {
 
 using ::testing::StrEq;
+using ::testing::UnorderedElementsAreArray;
 
 class GetSensorPathTest :
     public ::testing::TestWithParam<
@@ -36,5 +40,50 @@
         std::make_tuple("temp", "123",
                         "/xyz/openbmc_project/sensors/temperature/123")));
 
+class FindSensorsTest : public ::testing::Test
+{
+  protected:
+    const std::unordered_map<std::string, std::string> sensors = {
+        {"path_a", "b"},
+        {"apple", "juice"},
+        {"other_le", "thing"},
+    };
+
+    std::vector<std::pair<std::string, std::string>> results;
+};
+
+TEST_F(FindSensorsTest, NoMatches)
+{
+    const std::string target = "abcd";
+
+    EXPECT_FALSE(findSensors(sensors, target, results));
+}
+
+TEST_F(FindSensorsTest, OneMatches)
+{
+    const std::string target = "a";
+
+    EXPECT_TRUE(findSensors(sensors, target, results));
+
+    std::vector<std::pair<std::string, std::string>> expected_results = {
+        {"path_a", "b"},
+    };
+
+    EXPECT_THAT(results, UnorderedElementsAreArray(expected_results));
+}
+
+TEST_F(FindSensorsTest, MultipleMatches)
+{
+    const std::string target = "le";
+    EXPECT_TRUE(findSensors(sensors, target, results));
+
+    std::vector<std::pair<std::string, std::string>> expected_results = {
+        {"apple", "juice"},
+        {"other_le", "thing"},
+    };
+
+    EXPECT_THAT(results, UnorderedElementsAreArray(expected_results));
+}
+
 } // namespace
 } // namespace pid_control