version 3.0.3 fix Docker file error and add logging to config file and updated testing 86/1886/1
authoraa7133@att.com <aa7133@att.com>
Sun, 1 Dec 2019 16:21:20 +0000 (18:21 +0200)
committeraa7133@att.com <aa7133@att.com>
Sun, 1 Dec 2019 16:21:40 +0000 (18:21 +0200)
Change-Id: Ic7b01c12a56cbbced19e386ef19460512d6dfa13
Signed-off-by: aa7133@att.com <aa7133@att.com>
RIC-E2-TERMINATION/Dockerfile
RIC-E2-TERMINATION/ReadConfigFile.h
RIC-E2-TERMINATION/TEST/ConfigurationFileTest/testConfigFile.cpp

index 6b65c7c..ad9eb3c 100644 (file)
@@ -41,7 +41,7 @@ RUN apt-get install -y autoconf gawk libtool automake pkg-config autoconf-archiv
     && cd cxxopts && mkdir build && cd build && cmake .. && make install && ldconfig \
     && cd /opt/e2/RIC-E2-TERMINATION/3rdparty \
     && git clone https://github.com/Tencent/rapidjson.git && cd rapidjson \
-    && cd build && cmake .. && make install && ldconfig \
+    && mkdir build && cd build && cmake .. && make install && ldconfig \
     && cd /opt/e2/RIC-E2-TERMINATION/3rdparty \
     && wget --content-disposition https://github.com/cgreen-devs/cgreen/releases/download/1.2.0/cgreen_1.2.0_amd64.deb \
     && dpkg -i cgreen_1.2.0_amd64.deb \
index 941be6e..3f45e8c 100644 (file)
@@ -30,6 +30,7 @@
 #include <cstdlib>
 
 #include <boost/algorithm/string.hpp>
+#include <mdclog/mdclog.h>
 
 using namespace std;
 
@@ -41,8 +42,7 @@ public:
     int openConfigFile(std::string const& configFile) {
         std::ifstream file(configFile.c_str());
         if (!file) {  // file not found
-            //perror(configFile.c_str());
-            //mdclog_write(MDCLOG_ERR, "File: %s, failed to open", configFile.c_str());
+            mdclog_write(MDCLOG_ERR, "File: %s, failed to open", configFile.c_str());
             return -1;
         }
         std::string line;
@@ -57,9 +57,18 @@ public:
             }
 
             auto leftHand = line.find('=');
+            if (leftHand == std::string::npos) {
+                mdclog_write(MDCLOG_ERR, "problematic entry: %s  ", line.c_str());
+                continue;
+            }
             auto name = line.substr(0,leftHand);
             trim(name);
             auto value = line.substr(leftHand+1);
+            if (value.length() == 0) {
+                mdclog_write(MDCLOG_ERR, "problematic entry: %s no value ", line.c_str());
+                continue;
+
+            }
             trim(value);
             //cout << "entry = " << name << " value = " << value  << endl;
             entries[name] = value;
index dc211d5..296cc94 100644 (file)
@@ -44,21 +44,21 @@ Ensure(Cgreen, fileNotExist) {
 
 Ensure(Cgreen, fileExists) {
     ReadConfigFile  conf {};
-    assert_that(conf.openConfigFile("config") == 0);
+    assert_that(conf.openConfigFile("config/config.conf") == 0);
 }
 
 Ensure(Cgreen, goodparams) {
     ReadConfigFile  conf {};
-    assert_that(conf.openConfigFile("config") == 0);
+    assert_that(conf.openConfigFile("config/config.conf") == 0);
     assert_that(conf.getIntValue("nano") == 38000);
     assert_that(conf.getStringValue("loglevel") == "info");
-    assert_that(conf.getStringValue("volume") == ".");
+    assert_that(conf.getStringValue("volume") == "log");
 
 }
 
 Ensure(Cgreen, badParams) {
     ReadConfigFile  conf {};
-    assert_that(conf.openConfigFile("config") == 0);
+    assert_that(conf.openConfigFile("config/config.conf") == 0);
     assert_that(conf.getIntValue("nano") != 38002);
     assert_that(conf.getStringValue("loglevel") != "");
     assert_that(conf.getStringValue("volume") != "bob");
@@ -67,12 +67,17 @@ Ensure(Cgreen, badParams) {
 
 Ensure(Cgreen, wrongType) {
     ReadConfigFile  conf {};
-    assert_that(conf.openConfigFile("config") == 0);
+    assert_that(conf.openConfigFile("config/config.conf") == 0);
     assert_that(conf.getStringValue("nano") != "debug");
     assert_that(conf.getIntValue("loglevel") != 3);
     assert_that(conf.getDoubleValue("loglevel") != 3.0);
 }
 
+Ensure(Cgreen, badValues) {
+    ReadConfigFile  conf {};
+    assert_that(conf.openConfigFile("config/config.bad") == 0);
+}
+
 
 int main(const int argc, char **argv) {
     mdclog_severity_t loglevel = MDCLOG_INFO;
@@ -87,6 +92,7 @@ int main(const int argc, char **argv) {
     add_test_with_context(suite, Cgreen, goodparams);
     add_test_with_context(suite, Cgreen, badParams);
     add_test_with_context(suite, Cgreen, wrongType);
+    add_test_with_context(suite, Cgreen, badValues);
 
     return cgreen::run_test_suite(suite, create_text_reporter());