logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

federation_test.exs (1536B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Integration.FederationTest do
  5. use Pleroma.DataCase
  6. @moduletag :federated
  7. import Pleroma.Cluster
  8. setup_all do
  9. Pleroma.Cluster.spawn_default_cluster()
  10. :ok
  11. end
  12. @federated1 :"federated1@127.0.0.1"
  13. describe "federated cluster primitives" do
  14. test "within/2 captures local bindings and executes block on remote node" do
  15. captured_binding = :captured
  16. result =
  17. within @federated1 do
  18. user = Pleroma.Factory.insert(:user)
  19. {captured_binding, node(), user}
  20. end
  21. assert {:captured, @federated1, user} = result
  22. refute Pleroma.User.get_by_id(user.id)
  23. assert user.id == within(@federated1, do: Pleroma.User.get_by_id(user.id)).id
  24. end
  25. test "runs webserver on customized port" do
  26. {nickname, url, url_404} =
  27. within @federated1 do
  28. import Pleroma.Web.Router.Helpers
  29. user = Pleroma.Factory.insert(:user)
  30. user_url = account_url(Pleroma.Web.Endpoint, :show, user)
  31. url_404 = account_url(Pleroma.Web.Endpoint, :show, "not-exists")
  32. {user.nickname, user_url, url_404}
  33. end
  34. assert {:ok, {{_, 200, _}, _headers, body}} = :httpc.request(~c"#{url}")
  35. assert %{"acct" => ^nickname} = Jason.decode!(body)
  36. assert {:ok, {{_, 404, _}, _headers, _body}} = :httpc.request(~c"#{url_404}")
  37. end
  38. end
  39. end