2020-02-11 02:12:57 -05:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-03 18:16:24 -05:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2020-02-11 02:12:57 -05:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.HTTP.ConnectionTest do
|
2020-04-29 03:31:41 -04:00
|
|
|
use ExUnit.Case
|
2020-03-06 12:23:58 -05:00
|
|
|
|
2020-02-11 02:12:57 -05:00
|
|
|
alias Pleroma.HTTP.Connection
|
|
|
|
|
2020-04-29 03:31:41 -04:00
|
|
|
describe "format_host/1" do
|
2020-02-11 02:12:57 -05:00
|
|
|
test "as atom to charlist" do
|
2020-04-29 03:31:41 -04:00
|
|
|
assert Connection.format_host(:localhost) == 'localhost'
|
2020-02-11 02:12:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
test "as string to charlist" do
|
2020-04-29 03:31:41 -04:00
|
|
|
assert Connection.format_host("localhost.com") == 'localhost.com'
|
2020-02-11 02:12:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
test "as string ip to tuple" do
|
2020-04-29 03:31:41 -04:00
|
|
|
assert Connection.format_host("127.0.0.1") == {127, 0, 0, 1}
|
2020-02-11 02:12:57 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-29 03:31:41 -04:00
|
|
|
describe "options/2" do
|
|
|
|
test "defaults" do
|
|
|
|
assert Connection.options(%URI{}) == [env: :test, pool: :federation]
|
2020-02-11 02:12:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
test "passed opts have more weight than defaults" do
|
2020-04-29 03:31:41 -04:00
|
|
|
assert Connection.options(%URI{}, pool: :media) == [env: :test, pool: :media]
|
2020-02-11 02:12:57 -05:00
|
|
|
end
|
2020-03-10 08:54:11 -04:00
|
|
|
|
2020-04-29 03:31:41 -04:00
|
|
|
test "adding defaults for hackney adapter" do
|
|
|
|
initial = Application.get_env(:tesla, :adapter)
|
|
|
|
Application.put_env(:tesla, :adapter, Tesla.Adapter.Hackney)
|
|
|
|
on_exit(fn -> Application.put_env(:tesla, :adapter, initial) end)
|
2020-03-10 08:54:11 -04:00
|
|
|
|
2020-04-29 03:31:41 -04:00
|
|
|
refute %URI{scheme: "https", host: "example.com"}
|
|
|
|
|> Connection.options()
|
|
|
|
|> Keyword.delete(:pool) == []
|
2020-03-10 08:54:11 -04:00
|
|
|
end
|
|
|
|
|
2020-04-29 03:31:41 -04:00
|
|
|
test "adding defaults for gun adapter" do
|
|
|
|
initial = Application.get_env(:tesla, :adapter)
|
|
|
|
Application.put_env(:tesla, :adapter, Tesla.Adapter.Gun)
|
|
|
|
on_exit(fn -> Application.put_env(:tesla, :adapter, initial) end)
|
2020-03-10 08:54:11 -04:00
|
|
|
|
2020-04-29 03:31:41 -04:00
|
|
|
refute %URI{scheme: "https", host: "example.com"}
|
|
|
|
|> Connection.options()
|
|
|
|
|> Keyword.delete(:pool) == []
|
2020-03-10 08:54:11 -04:00
|
|
|
end
|
|
|
|
end
|
2020-02-11 02:12:57 -05:00
|
|
|
end
|