1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MediaProxy.Invalidation.HttpTest do
7 alias Pleroma.Web.MediaProxy.Invalidation
9 import ExUnit.CaptureLog
13 on_exit(fn -> Cachex.clear(:banned_urls_cache) end)
16 test "logs hasn't error message when request is valid" do
18 %{method: :purge, url: "http://example.com/media/example.jpg"} ->
19 %Tesla.Env{status: 200}
22 refute capture_log(fn ->
23 assert Invalidation.Http.purge(
24 ["http://example.com/media/example.jpg"],
26 ) == {:ok, ["http://example.com/media/example.jpg"]}
27 end) =~ "Error while cache purge"
30 test "it write error message in logs when request invalid" do
32 %{method: :purge, url: "http://example.com/media/example1.jpg"} ->
33 %Tesla.Env{status: 404}
36 assert capture_log(fn ->
37 assert Invalidation.Http.purge(
38 ["http://example.com/media/example1.jpg"],
40 ) == {:ok, ["http://example.com/media/example1.jpg"]}
41 end) =~ "Error while cache purge: url - http://example.com/media/example1.jpg"