X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=tst%2Fconfigurationreader_test.cpp;h=4e730f04eb4d7acf0ba5d3b4202ed79b82ee58c1;hb=refs%2Fchanges%2F28%2F6128%2F4;hp=8120052193e3d7918becc0d312e614737f9b773e;hpb=ef2bf51d04aaf01fa0cabdcaf905b23423067662;p=ric-plt%2Fsdl.git diff --git a/tst/configurationreader_test.cpp b/tst/configurationreader_test.cpp index 8120052..4e730f0 100644 --- a/tst/configurationreader_test.cpp +++ b/tst/configurationreader_test.cpp @@ -14,6 +14,11 @@ limitations under the License. */ +/* + * This source code is part of the near-RT RIC (RAN Intelligent Controller) + * platform project (RICP). +*/ + #include #include #include @@ -62,6 +67,16 @@ namespace EXPECT_CALL(databaseConfigurationMock, checkAndApplyServerAddress(address)); } + void expectSentinelAddressConfigurationCheckAndApply(const std::string& address) + { + EXPECT_CALL(databaseConfigurationMock, checkAndApplySentinelAddress(address)); + } + + void expectSentinelMasterNameConfigurationCheckAndApply(const std::string& address) + { + EXPECT_CALL(databaseConfigurationMock, checkAndApplySentinelMasterName(address)); + } + void expectDatabaseConfigurationIsEmpty_returnFalse() { EXPECT_CALL(databaseConfigurationMock, isEmpty()). @@ -723,6 +738,9 @@ class ConfigurationReaderEnvironmentVariableTest: public ConfigurationReaderBase public: std::string dbHostEnvVariableValue; std::string dbPortEnvVariableValue; + std::string sentinelPortEnvVariableValue; + std::string sentinelMasterNameEnvVariableValue; + std::string dbClusterAddrListEnvVariableValue; std::istringstream is{R"JSON( { "database": @@ -757,8 +775,11 @@ public: try { EXPECT_CALL(systemMock, getenv(_)) - .Times(2) + .Times(5) .WillOnce(Return(dbHostEnvVariableValue.c_str())) + .WillOnce(Return(nullptr)) + .WillOnce(Return(nullptr)) + .WillOnce(Return(nullptr)) .WillOnce(Return(nullptr)); initializeReaderWithoutDirectories(); configurationReader->readDatabaseConfiguration(databaseConfigurationMock); @@ -779,6 +800,9 @@ TEST_F(ConfigurationReaderEnvironmentVariableTest, EnvironmentConfigurationCanOv expectGetEnvironmentString(dbHostEnvVariableValue.c_str()); dbPortEnvVariableValue = "12345"; expectGetEnvironmentString(dbPortEnvVariableValue.c_str()); + expectGetEnvironmentString(nullptr); //SENTINEL_PORT_ENV_VAR_NAME + expectGetEnvironmentString(nullptr); //SENTINEL_MASTER_NAME_ENV_VAR_NAME + expectGetEnvironmentString(nullptr); //DB_CLUSTER_ENV_VAR_NAME expectDbTypeConfigurationCheckAndApply("redis-standalone"); expectDBServerAddressConfigurationCheckAndApply("unknownAddress.local:12345"); @@ -792,7 +816,10 @@ TEST_F(ConfigurationReaderEnvironmentVariableTest, EnvironmentConfigurationWitho InSequence dummy; dbHostEnvVariableValue = "server.local"; expectGetEnvironmentString(dbHostEnvVariableValue.c_str()); - expectGetEnvironmentString(nullptr); + expectGetEnvironmentString(nullptr); //DB_PORT_ENV_VAR_NAME + expectGetEnvironmentString(nullptr); //SENTINEL_PORT_ENV_VAR_NAME + expectGetEnvironmentString(nullptr); //SENTINEL_MASTER_NAME_ENV_VAR_NAME + expectGetEnvironmentString(nullptr); //DB_CLUSTER_ENV_VAR_NAME expectDbTypeConfigurationCheckAndApply("redis-standalone"); expectDBServerAddressConfigurationCheckAndApply("server.local"); @@ -817,10 +844,57 @@ TEST_F(ConfigurationReaderEnvironmentVariableTest, EnvironmentConfigurationAccep InSequence dummy; dbHostEnvVariableValue = "[2001::123]:12345"; expectGetEnvironmentString(dbHostEnvVariableValue.c_str()); - expectGetEnvironmentString(nullptr); + expectGetEnvironmentString(nullptr); //DB_PORT_ENV_VAR_NAME + expectGetEnvironmentString(nullptr); //SENTINEL_PORT_ENV_VAR_NAME + expectGetEnvironmentString(nullptr); //SENTINEL_MASTER_NAME_ENV_VAR_NAME + expectGetEnvironmentString(nullptr); //DB_CLUSTER_ENV_VAR_NAME expectDbTypeConfigurationCheckAndApply("redis-standalone"); expectDBServerAddressConfigurationCheckAndApply("[2001::123]:12345"); initializeReaderWithoutDirectories(); configurationReader->readDatabaseConfiguration(databaseConfigurationMock); } + +TEST_F(ConfigurationReaderEnvironmentVariableTest, EnvironmentConfigurationWithSentinel) +{ + InSequence dummy; + dbHostEnvVariableValue = "sentinelAddress.local"; + expectGetEnvironmentString(dbHostEnvVariableValue.c_str()); + dbPortEnvVariableValue = "1111"; + expectGetEnvironmentString(dbPortEnvVariableValue.c_str()); + sentinelPortEnvVariableValue = "2222"; + expectGetEnvironmentString(sentinelPortEnvVariableValue.c_str()); + sentinelMasterNameEnvVariableValue = "mymaster"; + expectGetEnvironmentString(sentinelMasterNameEnvVariableValue.c_str()); + expectGetEnvironmentString(nullptr); //DB_CLUSTER_ENV_VAR_NAME + + expectDbTypeConfigurationCheckAndApply("redis-sentinel"); + expectSentinelAddressConfigurationCheckAndApply("sentinelAddress.local:2222"); + expectSentinelMasterNameConfigurationCheckAndApply(sentinelMasterNameEnvVariableValue); + initializeReaderWithoutDirectories(); + configurationReader->readDatabaseConfiguration(databaseConfigurationMock); +} + +TEST_F(ConfigurationReaderEnvironmentVariableTest, EnvironmentConfigurationWithSentinelAndClusterConfiguration) +{ + InSequence dummy; + dbHostEnvVariableValue = "address-0.local"; + expectGetEnvironmentString(dbHostEnvVariableValue.c_str()); + dbPortEnvVariableValue = "1111"; + expectGetEnvironmentString(dbPortEnvVariableValue.c_str()); + sentinelPortEnvVariableValue = "2222"; + expectGetEnvironmentString(sentinelPortEnvVariableValue.c_str()); + sentinelMasterNameEnvVariableValue = "mymaster"; + expectGetEnvironmentString(sentinelMasterNameEnvVariableValue.c_str()); + dbClusterAddrListEnvVariableValue = "address-0.local,address-1.local,address-2.local"; + expectGetEnvironmentString(dbClusterAddrListEnvVariableValue.c_str()); + + expectDbTypeConfigurationCheckAndApply("sdl-cluster"); + expectDBServerAddressConfigurationCheckAndApply("address-0.local"); + expectDBServerAddressConfigurationCheckAndApply("address-1.local"); + expectDBServerAddressConfigurationCheckAndApply("address-2.local"); + expectSentinelAddressConfigurationCheckAndApply("address-0.local:2222"); + expectSentinelMasterNameConfigurationCheckAndApply(sentinelMasterNameEnvVariableValue); + initializeReaderWithoutDirectories(); + configurationReader->readDatabaseConfiguration(databaseConfigurationMock); +}