Merge branch 'develop' of https://git.pleroma.social/pleroma/pleroma into develop
[akkoma] / test / pleroma / web / media_proxy / invalidation / script_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.MediaProxy.Invalidation.ScriptTest do
6 use ExUnit.Case, async: true
7 alias Pleroma.Web.MediaProxy.Invalidation
8
9 import ExUnit.CaptureLog
10
11 test "it logs error when script is not found" do
12 assert capture_log(fn ->
13 assert Invalidation.Script.purge(
14 ["http://example.com/media/example.jpg"],
15 script_path: "./example"
16 ) == {:error, "%ErlangError{original: :enoent}"}
17 end) =~ "Error while cache purge: %ErlangError{original: :enoent}"
18
19 capture_log(fn ->
20 assert Invalidation.Script.purge(
21 ["http://example.com/media/example.jpg"],
22 []
23 ) == {:error, "\"not found script path\""}
24 end)
25 end
26
27 describe "url formatting" do
28 setup do
29 urls = [
30 "https://bikeshed.party/media/foo.png",
31 "http://safe.millennial.space/proxy/wheeeee.gif",
32 "https://lain.com/proxy/mediafile.mp4?foo&bar=true",
33 "http://localhost:4000/media/upload.jpeg"
34 ]
35
36 [urls: urls]
37 end
38
39 test "with invalid formatter", %{urls: urls} do
40 assert urls == Invalidation.Script.maybe_format_urls(urls, nil)
41 end
42
43 test "with :htcacheclean formatter", %{urls: urls} do
44 assert [
45 "https://bikeshed.party:443/media/foo.png?",
46 "http://safe.millennial.space:80/proxy/wheeeee.gif?",
47 "https://lain.com:443/proxy/mediafile.mp4?foo&bar=true",
48 "http://localhost:4000/media/upload.jpeg?"
49 ] == Invalidation.Script.maybe_format_urls(urls, :htcacheclean)
50 end
51 end
52 end