logo

pleroma

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

http_test.exs (1246B)


  1. defmodule Pleroma.Web.MediaProxy.Invalidation.HttpTest do
  2. use ExUnit.Case
  3. alias Pleroma.Web.MediaProxy.Invalidation
  4. import ExUnit.CaptureLog
  5. import Tesla.Mock
  6. setup do
  7. on_exit(fn -> Cachex.clear(:banned_urls_cache) end)
  8. end
  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