hdfs-chmod-mock.cc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #include <functional>
  19. #include <memory>
  20. #include <string>
  21. #include <vector>
  22. #include <gmock/gmock.h>
  23. #include <gtest/gtest.h>
  24. #include "hdfs-chmod-mock.h"
  25. #include "hdfs-chmod.h"
  26. #include "hdfs-tool-tests.h"
  27. namespace hdfs::tools::test {
  28. ChmodMock::~ChmodMock() = default;
  29. void ChmodMock::SetExpectations(
  30. std::function<std::unique_ptr<ChmodMock>()> test_case,
  31. const std::vector<std::string> &args) const {
  32. // Get the pointer to the function that defines the test case
  33. const auto test_case_func =
  34. test_case.target<std::unique_ptr<ChmodMock> (*)()>();
  35. ASSERT_NE(test_case_func, nullptr);
  36. // Set the expected method calls and their corresponding arguments for each
  37. // test case
  38. if (*test_case_func == &CallHelp<ChmodMock>) {
  39. EXPECT_CALL(*this, HandleHelp()).Times(1).WillOnce(testing::Return(true));
  40. return;
  41. }
  42. if (*test_case_func == &PassPermissionsAndAPath<ChmodMock>) {
  43. const auto arg1 = args[0];
  44. const auto arg2 = args[1];
  45. EXPECT_CALL(*this, HandlePath(arg1, false, arg2))
  46. .Times(1)
  47. .WillOnce(testing::Return(true));
  48. }
  49. if (*test_case_func == &PassRecursivePermissionsAndAPath<ChmodMock>) {
  50. const auto arg1 = args[1];
  51. const auto arg2 = args[2];
  52. EXPECT_CALL(*this, HandlePath(arg1, true, arg2))
  53. .Times(1)
  54. .WillOnce(testing::Return(true));
  55. }
  56. }
  57. } // namespace hdfs::tools::test