hdfs-du-mock.cc 2.2 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-du-mock.h"
  25. #include "hdfs-tool-tests.h"
  26. namespace hdfs::tools::test {
  27. DuMock::~DuMock() = default;
  28. void DuMock::SetExpectations(std::function<std::unique_ptr<DuMock>()> test_case,
  29. const std::vector<std::string> &args) const {
  30. // Get the pointer to the function that defines the test case
  31. const auto test_case_func = test_case.target<std::unique_ptr<DuMock> (*)()>();
  32. ASSERT_NE(test_case_func, nullptr);
  33. // Set the expected method calls and their corresponding arguments for each
  34. // test case
  35. if (*test_case_func == &CallHelp<DuMock>) {
  36. EXPECT_CALL(*this, HandleHelp()).Times(1).WillOnce(testing::Return(true));
  37. return;
  38. }
  39. if (*test_case_func == &PassAPath<DuMock>) {
  40. const auto arg1 = args[0];
  41. EXPECT_CALL(*this, HandlePath(arg1, false))
  42. .Times(1)
  43. .WillOnce(testing::Return(true));
  44. }
  45. if (*test_case_func == &PassRecursivePath<DuMock>) {
  46. const auto arg1 = args[0];
  47. const auto arg2 = args[1];
  48. ASSERT_EQ(arg1, "-R");
  49. EXPECT_CALL(*this, HandlePath(arg2, true))
  50. .Times(1)
  51. .WillOnce(testing::Return(true));
  52. }
  53. if (*test_case_func == &PassRecursive<DuMock>) {
  54. const auto arg1 = args[0];
  55. ASSERT_EQ(arg1, "-R");
  56. }
  57. }
  58. } // namespace hdfs::tools::test