summaryrefslogtreecommitdiffstats
path: root/test/manager_stat_unittest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/manager_stat_unittest.cpp')
-rw-r--r--test/manager_stat_unittest.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/test/manager_stat_unittest.cpp b/test/manager_stat_unittest.cpp
new file mode 100644
index 0000000..a13a66d
--- /dev/null
+++ b/test/manager_stat_unittest.cpp
@@ -0,0 +1,60 @@
+#include "blob_mock.hpp"
+#include "manager.hpp"
+
+#include <gtest/gtest.h>
+
+namespace blobs
+{
+
+using ::testing::Return;
+
+TEST(ManagerStatTest, StatNoHandler)
+{
+ // There is no handler for this path.
+
+ BlobManager mgr;
+ std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>();
+ auto m1ptr = m1.get();
+ EXPECT_TRUE(mgr.registerHandler(std::move(m1)));
+
+ struct BlobMeta meta;
+ std::string path = "/asdf/asdf";
+ EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(false));
+
+ EXPECT_FALSE(mgr.stat(path, &meta));
+}
+
+TEST(ManagerStatTest, StatHandlerFoundButFails)
+{
+ // There is a handler for this path but Stat fails.
+
+ BlobManager mgr;
+ std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>();
+ auto m1ptr = m1.get();
+ EXPECT_TRUE(mgr.registerHandler(std::move(m1)));
+
+ struct BlobMeta meta;
+ std::string path = "/asdf/asdf";
+ EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(true));
+ EXPECT_CALL(*m1ptr, stat(path, &meta)).WillOnce(Return(false));
+
+ EXPECT_FALSE(mgr.stat(path, &meta));
+}
+
+TEST(ManagerStatTest, StatHandlerFoundAndSucceeds)
+{
+ // There is a handler and Stat succeeds.
+
+ BlobManager mgr;
+ std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>();
+ auto m1ptr = m1.get();
+ EXPECT_TRUE(mgr.registerHandler(std::move(m1)));
+
+ struct BlobMeta meta;
+ std::string path = "/asdf/asdf";
+ EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(true));
+ EXPECT_CALL(*m1ptr, stat(path, &meta)).WillOnce(Return(true));
+
+ EXPECT_TRUE(mgr.stat(path, &meta));
+}
+} // namespace blobs
OpenPOWER on IntegriCloud