1 #include "blob_mock.hpp" 2 3 #include <blobs-ipmid/manager.hpp> 4 5 #include <gtest/gtest.h> 6 7 namespace blobs 8 { 9 10 using ::testing::Return; 11 12 TEST(ManagerStatTest, StatNoHandler) 13 { 14 // There is no handler for this path. 15 16 BlobManager mgr; 17 std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>(); 18 auto m1ptr = m1.get(); 19 EXPECT_TRUE(mgr.registerHandler(std::move(m1))); 20 21 struct BlobMeta meta; 22 std::string path = "/asdf/asdf"; 23 EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(false)); 24 25 EXPECT_FALSE(mgr.stat(path, &meta)); 26 } 27 28 TEST(ManagerStatTest, StatHandlerFoundButFails) 29 { 30 // There is a handler for this path but Stat fails. 31 32 BlobManager mgr; 33 std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>(); 34 auto m1ptr = m1.get(); 35 EXPECT_TRUE(mgr.registerHandler(std::move(m1))); 36 37 struct BlobMeta meta; 38 std::string path = "/asdf/asdf"; 39 EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(true)); 40 EXPECT_CALL(*m1ptr, stat(path, &meta)).WillOnce(Return(false)); 41 42 EXPECT_FALSE(mgr.stat(path, &meta)); 43 } 44 45 TEST(ManagerStatTest, StatHandlerFoundAndSucceeds) 46 { 47 // There is a handler and Stat succeeds. 48 49 BlobManager mgr; 50 std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>(); 51 auto m1ptr = m1.get(); 52 EXPECT_TRUE(mgr.registerHandler(std::move(m1))); 53 54 struct BlobMeta meta; 55 std::string path = "/asdf/asdf"; 56 EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(true)); 57 EXPECT_CALL(*m1ptr, stat(path, &meta)).WillOnce(Return(true)); 58 59 EXPECT_TRUE(mgr.stat(path, &meta)); 60 } 61 } // namespace blobs 62