1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.HTTP.AdapterHelperTest do
6 use Pleroma.DataCase, async: true
7 alias Pleroma.HTTP.AdapterHelper
9 describe "format_proxy/1" do
11 assert AdapterHelper.format_proxy(nil) == nil
15 assert AdapterHelper.format_proxy("http://127.0.0.1:8123") == {:http, "127.0.0.1", 8123, []}
18 test "localhost with port" do
19 assert AdapterHelper.format_proxy("https://localhost:8123") ==
20 {:https, "localhost", 8123, []}
24 assert AdapterHelper.format_proxy({:http, "localhost", 9050}) ==
25 {:http, "localhost", 9050, []}
29 describe "maybe_add_proxy_pool/1" do
30 test "should do nothing with nil" do
31 assert AdapterHelper.maybe_add_proxy_pool([], nil) == []
34 test "should create pools" do
35 assert AdapterHelper.maybe_add_proxy_pool([], "proxy") == [
36 pools: %{default: [conn_opts: [proxy: "proxy"]]}
40 test "should not override conn_opts if set" do
41 assert AdapterHelper.maybe_add_proxy_pool(
42 [pools: %{default: [conn_opts: [already: "set"]]}],
45 pools: %{default: [conn_opts: [proxy: "proxy", already: "set"]]}
50 describe "timeout settings" do
51 test "should default to 5000/15000" do
52 options = AdapterHelper.options(%URI{host: 'somewhere'})
53 assert options[:pool_timeout] == 5000
54 assert options[:receive_timeout] == 15_000
57 test "pool_timeout should be overridden by :http, :pool_timeout" do
58 clear_config([:http, :pool_timeout], 10_000)
59 options = AdapterHelper.options(%URI{host: 'somewhere'})
60 assert options[:pool_timeout] == 10_000
63 test "receive_timeout should be overridden by :http, :receive_timeout" do
64 clear_config([:http, :receive_timeout], 20_000)
65 options = AdapterHelper.options(%URI{host: 'somewhere'})
66 assert options[:receive_timeout] == 20_000