Added test for --modules_dir flag.

Review: https://reviews.apache.org/r/47905/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/4dfdc875
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/4dfdc875
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/4dfdc875

Branch: refs/heads/master
Commit: 4dfdc8757946438610356476ba3f556a4c0a6b6f
Parents: c7600b7
Author: Kapil Arya <[email protected]>
Authored: Mon May 30 19:25:13 2016 +0200
Committer: Till Toenshoff <[email protected]>
Committed: Mon May 30 19:59:57 2016 +0200

----------------------------------------------------------------------
 src/tests/module_tests.cpp | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/4dfdc875/src/tests/module_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/module_tests.cpp b/src/tests/module_tests.cpp
index 950d8e4..54a22e3 100644
--- a/src/tests/module_tests.cpp
+++ b/src/tests/module_tests.cpp
@@ -16,12 +16,16 @@
 
 #include <mesos/module.hpp>
 
+#include <mesos/module/hook.hpp>
 #include <mesos/module/isolator.hpp>
 #include <mesos/module/module.hpp>
 
 #include <mesos/slave/isolator.hpp>
 
 #include <stout/dynamiclibrary.hpp>
+#include <stout/os.hpp>
+#include <stout/path.hpp>
+#include <stout/stringify.hpp>
 
 #include "common/parse.hpp"
 #include "examples/test_module.hpp"
@@ -193,6 +197,40 @@ TEST_F(ModuleTest, ExampleModuleLoadTest)
 }
 
 
+// Test that we can load module manifests from modules-dir.
+TEST_F(ModuleTest, ModulesDirTest)
+{
+  string modulesDir = path::join(os::getcwd(), "modules_dir");
+  ASSERT_SOME(os::mkdir(modulesDir));
+
+  // Create a JSON file for the example module.
+  EXPECT_SOME(os::write(
+      path::join(modulesDir, "default_module.json"),
+      stringify(JSON::protobuf(defaultModules))));
+
+  // Let's also create another JSON file for the example module.
+  EXPECT_SOME(os::write(
+      path::join(modulesDir, "dup_default_module.json"),
+      stringify(JSON::protobuf(defaultModules))));
+
+  // Create a JSON for the 'TestHook' module.
+  Modules extraModules = getModules("testhook", "org_apache_mesos_TestHook");
+
+  EXPECT_SOME(os::write(
+      path::join(modulesDir, "extra_module.json"),
+      stringify(JSON::protobuf(extraModules))));
+
+  // Now load modules using the modules directory.
+  EXPECT_SOME(ModuleManager::load(modulesDir));
+
+  EXPECT_TRUE(ModuleManager::contains<TestModule>(DEFAULT_MODULE_NAME));
+  EXPECT_TRUE(ModuleManager::contains<Hook>("org_apache_mesos_TestHook"));
+
+  // Perform cleanup.
+  EXPECT_SOME(os::rmdir(modulesDir));
+}
+
+
 // Test passing parameter without value.
 TEST_F(ModuleTest, ParameterWithoutValue)
 {

Reply via email to