logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

http_test.exs (1331B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.MediaProxy.Invalidation.HttpTest do
  5. use ExUnit.Case
  6. alias Pleroma.Web.MediaProxy.Invalidation
  7. import ExUnit.CaptureLog
  8. import Tesla.Mock
  9. test "logs hasn't error message when request is valid" do
  10. mock(fn
  11. %{method: :purge, url: "http://example.com/media/example.jpg"} ->
  12. %Tesla.Env{status: 200}
  13. end)
  14. refute capture_log(fn ->
  15. assert Invalidation.Http.purge(
  16. ["http://example.com/media/example.jpg"],
  17. []
  18. ) == {:ok, ["http://example.com/media/example.jpg"]}
  19. end) =~ "Error while cache purge"
  20. end
  21. test "it write error message in logs when request invalid" do
  22. mock(fn
  23. %{method: :purge, url: "http://example.com/media/example1.jpg"} ->
  24. %Tesla.Env{status: 404}
  25. end)
  26. assert capture_log(fn ->
  27. assert Invalidation.Http.purge(
  28. ["http://example.com/media/example1.jpg"],
  29. []
  30. ) == {:ok, ["http://example.com/media/example1.jpg"]}
  31. end) =~ "Error while cache purge: url - http://example.com/media/example1.jpg"
  32. end
  33. end