summaryrefslogtreecommitdiff
path: root/test/gun
diff options
context:
space:
mode:
authorAlexander Strizhakov <alex.strizhakov@gmail.com>2020-02-11 10:12:57 +0300
committerAlexander Strizhakov <alex.strizhakov@gmail.com>2020-02-18 08:19:01 +0300
commit514c899275a32e6ef63305f9424c50344d41b12e (patch)
treeac6be2ed464506378e1d8ccd20439677c89c9896 /test/gun
parent962eb8d4ac1aafeed6e3ae9b17847b9afaec7712 (diff)
downloadpleroma-514c899275a32e6ef63305f9424c50344d41b12e.tar.gz
pleroma-514c899275a32e6ef63305f9424c50344d41b12e.zip
adding gun adapter
Diffstat (limited to 'test/gun')
-rw-r--r--test/gun/gun_test.exs33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/gun/gun_test.exs b/test/gun/gun_test.exs
new file mode 100644
index 000000000..7f185617c
--- /dev/null
+++ b/test/gun/gun_test.exs
@@ -0,0 +1,33 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.GunTest do
+ use ExUnit.Case
+ alias Pleroma.Gun
+
+ @moduletag :integration
+
+ test "opens connection and receive response" do
+ {:ok, conn} = Gun.open('httpbin.org', 443)
+ assert is_pid(conn)
+ {:ok, _protocol} = Gun.await_up(conn)
+ ref = :gun.get(conn, '/get?a=b&c=d')
+ assert is_reference(ref)
+
+ assert {:response, :nofin, 200, _} = Gun.await(conn, ref)
+ assert json = receive_response(conn, ref)
+
+ assert %{"args" => %{"a" => "b", "c" => "d"}} = Jason.decode!(json)
+ end
+
+ defp receive_response(conn, ref, acc \\ "") do
+ case Gun.await(conn, ref) do
+ {:data, :nofin, body} ->
+ receive_response(conn, ref, acc <> body)
+
+ {:data, :fin, body} ->
+ acc <> body
+ end
+ end
+end