blob: 2bdc377c68cb621e9a558c35656cfc9072bf1271 [file] [log] [blame]
Rolf Badorekef2bf512019-08-20 11:17:15 +03001/*
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
24using namespace shareddatalayer;
25using namespace shareddatalayer::redis;
26using namespace shareddatalayer::tst;
27using namespace testing;
28
29namespace
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
46TEST_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
54TEST_F(RedisGeneralTest, CheckRedisModuleCommandsAllCommandsFound)
55{
56 std::set<std::string> requiredRedisModuleCommands(getRequiredRedisModuleCommands());
57 EXPECT_TRUE(checkRedisModuleCommands(requiredRedisModuleCommands));
58}
59
60TEST_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
68TEST_F(RedisGeneralTest, CheckRedisModuleCommandsAllCommandsMissing)
69{
70 std::set<std::string> requiredRedisModuleCommands({});
71 EXPECT_FALSE(checkRedisModuleCommands(requiredRedisModuleCommands));
72}