Exemplo n.º 1
0
TEST_F(ExtensionsTest, test_manager_runnable) {
  // Start a testing extension manager.
  auto status = startExtensionManager(socket_path);
  EXPECT_TRUE(status.ok());
  // Call success if the Unix socket was created.
  EXPECT_TRUE(socketExists(socket_path));
}
Exemplo n.º 2
0
TEST_F(ExtensionsTest, test_extension_start) {
  auto status = startExtensionManager(socket_path);
  EXPECT_TRUE(status.ok());
  EXPECT_TRUE(socketExistsLocal(socket_path));

  // Now allow duplicates (for testing, since EM/E are the same).
  Registry::allowDuplicates(true);
  status = startExtension(socket_path, "test", "0.1", "0.0.0", "9.9.9");
  // This will not be false since we are allowing deplicate items.
  // Otherwise, starting an extension and extensionManager would fatal.
  ASSERT_TRUE(status.ok());

  // Checks for version comparisons (also used by packs).
  ASSERT_FALSE(versionAtLeast("1.1.1", "0.0.1"));
  ASSERT_TRUE(versionAtLeast("1.1.1", "1.1.1"));
  ASSERT_TRUE(versionAtLeast("1.1.1", "1.1.2"));

  // The `startExtension` internal call (exposed for testing) returns the
  // uuid of the extension in the success status.
  RouteUUID uuid = (RouteUUID)stoi(status.getMessage(), nullptr, 0);

  // We can test-wait for the extensions's socket to open.
  EXPECT_TRUE(socketExistsLocal(socket_path + "." + std::to_string(uuid)));

  // Then clean up the registry modifications.
  Registry::removeBroadcast(uuid);
  Registry::allowDuplicates(false);
}
Exemplo n.º 3
0
TEST_F(ExtensionsTest, test_extension_runnable) {
  auto status = startExtensionManager(socket_path);
  EXPECT_TRUE(status.ok());
  // Wait for the extension manager to start.
  EXPECT_TRUE(socketExists(socket_path));

  // Test the extension manager API 'ping' call.
  EXPECT_TRUE(ping());
}
Exemplo n.º 4
0
TEST_F(ExtensionsTest, test_extension_broadcast) {
  auto status = startExtensionManager(socket_path);
  EXPECT_TRUE(status.ok());
  EXPECT_TRUE(socketExists(socket_path));

  // This time we're going to add a plugin to the extension_test registry.
  Registry::add<TestExtensionPlugin>("extension_test", "test_item");

  // Now we create a registry alias that will be broadcasted but NOT used for
  // internal call lookups. Aliasing was introduced for testing such that an
  // EM/E could exist in the same process (the same registry) without having
  // duplicate registry items in the internal registry list AND extension
  // registry route table.
  Registry::addAlias("extension_test", "test_item", "test_alias");
  Registry::allowDuplicates(true);

  // Before registering the extension there is NO route to "test_alias" since
  // alias resolutions are performed by the EM.
  EXPECT_TRUE(Registry::exists("extension_test", "test_item"));
  EXPECT_FALSE(Registry::exists("extension_test", "test_alias"));

  status = startExtension(socket_path, "test", "0.1", "0.0.0", "0.0.1");
  EXPECT_TRUE(status.ok());

  RouteUUID uuid;
  try {
    uuid = (RouteUUID)stoi(status.getMessage(), nullptr, 0);
  } catch (const std::exception& e) {
    EXPECT_TRUE(false);
    return;
  }

  auto ext_socket = socket_path + "." + std::to_string(uuid);
  EXPECT_TRUE(socketExists(ext_socket));

  // Make sure the EM registered the extension (called in start extension).
  auto extensions = registeredExtensions();
  // Expect two, since `getExtensions` includes the core.
  ASSERT_EQ(extensions.size(), 2U);
  EXPECT_EQ(extensions.count(uuid), 1U);
  EXPECT_EQ(extensions.at(uuid).name, "test");
  EXPECT_EQ(extensions.at(uuid).version, "0.1");
  EXPECT_EQ(extensions.at(uuid).sdk_version, "0.0.1");

  // We are broadcasting to our own registry in the test, which internally has
  // a "test_item" aliased to "test_alias", "test_item" is internally callable
  // but "test_alias" can only be resolved by an EM call.
  EXPECT_TRUE(Registry::exists("extension_test", "test_item"));
  // Now "test_alias" exists since it is in the extensions route table.
  EXPECT_TRUE(Registry::exists("extension_test", "test_alias"));

  PluginResponse response;
  // This registry call will fail, since "test_alias" cannot be resolved using
  // a local registry call.
  status = Registry::call("extension_test", "test_alias", {{}}, response);
  EXPECT_FALSE(status.ok());

  // The following will be the result of a:
  //   Registry::call("extension_test", "test_alias", {{}}, response);
  status = callExtension(ext_socket,
                         "extension_test",
                         "test_alias",
                         {{"test_key", "test_value"}},
                         response);
  EXPECT_TRUE(status.ok());
  EXPECT_EQ(response.size(), 1U);
  EXPECT_EQ(response[0]["test_key"], "test_value");

  Registry::removeBroadcast(uuid);
  Registry::allowDuplicates(false);
}