Merge pull request 'fix flaky participation_test.exs' (#238) from ilja/akkoma:fix_err...
[akkoma] / test / pleroma / http / adapter_helper_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.HTTP.AdapterHelperTest do
6 use ExUnit.Case, async: true
7
8 alias Pleroma.HTTP.AdapterHelper
9
10 describe "format_proxy/1" do
11 test "with nil" do
12 assert AdapterHelper.format_proxy(nil) == nil
13 end
14
15 test "with string" do
16 assert AdapterHelper.format_proxy("http://127.0.0.1:8123") == {:http, "127.0.0.1", 8123, []}
17 end
18
19 test "localhost with port" do
20 assert AdapterHelper.format_proxy("https://localhost:8123") ==
21 {:https, "localhost", 8123, []}
22 end
23
24 test "tuple" do
25 assert AdapterHelper.format_proxy({:http, "localhost", 9050}) ==
26 {:http, "localhost", 9050, []}
27 end
28 end
29
30 describe "maybe_add_proxy_pool/1" do
31 test "should do nothing with nil" do
32 assert AdapterHelper.maybe_add_proxy_pool([], nil) == []
33 end
34
35 test "should create pools" do
36 assert AdapterHelper.maybe_add_proxy_pool([], "proxy") == [
37 pools: %{default: [conn_opts: [proxy: "proxy"]]}
38 ]
39 end
40
41 test "should not override conn_opts if set" do
42 assert AdapterHelper.maybe_add_proxy_pool(
43 [pools: %{default: [conn_opts: [already: "set"]]}],
44 "proxy"
45 ) == [
46 pools: %{default: [conn_opts: [proxy: "proxy", already: "set"]]}
47 ]
48 end
49 end
50 end