test: sensor_manager: add test and sensor_mock

Adds a mock sensor for use in future tests, as well as
adds a unit-test to sensor_manager_unittest to check that the
type of a sensor added is not validated against anything.

Change-Id: I684ec71c02f427cfa7a414a6a4162beaba2269da
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/test/sensor_manager_unittest.cpp b/test/sensor_manager_unittest.cpp
index 17ccffa..b873886 100644
--- a/test/sensor_manager_unittest.cpp
+++ b/test/sensor_manager_unittest.cpp
@@ -4,6 +4,8 @@
 #include <gtest/gtest.h>
 #include <sdbusplus/test/sdbus_mock.hpp>
 
+#include "test/sensor_mock.hpp"
+
 using ::testing::_;
 using ::testing::IsNull;
 using ::testing::Return;
@@ -26,3 +28,32 @@
     SensorManager s(std::move(bus_mock_passive), std::move(bus_mock_host));
     // Success
 }
+
+TEST(SensorManagerTest, AddSensorInvalidTypeTest) {
+    // AddSensor doesn't validate the type of sensor you're adding, because
+    // ultimately it doesn't care -- but if we decide to change that this
+    // test will start failing :D
+
+    sdbusplus::SdBusMock sdbus_mock_passive, sdbus_mock_host;
+    auto bus_mock_passive = sdbusplus::get_mocked_new(&sdbus_mock_passive);
+    auto bus_mock_host = sdbusplus::get_mocked_new(&sdbus_mock_host);
+
+    EXPECT_CALL(sdbus_mock_host,
+                sd_bus_add_object_manager(
+                    IsNull(),
+                    _,
+                    StrEq("/xyz/openbmc_project/extsensors")))
+    .WillOnce(Return(0));
+
+    SensorManager s(std::move(bus_mock_passive), std::move(bus_mock_host));
+
+    std::string name = "name";
+    std::string type = "invalid";
+    int64_t timeout = 1;
+    std::unique_ptr<Sensor> sensor =
+        std::make_unique<SensorMock>(name, timeout);
+    Sensor *sensor_ptr = sensor.get();
+
+    s.addSensor(type, name, std::move(sensor));
+    EXPECT_EQ(s.getSensor(name).get(), sensor_ptr);
+}