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 @@ -18,7 +18,10 @@

add_executable(hdfs_tool_tests
hdfs-allow-snapshot-mock.cc
hdfs-disallow-snapshot-mock.cc
hdfs-rename-snapshot-mock.cc
hdfs-delete-snapshot-mock.cc
hdfs-create-snapshot-mock.cc
hdfs-cat-mock.cc
hdfs-tool-test-fixtures.cc
hdfs-tool-tests.cc
Expand All @@ -29,12 +32,18 @@ target_include_directories(hdfs_tool_tests PRIVATE
../../tools
../../tools/hdfs-df
../../tools/hdfs-allow-snapshot
../../tools/hdfs-disallow-snapshot
../../tools/hdfs-delete-snapshot
../../tools/hdfs-create-snapshot
../../tools/hdfs-rename-snapshot
../../tools/hdfs-cat)
target_link_libraries(hdfs_tool_tests PRIVATE
gmock_main
hdfs_df_lib
hdfs_allowSnapshot_lib
hdfs_disallowSnapshot_lib
hdfs_deleteSnapshot_lib
hdfs_createSnapshot_lib
hdfs_renameSnapshot_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,58 @@
/*
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 <optional>
#include <string>
#include <vector>

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

#include "hdfs-create-snapshot-mock.h"
#include "hdfs-tool-tests.h"

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

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

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

if (*test_case_func == &PassNOptAndAPath<CreateSnapshotMock>) {
const auto arg1 = args[1];
const auto arg2 = std::optional{args[0]};
EXPECT_CALL(*this, HandleSnapshot(arg1, arg2))
.Times(1)
.WillOnce(testing::Return(true));
}
}
} // namespace hdfs::tools::test
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* 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_CREATE_SNAPSHOT_MOCK
#define LIBHDFSPP_TOOLS_HDFS_CREATE_SNAPSHOT_MOCK

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

#include <gmock/gmock.h>

#include "hdfs-create-snapshot.h"

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

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

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

MOCK_METHOD(bool, HandleSnapshot,
(const std::string &, const std::optional<std::string> &),
(const, override));
};
} // namespace hdfs::tools::test

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

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

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

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

if (*test_case_func == &PassAPath<DisallowSnapshotMock>) {
const auto arg1 = args[0];
EXPECT_CALL(*this, HandleSnapshot(arg1))
.Times(1)
.WillOnce(testing::Return(true));
}
}
} // namespace hdfs::tools::test
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* 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_DISALLOW_SNAPSHOT_MOCK
#define LIBHDFSPP_TOOLS_HDFS_DISALLOW_SNAPSHOT_MOCK

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

#include <gmock/gmock.h>

#include "hdfs-disallow-snapshot.h"

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

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

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

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

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

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

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

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

if (*test_case_func == &Pass3Paths<RenameSnapshotMock>) {
const auto arg1 = args[0];
const auto arg2 = args[1];
const auto arg3 = args[2];
EXPECT_CALL(*this, HandleSnapshot(arg1, arg2, arg3))
.Times(1)
.WillOnce(testing::Return(true));
}
}
} // namespace hdfs::tools::test
Loading