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 ExUnit.Case, async: true
8 alias Pleroma.HTTP.AdapterHelper
10 describe "format_proxy/1" do
12 assert AdapterHelper.format_proxy(nil) == nil
16 assert AdapterHelper.format_proxy("http://127.0.0.1:8123") == {:http, "127.0.0.1", 8123, []}
19 test "localhost with port" do
20 assert AdapterHelper.format_proxy("https://localhost:8123") ==
21 {:https, "localhost", 8123, []}
25 assert AdapterHelper.format_proxy({:http, "localhost", 9050}) ==
26 {:http, "localhost", 9050, []}
30 describe "maybe_add_proxy_pool/1" do
31 test "should do nothing with nil" do
32 assert AdapterHelper.maybe_add_proxy_pool([], nil) == []
35 test "should create pools" do
36 assert AdapterHelper.maybe_add_proxy_pool([], "proxy") == [
37 pools: %{default: [conn_opts: [proxy: "proxy"]]}
41 test "should not override conn_opts if set" do
42 assert AdapterHelper.maybe_add_proxy_pool(
43 [pools: %{default: [conn_opts: [already: "set"]]}],
46 pools: %{default: [conn_opts: [proxy: "proxy", already: "set"]]}