From 65d96929755ca7240d04b68220fce443285b29e8 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Tue, 26 May 2020 06:38:45 +0300 Subject: [PATCH] fix tests --- lib/pleroma/web/media_proxy/media_proxy.ex | 6 +++--- test/web/media_proxy/invalidation_test.exs | 5 +++++ test/web/media_proxy/invalidations/http_test.exs | 5 +++++ test/web/media_proxy/invalidations/script_test.exs | 5 +++++ test/web/media_proxy/media_proxy_controller_test.exs | 5 +++++ 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/web/media_proxy/media_proxy.ex b/lib/pleroma/web/media_proxy/media_proxy.ex index 25eabca1e..4a0fec288 100644 --- a/lib/pleroma/web/media_proxy/media_proxy.ex +++ b/lib/pleroma/web/media_proxy/media_proxy.ex @@ -10,10 +10,10 @@ defmodule Pleroma.Web.MediaProxy do @base64_opts [padding: false] @spec in_deleted_urls(String.t()) :: boolean() - def in_deleted_urls(url), do: !!Cachex.get!(:deleted_urls_cache, url) + def in_deleted_urls(url), do: elem(Cachex.exists?(:deleted_urls_cache, url), 1) def remove_from_deleted_urls(urls) when is_list(urls) do - Enum.each(urls, &remove_from_deleted_urls(&1)) + Enum.each(urls, &remove_from_deleted_urls/1) end def remove_from_deleted_urls(url) when is_binary(url) do @@ -21,7 +21,7 @@ defmodule Pleroma.Web.MediaProxy do end def put_in_deleted_urls(urls) when is_list(urls) do - Enum.each(urls, &put_in_deleted_urls(&1)) + Enum.each(urls, &put_in_deleted_urls/1) end def put_in_deleted_urls(url) when is_binary(url) do diff --git a/test/web/media_proxy/invalidation_test.exs b/test/web/media_proxy/invalidation_test.exs index 8348663f3..31b5207bf 100644 --- a/test/web/media_proxy/invalidation_test.exs +++ b/test/web/media_proxy/invalidation_test.exs @@ -11,6 +11,11 @@ defmodule Pleroma.Web.MediaProxy.InvalidationTest do setup do: clear_config([:media_proxy]) + setup do + on_exit(fn -> Cachex.purge(:deleted_urls_cache) end) + :ok + end + describe "Invalidation.Http" do test "perform request to clear cache" do Config.put([:media_proxy, :enabled], false) diff --git a/test/web/media_proxy/invalidations/http_test.exs b/test/web/media_proxy/invalidations/http_test.exs index 062dd0b87..a3a681fd9 100644 --- a/test/web/media_proxy/invalidations/http_test.exs +++ b/test/web/media_proxy/invalidations/http_test.exs @@ -5,6 +5,11 @@ defmodule Pleroma.Web.MediaProxy.Invalidation.HttpTest do import ExUnit.CaptureLog import Tesla.Mock + setup do + on_exit(fn -> Cachex.purge(:deleted_urls_cache) end) + :ok + end + test "logs hasn't error message when request is valid" do mock(fn %{method: :purge, url: "http://example.com/media/example.jpg"} -> diff --git a/test/web/media_proxy/invalidations/script_test.exs b/test/web/media_proxy/invalidations/script_test.exs index 4f95d40ef..d488dbff2 100644 --- a/test/web/media_proxy/invalidations/script_test.exs +++ b/test/web/media_proxy/invalidations/script_test.exs @@ -4,6 +4,11 @@ defmodule Pleroma.Web.MediaProxy.Invalidation.ScriptTest do import ExUnit.CaptureLog + setup do + on_exit(fn -> Cachex.purge(:deleted_urls_cache) end) + :ok + end + test "it logger error when script not found" do assert capture_log(fn -> assert Invalidation.Script.purge( diff --git a/test/web/media_proxy/media_proxy_controller_test.exs b/test/web/media_proxy/media_proxy_controller_test.exs index 306d53bf8..a48310d70 100644 --- a/test/web/media_proxy/media_proxy_controller_test.exs +++ b/test/web/media_proxy/media_proxy_controller_test.exs @@ -10,6 +10,11 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do setup do: clear_config(:media_proxy) setup do: clear_config([Pleroma.Web.Endpoint, :secret_key_base]) + setup do + on_exit(fn -> Cachex.purge(:deleted_urls_cache) end) + :ok + end + test "it returns 404 when MediaProxy disabled", %{conn: conn} do Config.put([:media_proxy, :enabled], false)