for injection, add handler: add unit-tests
Add a handler to enable dependency injection for testing. This is a
required step to use mocks.
Add the unit-tests.
Tested: Verified the new unit-tests ran.
Change-Id: I991849e6df2c3e74f59145a966048fc6825560db
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/handler.hpp b/handler.hpp
new file mode 100644
index 0000000..77ad55c
--- /dev/null
+++ b/handler.hpp
@@ -0,0 +1,41 @@
+#pragma once
+
+#include <cstdint>
+#include <string>
+
+namespace ethstats
+{
+
+class EthStatsInterface
+{
+ public:
+ virtual ~EthStatsInterface() = default;
+
+ /** Given an ifname and a statistic, validate both.
+ *
+ * @param[in] path - the interface name and statistics field
+ * @return true if both valid, false otherwise.
+ */
+ virtual bool validIfNameAndField(const std::string& path) const = 0;
+
+ /** Given an ifname and a statistic, return the value.
+ *
+ * @param[in] path - the interface name and statistics field
+ * @return the value of that statistic for that interface.
+ */
+ virtual std::uint64_t readStatistic(const std::string& path) const = 0;
+};
+
+class EthStats : public EthStatsInterface
+{
+ public:
+ EthStats() = default;
+ ~EthStats() = default;
+
+ bool validIfNameAndField(const std::string& path) const override;
+ std::uint64_t readStatistic(const std::string& path) const override;
+};
+
+extern EthStats handler;
+
+} // namespace ethstats