@@ -35,6 +35,10 @@ defmodule HTTPoisonBaseTest do
35
35
do: Keyword . merge ( options , params: Map . merge ( options [ :params ] , % { key: "fizz" } ) )
36
36
end
37
37
38
+ defmodule ExampleRequest do
39
+ use HTTPoison.Base
40
+ end
41
+
38
42
setup do
39
43
on_exit ( fn ->
40
44
System . delete_env ( "HTTP_PROXY" )
@@ -125,7 +129,7 @@ defmodule HTTPoisonBaseTest do
125
129
}
126
130
end
127
131
128
- test "request raises error tuple" do
132
+ test "get!/1 raises error tuple" do
129
133
reason = { :closed , "Something happened" }
130
134
131
135
expect ( :hackney , :request , fn _ , _ , _ , _ , _ -> { :error , reason } end )
@@ -698,4 +702,35 @@ defmodule HTTPoisonBaseTest do
698
702
}
699
703
} }
700
704
end
705
+
706
+ test "request body using request/1 example" do
707
+ expect ( :hackney , :request , fn :get , "http://localhost" , [ ] , "" , [ ] ->
708
+ { :ok , 200 , "headers" , :client }
709
+ end )
710
+
711
+ expect ( :hackney , :body , fn _ , _ -> { :ok , "response" } end )
712
+
713
+ request = % HTTPoison.Request { url: "http://localhost" }
714
+ assert ExampleRequest . request! ( request ) ==
715
+ % HTTPoison.Response {
716
+ status_code: 200 ,
717
+ headers: "headers" ,
718
+ body: "response" ,
719
+ request_url: "http://localhost" ,
720
+ request: request ,
721
+ }
722
+ end
723
+
724
+ test "request! raises error tuple" do
725
+ reason = { :closed , "Something happened" }
726
+
727
+ expect ( :hackney , :request , fn _ , _ , _ , _ , _ -> { :error , reason } end )
728
+ expect ( :hackney , :request , fn _ , _ , _ , _ , _ -> { :error , reason } end )
729
+
730
+ assert_raise HTTPoison.Error , "{:closed, \" Something happened\" }" , fn ->
731
+ HTTPoison . request! ( :get , "http://localhost" )
732
+ end
733
+
734
+ assert HTTPoison . request ( :get , "http://localhost" ) == { :error , % HTTPoison.Error { reason: reason } }
735
+ end
701
736
end
0 commit comments