Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ add_executable(hdfs_tool_tests
hdfs-rm-mock.cc
hdfs-get-mock.cc
hdfs-find-mock.cc
hdfs-ls-mock.cc
main.cc)
target_include_directories(hdfs_tool_tests PRIVATE
../tools
Expand All @@ -58,6 +59,7 @@ target_include_directories(hdfs_tool_tests PRIVATE
../../tools/hdfs-rm
../../tools/hdfs-get
../../tools/hdfs-find
../../tools/hdfs-ls
../../tools/hdfs-cat)
target_link_libraries(hdfs_tool_tests PRIVATE
gmock_main
Expand All @@ -78,5 +80,6 @@ target_link_libraries(hdfs_tool_tests PRIVATE
hdfs_rm_lib
hdfs_get_lib
hdfs_find_lib
hdfs_ls_lib
hdfs_cat_lib)
add_test(hdfs_tool_tests hdfs_tool_tests)
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <functional>
#include <memory>
#include <string>
#include <vector>

#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include "hdfs-ls-mock.h"
#include "hdfs-tool-tests.h"

namespace hdfs::tools::test {
LsMock::~LsMock() = default;

void LsMock::SetExpectations(std::function<std::unique_ptr<LsMock>()> test_case,
const std::vector<std::string> &args) const {
// Get the pointer to the function that defines the test case
const auto test_case_func = test_case.target<std::unique_ptr<LsMock> (*)()>();
ASSERT_NE(test_case_func, nullptr);

// Set the expected method calls and their corresponding arguments for each
// test case
if (*test_case_func == &CallHelp<LsMock>) {
EXPECT_CALL(*this, HandleHelp()).Times(1).WillOnce(testing::Return(true));
return;
}

if (*test_case_func == &PassAPath<LsMock>) {
const auto arg1 = args[0];
EXPECT_CALL(*this, HandlePath(arg1, false))
.Times(1)
.WillOnce(testing::Return(true));
}

if (*test_case_func == &PassRecursivePath<LsMock>) {
const auto arg1 = args[0];
const auto arg2 = args[1];
ASSERT_EQ(arg1, "-R");
EXPECT_CALL(*this, HandlePath(arg2, true))
.Times(1)
.WillOnce(testing::Return(true));
}

if (*test_case_func == &PassRecursive<LsMock>) {
const auto arg1 = args[0];
ASSERT_EQ(arg1, "-R");
}
}
} // namespace hdfs::tools::test
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef LIBHDFSPP_TOOLS_HDFS_LS_MOCK
#define LIBHDFSPP_TOOLS_HDFS_LS_MOCK

#include <functional>
#include <memory>
#include <string>
#include <vector>

#include <gmock/gmock.h>

#include "hdfs-ls.h"

namespace hdfs::tools::test {
/**
* {@class LsMock} is an {@class Ls} whereby it mocks the
* HandleHelp and HandlePath methods for testing their functionality.
*/
class LsMock : public hdfs::tools::Ls {
public:
/**
* {@inheritdoc}
*/
LsMock(const int argc, char **argv) : Ls(argc, argv) {}

// Abiding to the Rule of 5
LsMock(const LsMock &) = delete;
LsMock(LsMock &&) = delete;
LsMock &operator=(const LsMock &) = delete;
LsMock &operator=(LsMock &&) = delete;
~LsMock() override;

/**
* Defines the methods and the corresponding arguments that are expected
* to be called on this instance of {@link HdfsTool} for the given test case.
*
* @param test_case An {@link std::function} object that points to the
* function defining the test case
* @param args The arguments that are passed to this test case
*/
void SetExpectations(std::function<std::unique_ptr<LsMock>()> test_case,
const std::vector<std::string> &args = {}) const;

MOCK_METHOD(bool, HandleHelp, (), (const, override));

MOCK_METHOD(bool, HandlePath, (const std::string &, const bool),
(const, override));
};
} // namespace hdfs::tools::test

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "hdfs-du-mock.h"
#include "hdfs-find-mock.h"
#include "hdfs-get-mock.h"
#include "hdfs-ls-mock.h"
#include "hdfs-mkdir-mock.h"
#include "hdfs-move-to-local-mock.h"
#include "hdfs-rename-snapshot-mock.h"
Expand Down Expand Up @@ -81,6 +82,12 @@ INSTANTIATE_TEST_SUITE_P(
CallHelp<hdfs::tools::test::DuMock>,
PassRecursivePath<hdfs::tools::test::DuMock>));

INSTANTIATE_TEST_SUITE_P(
HdfsLs, HdfsToolBasicTest,
testing::Values(PassAPath<hdfs::tools::test::LsMock>,
CallHelp<hdfs::tools::test::LsMock>,
PassRecursivePath<hdfs::tools::test::LsMock>));

INSTANTIATE_TEST_SUITE_P(
HdfsDeleteSnapshot, HdfsToolBasicTest,
testing::Values(CallHelp<hdfs::tools::test::DeleteSnapshotMock>,
Expand Down Expand Up @@ -180,6 +187,14 @@ INSTANTIATE_TEST_SUITE_P(
PassOwnerAndAPath<hdfs::tools::test::DuMock>,
PassPermissionsAndAPath<hdfs::tools::test::DuMock>));

INSTANTIATE_TEST_SUITE_P(
HdfsLs, HdfsToolNegativeTestThrows,
testing::Values(Pass2Paths<hdfs::tools::test::LsMock>,
Pass3Paths<hdfs::tools::test::LsMock>,
PassNOptAndAPath<hdfs::tools::test::LsMock>,
PassOwnerAndAPath<hdfs::tools::test::LsMock>,
PassPermissionsAndAPath<hdfs::tools::test::LsMock>));

INSTANTIATE_TEST_SUITE_P(
HdfsCat, HdfsToolNegativeTestThrows,
testing::Values(Pass2Paths<hdfs::tools::test::CatMock>));
Expand Down Expand Up @@ -262,6 +277,10 @@ INSTANTIATE_TEST_SUITE_P(
HdfsDu, HdfsToolNegativeTestNoThrow,
testing::Values(PassRecursive<hdfs::tools::test::DuMock>));

INSTANTIATE_TEST_SUITE_P(
HdfsLs, HdfsToolNegativeTestNoThrow,
testing::Values(PassRecursive<hdfs::tools::test::LsMock>));

INSTANTIATE_TEST_SUITE_P(
HdfsChown, HdfsToolNegativeTestNoThrow,
testing::Values(PassAPath<hdfs::tools::test::ChownMock>));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ add_subdirectory(hdfs-mkdir)

add_subdirectory(hdfs-rm)

add_executable(hdfs_ls hdfs_ls.cc)
target_link_libraries(hdfs_ls tools_common hdfspp_static)
add_subdirectory(hdfs-ls)

add_executable(hdfs_stat hdfs_stat.cc)
target_link_libraries(hdfs_stat tools_common hdfspp_static)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

add_library(hdfs_ls_lib STATIC $<TARGET_OBJECTS:hdfs_tool_obj> hdfs-ls.cc)
target_include_directories(hdfs_ls_lib PRIVATE ../../tools ${Boost_INCLUDE_DIRS})
target_link_libraries(hdfs_ls_lib PRIVATE Boost::boost Boost::program_options tools_common hdfspp_static)

add_executable(hdfs_ls main.cc)
target_include_directories(hdfs_ls PRIVATE ../../tools)
target_link_libraries(hdfs_ls PRIVATE hdfs_ls_lib)

install(TARGETS hdfs_ls RUNTIME DESTINATION bin)
Loading