Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 1 | /* |
| 2 | Copyright (c) 2018-2019 Nokia. |
| 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 | #include <type_traits> |
| 18 | #include <gtest/gtest.h> |
| 19 | #include <gmock/gmock.h> |
| 20 | #include "private/redis/asyncredisreply.hpp" |
| 21 | #include "private/redis/redisgeneral.hpp" |
| 22 | #include "private/tst/redisreplybuilder.hpp" |
| 23 | |
| 24 | using namespace shareddatalayer; |
| 25 | using namespace shareddatalayer::redis; |
| 26 | using namespace shareddatalayer::tst; |
| 27 | using namespace testing; |
| 28 | |
| 29 | namespace |
| 30 | { |
| 31 | class RedisGeneralTest: public testing::Test |
| 32 | { |
| 33 | public: |
| 34 | RedisReplyBuilder redisReplyBuilder; |
| 35 | RedisGeneralTest(): |
| 36 | redisReplyBuilder { } |
| 37 | { |
| 38 | } |
| 39 | |
| 40 | virtual ~RedisGeneralTest() |
| 41 | { |
| 42 | } |
| 43 | }; |
| 44 | } |
| 45 | |
| 46 | TEST_F(RedisGeneralTest, ParseCommandListReplySuccessfully) |
| 47 | { |
| 48 | std::set<std::string> requiredRedisModuleCommands(getRequiredRedisModuleCommands()); |
| 49 | const AsyncRedisReply replyHavingAllRequiredCommands(redisReplyBuilder.buildCommandListQueryReply()); |
| 50 | std::set<std::string> parsedRedisModuleCommands(parseCommandListReply(replyHavingAllRequiredCommands)); |
| 51 | EXPECT_THAT(requiredRedisModuleCommands, ContainerEq(parsedRedisModuleCommands)); |
| 52 | } |
| 53 | |
| 54 | TEST_F(RedisGeneralTest, CheckRedisModuleCommandsAllCommandsFound) |
| 55 | { |
| 56 | std::set<std::string> requiredRedisModuleCommands(getRequiredRedisModuleCommands()); |
| 57 | EXPECT_TRUE(checkRedisModuleCommands(requiredRedisModuleCommands)); |
| 58 | } |
| 59 | |
| 60 | TEST_F(RedisGeneralTest, CheckRedisModuleCommandsOneCommandMissing) |
| 61 | { |
| 62 | std::set<std::string> requiredRedisModuleCommands(getRequiredRedisModuleCommands()); |
| 63 | auto commandToRemove = --requiredRedisModuleCommands.end(); |
| 64 | requiredRedisModuleCommands.erase(commandToRemove); |
| 65 | EXPECT_FALSE(checkRedisModuleCommands(requiredRedisModuleCommands)); |
| 66 | } |
| 67 | |
| 68 | TEST_F(RedisGeneralTest, CheckRedisModuleCommandsAllCommandsMissing) |
| 69 | { |
| 70 | std::set<std::string> requiredRedisModuleCommands({}); |
| 71 | EXPECT_FALSE(checkRedisModuleCommands(requiredRedisModuleCommands)); |
| 72 | } |