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.GunTest do
9 @moduletag :integration
11 test "opens connection and receive response" do
12 {:ok, conn} = Gun.open('httpbin.org', 443)
14 {:ok, _protocol} = Gun.await_up(conn)
15 ref = :gun.get(conn, '/get?a=b&c=d')
16 assert is_reference(ref)
18 assert {:response, :nofin, 200, _} = Gun.await(conn, ref)
19 assert json = receive_response(conn, ref)
21 assert %{"args" => %{"a" => "b", "c" => "d"}} = Jason.decode!(json)
24 defp receive_response(conn, ref, acc \\ "") do
25 case Gun.await(conn, ref) do
26 {:data, :nofin, body} ->
27 receive_response(conn, ref, acc <> body)
29 {:data, :fin, body} ->