123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- /*
- 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_TOOL_TESTS
- #define LIBHDFSPP_TOOLS_HDFS_TOOL_TESTS
- #include <memory>
- #include <string>
- /**
- * This file contains the generalized test cases to run against the derivatives
- * of {@link hdfs::tools::HdfsTool}.
- *
- * Each test case passes the arguments to the {@link hdfs::tools::HdfsTool} and
- * calls the method to set the expectation on the instance of {@link
- * hdfs::tools::HdfsTool} as defined in its corresponding mock implementation.
- */
- template <class T> std::unique_ptr<T> PassAPath() {
- constexpr auto argc = 2;
- static std::string exe("hdfs_tool_name");
- static std::string arg1("a/b/c");
- static char *argv[] = {exe.data(), arg1.data()};
- auto hdfs_tool = std::make_unique<T>(argc, argv);
- hdfs_tool->SetExpectations(PassAPath<T>, {arg1});
- return hdfs_tool;
- }
- template <class T> std::unique_ptr<T> PassRecursive() {
- constexpr auto argc = 2;
- static std::string exe("hdfs_tool_name");
- static std::string arg1("-R");
- static char *argv[] = {exe.data(), arg1.data()};
- auto hdfs_tool = std::make_unique<T>(argc, argv);
- hdfs_tool->SetExpectations(PassRecursive<T>, {arg1});
- return hdfs_tool;
- }
- template <class T> std::unique_ptr<T> PassRecursivePath() {
- constexpr auto argc = 3;
- static std::string exe("hdfs_tool_name");
- static std::string arg1("-R");
- static std::string arg2("a/b/c");
- static char *argv[] = {exe.data(), arg1.data(), arg2.data()};
- auto hdfs_tool = std::make_unique<T>(argc, argv);
- hdfs_tool->SetExpectations(PassRecursivePath<T>, {arg1, arg2});
- return hdfs_tool;
- }
- template <class T> std::unique_ptr<T> PassFOptAndAPath() {
- constexpr auto argc = 3;
- static std::string exe("hdfs_tool_name");
- static std::string arg1("-f");
- static std::string arg2("a/b/c");
- static char *argv[] = {exe.data(), arg1.data(), arg2.data()};
- auto hdfs_tool = std::make_unique<T>(argc, argv);
- hdfs_tool->SetExpectations(PassFOptAndAPath<T>, {arg1, arg2});
- return hdfs_tool;
- }
- template <class T> std::unique_ptr<T> CallHelp() {
- constexpr auto argc = 2;
- static std::string exe("hdfs_tool_name");
- static std::string arg1("-h");
- static char *argv[] = {exe.data(), arg1.data()};
- auto hdfs_tool = std::make_unique<T>(argc, argv);
- hdfs_tool->SetExpectations(CallHelp<T>);
- return hdfs_tool;
- }
- template <class T> std::unique_ptr<T> Pass2Paths() {
- constexpr auto argc = 3;
- static std::string exe("hdfs_tool_name");
- static std::string arg1("a/b/c");
- static std::string arg2("d/e/f");
- static char *argv[] = {exe.data(), arg1.data(), arg2.data()};
- auto hdfs_tool = std::make_unique<T>(argc, argv);
- hdfs_tool->SetExpectations(Pass2Paths<T>, {arg1, arg2});
- return hdfs_tool;
- }
- template <class T> std::unique_ptr<T> Pass3Paths() {
- constexpr auto argc = 4;
- static std::string exe("hdfs_tool_name");
- static std::string arg1("a/b/c");
- static std::string arg2("d/e/f");
- static std::string arg3("g/h/i");
- static char *argv[] = {exe.data(), arg1.data(), arg2.data(), arg3.data()};
- auto hdfs_tool = std::make_unique<T>(argc, argv);
- hdfs_tool->SetExpectations(Pass3Paths<T>, {arg1, arg2, arg3});
- return hdfs_tool;
- }
- template <class T> std::unique_ptr<T> PassNOptAndAPath() {
- constexpr auto argc = 4;
- static std::string exe("hdfs_tool_name");
- static std::string arg1("-n");
- static std::string arg2("some_name");
- static std::string arg3("g/h/i");
- static char *argv[] = {exe.data(), arg1.data(), arg2.data(), arg3.data()};
- auto hdfs_tool = std::make_unique<T>(argc, argv);
- hdfs_tool->SetExpectations(PassNOptAndAPath<T>, {arg1, arg2, arg3});
- return hdfs_tool;
- }
- template <class T> std::unique_ptr<T> PassOwnerAndAPath() {
- constexpr auto argc = 3;
- static std::string exe("hdfs_tool_name");
- static std::string arg1("new_owner:new_group");
- static std::string arg2("g/h/i");
- static char *argv[] = {exe.data(), arg1.data(), arg2.data()};
- auto hdfs_tool = std::make_unique<T>(argc, argv);
- hdfs_tool->SetExpectations(PassOwnerAndAPath<T>, {arg1, arg2});
- return hdfs_tool;
- }
- template <class T> std::unique_ptr<T> PassRecursiveOwnerAndAPath() {
- constexpr auto argc = 4;
- static std::string exe("hdfs_tool_name");
- static std::string arg1("-R");
- static std::string arg2("new_owner:new_group");
- static std::string arg3("g/h/i");
- static char *argv[] = {exe.data(), arg1.data(), arg2.data(), arg3.data()};
- auto hdfs_tool = std::make_unique<T>(argc, argv);
- hdfs_tool->SetExpectations(PassRecursiveOwnerAndAPath<T>, {arg1, arg2, arg3});
- return hdfs_tool;
- }
- template <class T> std::unique_ptr<T> PassPermissionsAndAPath() {
- constexpr auto argc = 3;
- static std::string exe("hdfs_tool_name");
- static std::string arg1("757");
- static std::string arg2("g/h/i");
- static char *argv[] = {exe.data(), arg1.data(), arg2.data()};
- auto hdfs_tool = std::make_unique<T>(argc, argv);
- hdfs_tool->SetExpectations(PassPermissionsAndAPath<T>, {arg1, arg2});
- return hdfs_tool;
- }
- template <class T> std::unique_ptr<T> PassRecursivePermissionsAndAPath() {
- constexpr auto argc = 4;
- static std::string exe("hdfs_tool_name");
- static std::string arg1("-R");
- static std::string arg2("757");
- static std::string arg3("g/h/i");
- static char *argv[] = {exe.data(), arg1.data(), arg2.data(), arg3.data()};
- auto hdfs_tool = std::make_unique<T>(argc, argv);
- hdfs_tool->SetExpectations(PassRecursivePermissionsAndAPath<T>,
- {arg1, arg2, arg3});
- return hdfs_tool;
- }
- template <class T> std::unique_ptr<T> PassQOpt() {
- constexpr auto argc = 2;
- static std::string exe("hdfs_tool_name");
- static std::string arg1("-q");
- static char *argv[] = {exe.data(), arg1.data()};
- auto hdfs_tool = std::make_unique<T>(argc, argv);
- hdfs_tool->SetExpectations(PassQOpt<T>, {arg1});
- return hdfs_tool;
- }
- template <class T> std::unique_ptr<T> PassQOptAndPath() {
- constexpr auto argc = 3;
- static std::string exe("hdfs_tool_name");
- static std::string arg1("-q");
- static std::string arg2("a/b/c");
- static char *argv[] = {exe.data(), arg1.data(), arg2.data()};
- auto hdfs_tool = std::make_unique<T>(argc, argv);
- hdfs_tool->SetExpectations(PassQOptAndPath<T>, {arg1, arg2});
- return hdfs_tool;
- }
- template <class T> std::unique_ptr<T> PassPOpt() {
- constexpr auto argc = 2;
- static std::string exe("hdfs_tool_name");
- static std::string arg1("-p");
- static char *argv[] = {exe.data(), arg1.data()};
- auto hdfs_tool = std::make_unique<T>(argc, argv);
- hdfs_tool->SetExpectations(PassPOpt<T>, {arg1});
- return hdfs_tool;
- }
- template <class T> std::unique_ptr<T> PassMOpt() {
- constexpr auto argc = 2;
- static std::string exe("hdfs_tool_name");
- static std::string arg1("-m");
- static char *argv[] = {exe.data(), arg1.data()};
- auto hdfs_tool = std::make_unique<T>(argc, argv);
- hdfs_tool->SetExpectations(PassMOpt<T>, {arg1});
- return hdfs_tool;
- }
- template <class T> std::unique_ptr<T> PassFOpt() {
- constexpr auto argc = 2;
- static std::string exe("hdfs_tool_name");
- static std::string arg1("-f");
- static char *argv[] = {exe.data(), arg1.data()};
- auto hdfs_tool = std::make_unique<T>(argc, argv);
- hdfs_tool->SetExpectations(PassFOpt<T>, {arg1});
- return hdfs_tool;
- }
- template <class T> std::unique_ptr<T> PassPOptAndPath() {
- constexpr auto argc = 3;
- static std::string exe("hdfs_tool_name");
- static std::string arg1("-p");
- static std::string arg2("a/b/c");
- static char *argv[] = {exe.data(), arg1.data(), arg2.data()};
- auto hdfs_tool = std::make_unique<T>(argc, argv);
- hdfs_tool->SetExpectations(PassPOptAndPath<T>, {arg1, arg2});
- return hdfs_tool;
- }
- template <class T> std::unique_ptr<T> PassMOptPermissionsAndAPath() {
- constexpr auto argc = 4;
- static std::string exe("hdfs_tool_name");
- static std::string arg1("-m");
- static std::string arg2("757");
- static std::string arg3("g/h/i");
- static char *argv[] = {exe.data(), arg1.data(), arg2.data(), arg3.data()};
- auto hdfs_tool = std::make_unique<T>(argc, argv);
- hdfs_tool->SetExpectations(PassMOptPermissionsAndAPath<T>,
- {arg1, arg2, arg3});
- return hdfs_tool;
- }
- template <class T> std::unique_ptr<T> PassMPOptsPermissionsAndAPath() {
- constexpr auto argc = 5;
- static std::string exe("hdfs_tool_name");
- static std::string arg1("-m");
- static std::string arg2("757");
- static std::string arg3("-p");
- static std::string arg4("g/h/i");
- static char *argv[] = {exe.data(), arg1.data(), arg2.data(), arg3.data(),
- arg4.data()};
- auto hdfs_tool = std::make_unique<T>(argc, argv);
- hdfs_tool->SetExpectations(PassMPOptsPermissionsAndAPath<T>,
- {arg1, arg2, arg3, arg4});
- return hdfs_tool;
- }
- template <class T> std::unique_ptr<T> PassNStrMNumAndAPath() {
- constexpr auto argc = 6;
- static std::string exe("hdfs_tool_name");
- static std::string arg1("-n");
- static std::string arg2("some_str");
- static std::string arg3("-m");
- static std::string arg4("757");
- static std::string arg5("some/path");
- static char *argv[] = {exe.data(), arg1.data(), arg2.data(),
- arg3.data(), arg4.data(), arg5.data()};
- auto hdfs_tool = std::make_unique<T>(argc, argv);
- hdfs_tool->SetExpectations(PassNStrMNumAndAPath<T>,
- {arg1, arg2, arg3, arg4, arg5});
- return hdfs_tool;
- }
- template <class T> std::unique_ptr<T> PassNOpt() {
- constexpr auto argc = 2;
- static std::string exe("hdfs_tool_name");
- static std::string arg1("-n");
- static char *argv[] = {exe.data(), arg1.data()};
- auto hdfs_tool = std::make_unique<T>(argc, argv);
- hdfs_tool->SetExpectations(PassNOpt<T>, {arg1});
- return hdfs_tool;
- }
- #endif
|