Skip to content

HDFS-16285. Make HDFS ownership tools cross platform #3588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Dec 9, 2021
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 @@ -23,6 +23,9 @@ add_executable(hdfs_tool_tests
hdfs-delete-snapshot-mock.cc
hdfs-create-snapshot-mock.cc
hdfs-cat-mock.cc
hdfs-chown-mock.cc
hdfs-chmod-mock.cc
hdfs-chgrp-mock.cc
hdfs-tool-test-fixtures.cc
hdfs-tool-tests.cc
hdfs-df-mock.cc
Expand All @@ -36,6 +39,9 @@ target_include_directories(hdfs_tool_tests PRIVATE
../../tools/hdfs-delete-snapshot
../../tools/hdfs-create-snapshot
../../tools/hdfs-rename-snapshot
../../tools/hdfs-chown
../../tools/hdfs-chgrp
../../tools/hdfs-chmod
../../tools/hdfs-cat)
target_link_libraries(hdfs_tool_tests PRIVATE
gmock_main
Expand All @@ -45,5 +51,8 @@ target_link_libraries(hdfs_tool_tests PRIVATE
hdfs_deleteSnapshot_lib
hdfs_createSnapshot_lib
hdfs_renameSnapshot_lib
hdfs_chown_lib
hdfs_chgrp_lib
hdfs_chmod_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-chgrp-mock.h"
#include "hdfs-chgrp.h"
#include "hdfs-tool-tests.h"

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

void ChgrpMock::SetExpectations(
std::function<std::unique_ptr<ChgrpMock>()> 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<ChgrpMock> (*)()>();
ASSERT_NE(test_case_func, nullptr);

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

if (*test_case_func == &PassOwnerAndAPath<ChgrpMock>) {
const auto arg1 = args[0];
const auto arg2 = args[1];

EXPECT_CALL(*this, HandlePath(arg1, false, arg2))
.Times(1)
.WillOnce(testing::Return(true));
}

if (*test_case_func == &PassRecursiveOwnerAndAPath<ChgrpMock>) {
const auto arg1 = args[1];
const auto arg2 = args[2];

EXPECT_CALL(*this, HandlePath(arg1, true, arg2))
.Times(1)
.WillOnce(testing::Return(true));
}
}
} // namespace hdfs::tools::test
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* 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_CHGRP_MOCK
#define LIBHDFSPP_TOOLS_HDFS_CHGRP_MOCK

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

#include <gmock/gmock.h>

#include "hdfs-chgrp.h"

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

// Abiding to the Rule of 5
ChgrpMock(const ChgrpMock &) = delete;
ChgrpMock(ChgrpMock &&) = delete;
ChgrpMock &operator=(const ChgrpMock &) = delete;
ChgrpMock &operator=(ChgrpMock &&) = delete;
~ChgrpMock() 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<ChgrpMock>()> test_case,
const std::vector<std::string> &args = {}) const;

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

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

#endif
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-chmod-mock.h"
#include "hdfs-chmod.h"
#include "hdfs-tool-tests.h"

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

void ChmodMock::SetExpectations(
std::function<std::unique_ptr<ChmodMock>()> 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<ChmodMock> (*)()>();
ASSERT_NE(test_case_func, nullptr);

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

if (*test_case_func == &PassPermissionsAndAPath<ChmodMock>) {
const auto arg1 = args[0];
const auto arg2 = args[1];

EXPECT_CALL(*this, HandlePath(arg1, false, arg2))
.Times(1)
.WillOnce(testing::Return(true));
}

if (*test_case_func == &PassRecursivePermissionsAndAPath<ChmodMock>) {
const auto arg1 = args[1];
const auto arg2 = args[2];

EXPECT_CALL(*this, HandlePath(arg1, true, arg2))
.Times(1)
.WillOnce(testing::Return(true));
}
}
} // namespace hdfs::tools::test
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* 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_CHMOD_MOCK
#define LIBHDFSPP_TOOLS_HDFS_CHMOD_MOCK

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

#include <gmock/gmock.h>

#include "hdfs-chmod.h"

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

// Abiding to the Rule of 5
ChmodMock(const ChmodMock &) = delete;
ChmodMock(ChmodMock &&) = delete;
ChmodMock &operator=(const ChmodMock &) = delete;
ChmodMock &operator=(ChmodMock &&) = delete;
~ChmodMock() 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<ChmodMock>()> test_case,
const std::vector<std::string> &args = {}) const;

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

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

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* 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-chown-mock.h"
#include "hdfs-chown.h"
#include "hdfs-tool-tests.h"

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

void ChownMock::SetExpectations(
std::function<std::unique_ptr<ChownMock>()> 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<ChownMock> (*)()>();
ASSERT_NE(test_case_func, nullptr);

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

if (*test_case_func == &PassOwnerAndAPath<ChownMock>) {
const auto arg1 = args[0];
const auto arg2 = args[1];
const Ownership ownership(arg1);

EXPECT_CALL(*this, HandlePath(ownership, false, arg2))
.Times(1)
.WillOnce(testing::Return(true));
}

if (*test_case_func == &PassRecursiveOwnerAndAPath<ChownMock>) {
const auto arg1 = args[1];
const auto arg2 = args[2];
const Ownership ownership(arg1);

EXPECT_CALL(*this, HandlePath(ownership, true, arg2))
.Times(1)
.WillOnce(testing::Return(true));
}
}
} // namespace hdfs::tools::test
Loading