lxcpp: Added simple container tests 22/49222/4
authorJan Olszak <j.olszak@samsung.com>
Thu, 8 Oct 2015 15:26:23 +0000 (17:26 +0200)
committerDariusz Michaluk <d.michaluk@samsung.com>
Mon, 12 Oct 2015 10:04:24 +0000 (03:04 -0700)
[Feature]       setInit and setLogger tests
[Cause]         N/A
[Solution]      N/A
[Verification]  Build, install, run tests

Change-Id: I944c76aa4483c6c287a6b032b4d7456ab58f7d44

libs/lxcpp/container.hpp
libs/lxcpp/guard/guard.cpp
tests/unit_tests/lxcpp/ut-container.cpp

index 7f98aed..e3d537f 100644 (file)
@@ -59,7 +59,7 @@ public:
 
     virtual void setLogger(const logger::LogType type,
                            const logger::LogLevel level,
-                           const std::string &arg) = 0;
+                           const std::string &arg = "") = 0;
 
     virtual void setTerminalCount(const unsigned int count) = 0;
 
index 369d423..28e572a 100644 (file)
@@ -60,7 +60,7 @@ int startGuard(int channelFD)
         setProcTitle(title);
     } catch (std::exception &e) {
         // Ignore, this is optional
-        LOGW("Failed to set the guard process title");
+        LOGW("Failed to set the guard process title: " << e.what());
     }
 
     // TODO: container preparation part 1
index 35672e0..ff72b94 100644 (file)
 #include "lxcpp/lxcpp.hpp"
 #include "lxcpp/exception.hpp"
 
+#include "utils/scoped-dir.hpp"
+
+#include <memory>
+
 namespace {
 
+const std::string TEST_DIR            = "/tmp/ut-zones";
+const std::string ROOT_DIR            = TEST_DIR + "/root";
+const std::string NON_EXISTANT_BINARY = TEST_DIR + "/nonexistantpath/bash";
+const std::string LOGGER_FILE         = TEST_DIR + "/loggerFile";
+
+const std::vector<std::string> COMMAND = {"/bin/bash",
+                                          "-c", "trap exit SIGTERM; while true; do sleep 0.1; done"
+                                         };
+
 struct Fixture {
-    Fixture() {}
+    utils::ScopedDir mTestDir;
+    utils::ScopedDir mRoot;
+
+    Fixture()
+        :mTestDir(TEST_DIR),
+         mRoot(ROOT_DIR)
+    {}
     ~Fixture() {}
 };
 
@@ -44,8 +63,60 @@ using namespace lxcpp;
 
 BOOST_AUTO_TEST_CASE(ConstructorDestructor)
 {
-    auto c = createContainer("FirstTestContainer", "/");
+    auto c = createContainer("ConstructorDestructor", ROOT_DIR);
     delete c;
 }
 
+BOOST_AUTO_TEST_CASE(SetInit)
+{
+    auto c = std::unique_ptr<Container>(createContainer("SetInit", "/"));
+
+    BOOST_CHECK_THROW(c->setInit({""}), ConfigureException);
+    BOOST_CHECK_THROW(c->setInit({}), ConfigureException);
+    BOOST_CHECK_THROW(c->setInit({NON_EXISTANT_BINARY}), ConfigureException);
+
+    BOOST_CHECK_NO_THROW(c->setInit(COMMAND));
+}
+
+BOOST_AUTO_TEST_CASE(SetLogger)
+{
+    auto c = std::unique_ptr<Container>(createContainer("SetLogger", ROOT_DIR));
+
+    BOOST_CHECK_NO_THROW(c->setLogger(logger::LogType::LOG_NULL,
+                                      logger::LogLevel::DEBUG));
+    BOOST_CHECK_NO_THROW(c->setLogger(logger::LogType::LOG_JOURNALD,
+                                      logger::LogLevel::DEBUG));
+    BOOST_CHECK_NO_THROW(c->setLogger(logger::LogType::LOG_SYSLOG,
+                                      logger::LogLevel::DEBUG));
+    BOOST_CHECK_NO_THROW(c->setLogger(logger::LogType::LOG_STDERR,
+                                      logger::LogLevel::DEBUG));
+
+    BOOST_CHECK_NO_THROW(c->setLogger(logger::LogType::LOG_FILE,
+                                      logger::LogLevel::DEBUG,
+                                      LOGGER_FILE));
+    BOOST_CHECK_NO_THROW(c->setLogger(logger::LogType::LOG_PERSISTENT_FILE,
+                                      logger::LogLevel::DEBUG,
+                                      LOGGER_FILE));
+
+    BOOST_CHECK_THROW(c->setLogger(logger::LogType::LOG_FILE,
+                                   logger::LogLevel::DEBUG,
+                                   ""),
+                      BadArgument);
+
+    BOOST_CHECK_THROW(c->setLogger(logger::LogType::LOG_PERSISTENT_FILE,
+                                   logger::LogLevel::DEBUG,
+                                   ""),
+                      BadArgument);
+}
+
+// BOOST_AUTO_TEST_CASE(StartStop)
+// {
+//     auto c = std::unique_ptr<Container>(createContainer("StartStop", "/"));
+//     BOOST_CHECK_NO_THROW(c->setInit(COMMAND));
+//     BOOST_CHECK_NO_THROW(c->setLogger(logger::LogType::LOG_PERSISTENT_FILE,
+//                                       logger::LogLevel::DEBUG,
+//                                       LOGGER_FILE));
+//     BOOST_CHECK_NO_THROW(c->start());
+// }
+
 BOOST_AUTO_TEST_SUITE_END()