* Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
* 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.
*/
#include "test_check_path.h"
#include "common/path_transform.h"
#include "jni/kv_helper.h"
namespace ock {
namespace bss {
namespace test {
TEST_F(TestCheckPath, test_path_utils_path_transform_extract_file_name)
{
std::string path = "/data/local/tmp.log";
const auto &extractFileName = PathTransform::ExtractFileName(path);
ASSERT_EQ(path, "/data/local/tmp.log");
ASSERT_EQ(extractFileName, "tmp.log");
}
TEST_F(TestCheckPath, test_path_utils_path_transform_extract_directory)
{
std::string path = "/data/local/tmp.log";
const auto &extracDirectory = PathTransform::ExtractDirectory(path);
ASSERT_EQ(path, "/data/local/tmp.log");
ASSERT_EQ(extracDirectory, "/data/local");
}
TEST_F(TestCheckPath, test_kv_helper_check_path_valid_for_file_not_ok)
{
auto realPath = realpath(EXIST_FILE_STR.c_str(), nullptr);
ASSERT_EQ(realPath != nullptr, true);
std::string existPath(realPath);
free(realPath);
ASSERT_EQ(CheckPathValid(existPath, false, true), false);
}
TEST_F(TestCheckPath, test_kv_helper_check_path_valid_for_directory_ok)
{
auto realPath = realpath(EXIST_DIR_STR.c_str(), nullptr);
ASSERT_EQ(realPath != nullptr, true);
std::string existPath(realPath);
free(realPath);
ASSERT_EQ(CheckPathValid(existPath, false, true), true);
}
TEST_F(TestCheckPath, test_kv_helper_check_path_valid_for_remote_ok)
{
std::string hdfsPath = "hdfs://namenode:8020/data/input/logs/2023/access.log";
ASSERT_EQ(CheckPathValid(hdfsPath, true), true);
}
TEST_F(TestCheckPath, test_kv_helper_check_path_valid)
{
auto realPath = realpath(EXIST_DIR_STR.c_str(), nullptr);
ASSERT_EQ(realPath != nullptr, true);
std::string existPath(realPath);
free(realPath);
std::string noExistPath = PathTransform::ExtractDirectory(existPath) + "/no_exist_dir";
ASSERT_EQ(CheckPathValid(noExistPath), false);
ASSERT_EQ(CheckPathValid(PathTransform::ExtractDirectory(noExistPath)), true);
std::string existPath2 = "file://" + existPath;
ASSERT_EQ(CheckPathValid(existPath2), true);
std::string noExistPath2 = "file://" + noExistPath;
ASSERT_EQ(CheckPathValid(noExistPath2), false);
}
}
}
}