From 8020e1e076e597a82962fe03990f89314f5419fa Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Mon, 17 Oct 2022 11:10:05 +0800
Subject: [PATCH 11/43] add ut for utils_fs

Signed-off-by: haozi007 <liuhao27@huawei.com>
---
 test/cutils/CMakeLists.txt          |  1 +
 test/cutils/utils_fs/CMakeLists.txt | 16 +++++++++++
 test/cutils/utils_fs/utils_fs_ut.cc | 42 +++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+)
 create mode 100644 test/cutils/utils_fs/CMakeLists.txt
 create mode 100644 test/cutils/utils_fs/utils_fs_ut.cc

diff --git a/test/cutils/CMakeLists.txt b/test/cutils/CMakeLists.txt
index d3e1038a..9073a68d 100644
--- a/test/cutils/CMakeLists.txt
+++ b/test/cutils/CMakeLists.txt
@@ -25,3 +25,4 @@ add_subdirectory(utils_namespace)
 add_subdirectory(utils_network)
 add_subdirectory(utils_aes)
 add_subdirectory(utils_error)
+add_subdirectory(utils_fs)
diff --git a/test/cutils/utils_fs/CMakeLists.txt b/test/cutils/utils_fs/CMakeLists.txt
new file mode 100644
index 00000000..7ff3176a
--- /dev/null
+++ b/test/cutils/utils_fs/CMakeLists.txt
@@ -0,0 +1,16 @@
+project(iSulad_UT)
+
+SET(EXE utils_fs_ut)
+
+add_executable(${EXE}
+    utils_fs_ut.cc)
+
+target_include_directories(${EXE} PUBLIC
+    ${GTEST_INCLUDE_DIR}
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../include
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/common
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/map
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils
+    )
+target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lcrypto -lyajl -lz)
+add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
diff --git a/test/cutils/utils_fs/utils_fs_ut.cc b/test/cutils/utils_fs/utils_fs_ut.cc
new file mode 100644
index 00000000..e1c4fd4b
--- /dev/null
+++ b/test/cutils/utils_fs/utils_fs_ut.cc
@@ -0,0 +1,42 @@
+/******************************************************************************
+ * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.
+ * iSulad licensed under the Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ *     http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: haozi007
+ * Create: 2022-10-13
+ * Description: utils namespace unit test
+ *******************************************************************************/
+
+#include <gtest/gtest.h>
+#include "utils_fs.h"
+
+int good_cb(const char *mp, const char *pattern)
+{
+    return 0;
+}
+
+int good_check_cb(const char *mp, const char *pattern)
+{
+    return pattern != nullptr ? 0 : -1;
+}
+
+int bad_cb(const char *mp, const char *pattern)
+{
+    return -1;
+}
+
+TEST(utils_fs, test_util_deal_with_mount_info)
+{
+    std::string spattern = "[0-9]*";
+
+    ASSERT_EQ(util_deal_with_mount_info(good_cb, spattern.c_str()), true);
+    ASSERT_EQ(util_deal_with_mount_info(bad_cb, spattern.c_str()), false);
+    ASSERT_EQ(util_deal_with_mount_info(good_check_cb, spattern.c_str()), true);
+    ASSERT_EQ(util_deal_with_mount_info(good_check_cb, nullptr), false);
+}
-- 
2.25.1

