2 Copyright (c) 2018-2019 Nokia.
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
8 http://www.apache.org/licenses/LICENSE-2.0
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.
18 * This source code is part of the near-RT RIC (RAN Intelligent Controller)
19 * platform project (RICP).
22 #include <arpa/inet.h>
23 #include <type_traits>
24 #include <gtest/gtest.h>
25 #include <gmock/gmock.h>
26 #include "private/redis/databaseinfo.hpp"
28 using namespace shareddatalayer;
29 using namespace shareddatalayer::redis;
30 using namespace testing;
34 static const std::string defaultAddress = "address";
35 static const uint16_t defaultPort = 3333;
37 DatabaseInfo getDatabaseInfo(DatabaseInfo::Type type = DatabaseInfo::Type::SINGLE,
38 std::string address = defaultAddress,
39 uint16_t port = defaultPort)
41 DatabaseInfo databaseInfo;
42 databaseInfo.type = type;
43 databaseInfo.hosts.push_back({address, htons(port)});
44 databaseInfo.ns = "namespace";
48 DatabaseInfo& addHost(DatabaseInfo& databaseInfo,
52 databaseInfo.hosts.push_back({address, htons(port)});
56 class DatabaseInfoTest: public testing::Test
63 virtual ~DatabaseInfoTest()
69 TEST_F(DatabaseInfoTest, EqualAndUnequalOperatorsIdenticalInfos)
72 DatabaseInfo databaseInfo1;
73 DatabaseInfo databaseInfo2;
75 databaseInfo1 = getDatabaseInfo();
76 databaseInfo2 = getDatabaseInfo();
78 EXPECT_TRUE(databaseInfo1 == databaseInfo2);
79 EXPECT_FALSE(databaseInfo1 != databaseInfo2);
82 TEST_F(DatabaseInfoTest, EqualOperatorDifferentAmountOfHosts)
85 DatabaseInfo databaseInfo1;
86 DatabaseInfo databaseInfo2;
88 databaseInfo1 = getDatabaseInfo();
89 databaseInfo2 = getDatabaseInfo();
90 databaseInfo2 = addHost(databaseInfo2,
94 EXPECT_FALSE(databaseInfo1 == databaseInfo2);
97 TEST_F(DatabaseInfoTest, EqualOperatorHostsInDifferentOrder)
100 DatabaseInfo databaseInfo1;
101 DatabaseInfo databaseInfo2;
103 databaseInfo1 = getDatabaseInfo(DatabaseInfo::Type::SINGLE,
106 databaseInfo1 = addHost(databaseInfo1,
109 databaseInfo2 = getDatabaseInfo();
110 databaseInfo2 = addHost(databaseInfo2,
114 EXPECT_TRUE(databaseInfo1 == databaseInfo2);
117 TEST_F(DatabaseInfoTest, EqualOperatorDiffrentAddressInHosts)
120 DatabaseInfo databaseInfo1;
121 DatabaseInfo databaseInfo2;
123 databaseInfo1 = getDatabaseInfo(DatabaseInfo::Type::SINGLE,
126 databaseInfo2 = getDatabaseInfo(DatabaseInfo::Type::SINGLE,
130 EXPECT_FALSE(databaseInfo1 == databaseInfo2);
133 TEST_F(DatabaseInfoTest, EqualOperatorDiffrentPortInHosts)
136 DatabaseInfo databaseInfo1;
137 DatabaseInfo databaseInfo2;
139 databaseInfo1 = getDatabaseInfo(DatabaseInfo::Type::SINGLE,
142 databaseInfo2 = getDatabaseInfo(DatabaseInfo::Type::SINGLE,
146 EXPECT_FALSE(databaseInfo1 == databaseInfo2);