/test/chsgen/checksumgenerator.cpp

https://gitlab.com/github-cloud-corporation/cynara · C++ · 121 lines · 56 code · 23 blank · 42 comment · 2 complexity · b68d410ac56f3e0894fa0d3570ad9d0c MD5 · raw file

  1. /*
  2. * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License
  15. */
  16. /**
  17. * @file test/chsgen/checksumgenerator.cpp
  18. * @author Pawel Wieczorek <p.wieczorek2@samsung.com>
  19. * @version 1.0
  20. * @brief Tests of ChecksumGenerator
  21. */
  22. #include <string>
  23. #include <cynara-error.h>
  24. #include <config/PathConfig.h>
  25. #include <chsgen/ChecksumGenerator.h>
  26. #include "ChsgenCommandlineTest.h"
  27. namespace {
  28. const std::string execName("./cynara-db-chsgen");
  29. const std::string &backupFilenameSuffix = Cynara::PathConfig::StoragePath::backupFilenameSuffix;
  30. const char fieldSeparator(Cynara::PathConfig::StoragePath::fieldSeparator);
  31. } // namespace
  32. /**
  33. * @brief Verify if passing no filenames to checksum generator returns error message
  34. * @test Expected result:
  35. * - CYNARA_API_UNKNOWN_ERROR returned from checksum generator
  36. * - empty output stream
  37. * - message from caught exception in error stream
  38. */
  39. TEST_F(ChsgenCommandlineTest, noFile) {
  40. using ::testing::StartsWith;
  41. std::string err;
  42. std::string out;
  43. clearOutput();
  44. prepare_argv({ execName });
  45. Cynara::ChecksumGenerator chsgen(this->argc(), this->argv());
  46. const auto ret = chsgen.run();
  47. getOutput(out, err);
  48. ASSERT_EQ(CYNARA_API_UNKNOWN_ERROR, ret);
  49. ASSERT_TRUE(out.empty());
  50. ASSERT_THAT(err, StartsWith("File not found: " + std::string()));
  51. }
  52. /**
  53. * @brief Verify if checksum generator returns valid records
  54. * @test Expected result:
  55. * - CYNARA_API_SUCCESS returned from checksum generator
  56. * - valid record in output stream
  57. * - empty error stream
  58. */
  59. TEST_F(ChsgenCommandlineTest, recordGeneration) {
  60. using ::testing::StartsWith;
  61. std::string err;
  62. std::string out;
  63. for (const std::string &file : { "_", "buckets" }) {
  64. clearOutput();
  65. prepare_argv({ execName, Cynara::PathConfig::testsPath + "/db3/" + file });
  66. SCOPED_TRACE(file);
  67. Cynara::ChecksumGenerator chsgen(this->argc(), this->argv());
  68. const auto ret = chsgen.run();
  69. getOutput(out, err);
  70. ASSERT_EQ(CYNARA_API_SUCCESS, ret);
  71. ASSERT_THAT(out, StartsWith(file + fieldSeparator + "$1$"));
  72. ASSERT_TRUE(err.empty());
  73. }
  74. }
  75. /**
  76. * @brief Verify if checksum generator returns valid records for backup files
  77. * @test Expected result:
  78. * - CYNARA_API_SUCCESS returned from checksum generator
  79. * - valid record in output stream
  80. * - empty error stream
  81. */
  82. TEST_F(ChsgenCommandlineTest, suffixErasing) {
  83. using ::testing::StartsWith;
  84. std::string err;
  85. std::string out;
  86. for (const std::string &file : { "_", "_additional", "buckets" }) {
  87. clearOutput();
  88. prepare_argv({ execName,
  89. Cynara::PathConfig::testsPath + "/db6/" + file + backupFilenameSuffix });
  90. SCOPED_TRACE(file);
  91. Cynara::ChecksumGenerator chsgen(this->argc(), this->argv());
  92. const auto ret = chsgen.run();
  93. getOutput(out, err);
  94. ASSERT_EQ(CYNARA_API_SUCCESS, ret);
  95. ASSERT_THAT(out, StartsWith(file + fieldSeparator + "$1$"));
  96. ASSERT_TRUE(err.empty());
  97. }
  98. }