1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.ReverseProxy.Client.TeslaTest do
7 use Pleroma.Tests.Helpers
8 alias Pleroma.ReverseProxy.Client
9 @moduletag :integration
11 clear_config_all(Pleroma.Gun.API) do
12 Pleroma.Config.put(Pleroma.Gun.API, Pleroma.Gun)
16 Application.put_env(:tesla, :adapter, Tesla.Adapter.Gun)
19 Application.put_env(:tesla, :adapter, Tesla.Mock)
23 test "get response body stream" do
24 {:ok, status, headers, ref} =
27 "http://httpbin.org/stream-bytes/10",
28 [{"accept", "application/octet-stream"}],
36 {:ok, response, ref} = Client.Tesla.stream_body(ref)
38 assert is_binary(response)
39 assert byte_size(response) == 10
41 assert :done == Client.Tesla.stream_body(ref)
42 assert :ok = Client.Tesla.close(ref)
45 test "head response" do
46 {:ok, status, headers} = Client.Tesla.request(:head, "https://httpbin.org/get", [], "")
52 test "get error response" do
53 {:ok, status, headers, _body} =
56 "https://httpbin.org/status/500",
65 describe "client error" do
67 adapter = Application.get_env(:tesla, :adapter)
68 Application.put_env(:tesla, :adapter, Tesla.Adapter.Hackney)
70 on_exit(fn -> Application.put_env(:tesla, :adapter, adapter) end)
74 test "adapter doesn't support reading body in chunks" do
75 assert_raise RuntimeError,
76 "Elixir.Tesla.Adapter.Hackney doesn't support reading body in chunks",
80 "http://httpbin.org/stream-bytes/10",
81 [{"accept", "application/octet-stream"}],
88 defp check_ref(%{pid: pid, stream: stream} = ref) do
90 assert is_reference(stream)