/test/storage/storage/buckets.cpp

https://gitlab.com/admin-github-cloud/cynara · C++ · 97 lines · 51 code · 23 blank · 23 comment · 0 complexity · c8d8e4f540daec646a7777464916ed67 MD5 · raw file

  1. /*
  2. * Copyright (c) 2014 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/storage/storage/buckets.cpp
  18. * @author Aleksander Zdyb <a.zdyb@samsung.com>
  19. * @version 1.0
  20. * @brief Tests of buckets in Storage
  21. */
  22. #include <gtest/gtest.h>
  23. #include <gmock/gmock.h>
  24. #include "types/PolicyType.h"
  25. #include "types/PolicyKey.h"
  26. #include "types/PolicyResult.h"
  27. #include "types/PolicyCollection.h"
  28. #include "types/pointers.h"
  29. #include "exceptions/DefaultBucketDeletionException.h"
  30. #include "storage/Storage.h"
  31. #include "storage/StorageBackend.h"
  32. #include "fakestoragebackend.h"
  33. #include "../../helpers.h"
  34. #include <memory>
  35. #include <tuple>
  36. using namespace Cynara;
  37. TEST(storage, addBucket) {
  38. using ::testing::Return;
  39. FakeStorageBackend backend;
  40. Cynara::Storage storage(backend);
  41. PolicyBucketId bucketId = "test-bucket";
  42. PolicyResult defaultPolicy(PredefinedPolicyType::DENY);
  43. EXPECT_CALL(backend, hasBucket(bucketId)).WillOnce(Return(false));
  44. EXPECT_CALL(backend, createBucket(bucketId, defaultPolicy));
  45. storage.addOrUpdateBucket(bucketId, defaultPolicy);
  46. }
  47. TEST(storage, updateBucket) {
  48. using ::testing::Return;
  49. FakeStorageBackend backend;
  50. Cynara::Storage storage(backend);
  51. PolicyBucketId bucketId = "test-bucket";
  52. PolicyResult defaultPolicy(PredefinedPolicyType::DENY);
  53. EXPECT_CALL(backend, hasBucket(bucketId)).WillOnce(Return(true));
  54. EXPECT_CALL(backend, updateBucket(bucketId, defaultPolicy));
  55. storage.addOrUpdateBucket(bucketId, defaultPolicy);
  56. }
  57. // Cannot delete default bucket
  58. TEST(storage, deleteDefaultBucket) {
  59. FakeStorageBackend backend;
  60. Cynara::Storage storage(backend);
  61. ASSERT_THROW(
  62. storage.deleteBucket(defaultPolicyBucketId),
  63. DefaultBucketDeletionException
  64. );
  65. }
  66. // Delete bucket and all policies linking to it
  67. TEST(storage, deleteBucket) {
  68. FakeStorageBackend backend;
  69. Cynara::Storage storage(backend);
  70. PolicyBucketId bucketId = "test-bucket";
  71. EXPECT_CALL(backend, deleteLinking(bucketId));
  72. EXPECT_CALL(backend, deleteBucket(bucketId));
  73. storage.deleteBucket(bucketId);
  74. }