summaryrefslogtreecommitdiffstats
path: root/cleanup/test
diff options
context:
space:
mode:
authorPatrick Venture <venture@google.com>2019-06-19 08:45:44 -0700
committerPatrick Venture <venture@google.com>2019-06-19 10:38:41 -0700
commit9efef5d97ec6c67e2c8e3b3c06727ee034846aa6 (patch)
treeb0aae16b8fb0041fdf4cd63441ec50f2cfbb79a3 /cleanup/test
parente1118bcb2dbb64e90ac5671f7978d4748d0a5e3b (diff)
downloadphosphor-ipmi-flash-9efef5d97ec6c67e2c8e3b3c06727ee034846aa6.tar.gz
phosphor-ipmi-flash-9efef5d97ec6c67e2c8e3b3c06727ee034846aa6.zip
bmc: add cleanup blob handler
Add a cleanup blob handler, such that there is a new blob id present named "/flash/cleanup" that will delete temporary files. This blob handler expects a client to open/commit/close the blob. This blob handler will delete files that are specified as temporary. The host client may use this to clean up artifacts on verification or update failure. This can be extended later to handle calling a service or doing anything else to cleanup. The cleanup handler will be added if --enable-cleanup-delete. The recipe will automatically add this blob handler if that configure variable is set. Tested: Not tested on real hardware. Signed-off-by: Patrick Venture <venture@google.com> Change-Id: I4502b2613e38f0a947d7235d084287376c6b0ce1
Diffstat (limited to 'cleanup/test')
-rw-r--r--cleanup/test/Makefile.am18
-rw-r--r--cleanup/test/cleanup_handler_unittest.cpp42
-rw-r--r--cleanup/test/filesystem_mock.hpp17
3 files changed, 77 insertions, 0 deletions
diff --git a/cleanup/test/Makefile.am b/cleanup/test/Makefile.am
new file mode 100644
index 0000000..4c347ba
--- /dev/null
+++ b/cleanup/test/Makefile.am
@@ -0,0 +1,18 @@
+AM_CPPFLAGS = -I$(top_srcdir)/ \
+ -I$(top_srcdir)/cleanup/ \
+ $(GTEST_CFLAGS) \
+ $(GMOCK_CFLAGS)
+AM_CXXFLAGS = \
+ $(PHOSPHOR_LOGGING_CFLAGS)
+AM_LDFLAGS = \
+ $(GTEST_LIBS) \
+ $(GMOCK_LIBS) \
+ -lgmock_main \
+ $(OESDK_TESTCASE_FLAGS) \
+ $(PHOSPHOR_LOGGING_LIBS)
+
+check_PROGRAMS = cleanup_handler_unittest
+TESTS = $(check_PROGRAMS)
+
+cleanup_handler_unittest_SOURCES = cleanup_handler_unittest.cpp
+cleanup_handler_unittest_LDADD = $(top_builddir)/cleanup/libfirmwarecleanupblob_common.la
diff --git a/cleanup/test/cleanup_handler_unittest.cpp b/cleanup/test/cleanup_handler_unittest.cpp
new file mode 100644
index 0000000..5191234
--- /dev/null
+++ b/cleanup/test/cleanup_handler_unittest.cpp
@@ -0,0 +1,42 @@
+#include "cleanup.hpp"
+#include "filesystem_mock.hpp"
+#include "util.hpp"
+
+#include <string>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+namespace ipmi_flash
+{
+namespace
+{
+
+using ::testing::Return;
+using ::testing::UnorderedElementsAreArray;
+
+class CleanupHandlerTest : public ::testing::Test
+{
+ protected:
+ std::vector<std::string> blobs = {"abcd", "efgh"};
+ FileSystemMock mock;
+ FileCleanupHandler handler{cleanupBlobId, blobs, &mock};
+};
+
+TEST_F(CleanupHandlerTest, GetBlobListReturnsExpectedList)
+{
+ EXPECT_TRUE(handler.canHandleBlob(cleanupBlobId));
+ EXPECT_THAT(handler.getBlobIds(),
+ UnorderedElementsAreArray({cleanupBlobId}));
+}
+
+TEST_F(CleanupHandlerTest, CommitShouldDeleteFiles)
+{
+ EXPECT_CALL(mock, remove("abcd")).WillOnce(Return());
+ EXPECT_CALL(mock, remove("efgh")).WillOnce(Return());
+
+ EXPECT_TRUE(handler.commit(1, {}));
+}
+
+} // namespace
+} // namespace ipmi_flash
diff --git a/cleanup/test/filesystem_mock.hpp b/cleanup/test/filesystem_mock.hpp
new file mode 100644
index 0000000..76a45c1
--- /dev/null
+++ b/cleanup/test/filesystem_mock.hpp
@@ -0,0 +1,17 @@
+#pragma once
+
+#include "fs.hpp"
+
+#include <string>
+
+#include <gmock/gmock.h>
+
+namespace ipmi_flash
+{
+
+class FileSystemMock : public FileSystemInterface
+{
+ public:
+ MOCK_CONST_METHOD1(remove, void(const std::string&));
+};
+} // namespace ipmi_flash
OpenPOWER on IntegriCloud