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