Added provisioner TestStore.

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


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

Branch: refs/heads/master
Commit: 6b8d8339b07591a475f4571f3524afd18b2dda26
Parents: ecc28e1
Author: Timothy Chen <[email protected]>
Authored: Tue Oct 27 09:33:22 2015 +0000
Committer: Timothy Chen <[email protected]>
Committed: Thu Nov 5 18:16:12 2015 -0800

----------------------------------------------------------------------
 src/tests/containerizer/store.hpp | 94 ++++++++++++++++++++++++++++++++++
 1 file changed, 94 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/6b8d8339/src/tests/containerizer/store.hpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/store.hpp 
b/src/tests/containerizer/store.hpp
new file mode 100644
index 0000000..974d91e
--- /dev/null
+++ b/src/tests/containerizer/store.hpp
@@ -0,0 +1,94 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TEST_STORE_HPP__
+#define __TEST_STORE_HPP__
+
+#include <gmock/gmock.h>
+
+#include <stout/option.hpp>
+
+#include <process/future.hpp>
+#include <process/shared.hpp>
+
+#include "slave/containerizer/mesos/provisioner/store.hpp"
+
+#include "tests/containerizer/rootfs.hpp"
+
+namespace mesos {
+namespace internal {
+namespace tests {
+
+class TestStore : public slave::Store
+{
+public:
+  TestStore(const hashmap<std::string, process::Shared<Rootfs>>& _rootfses)
+      : rootfses(_rootfses)
+  {
+    using testing::_;
+    using testing::DoDefault;
+    using testing::Invoke;
+
+    ON_CALL(*this, recover())
+      .WillByDefault(Invoke(this, &TestStore::unmocked_recover));
+    EXPECT_CALL(*this, recover())
+      .WillRepeatedly(DoDefault());
+
+    ON_CALL(*this, get(_))
+      .WillByDefault(Invoke(this, &TestStore::unmocked_get));
+    EXPECT_CALL(*this, get(_))
+      .WillRepeatedly(DoDefault());
+  }
+
+  MOCK_METHOD0(
+      recover,
+      process::Future<Nothing>());
+
+  MOCK_METHOD1(
+      get,
+      process::Future<std::vector<std::string>>(
+          const Image& image));
+
+  process::Future<Nothing> unmocked_recover()
+  {
+    return Nothing();
+  }
+
+  process::Future<std::vector<std::string>> unmocked_get(const Image& image)
+  {
+    if (!image.has_appc()) {
+      return process::Failure("Expecting APPC image");
+    }
+
+    Option<process::Shared<Rootfs>> rootfs = rootfses.at(image.appc().name());
+    if (rootfs.isSome()) {
+      return std::vector<std::string>({rootfs.get()->root});
+    }
+
+    return process::Failure("Cannot find image '" + image.appc().name());
+  }
+
+private:
+  hashmap<std::string, process::Shared<Rootfs>> rootfses;
+};
+
+} // namespace tests {
+} // namespace internal {
+} // namespace mesos {
+
+#endif // __TEST_STORE_HPP__

Reply via email to