Skip to content

Commit 90ee9fd

Browse files
authored
Fix all integration tests (#464)
1 parent 795174c commit 90ee9fd

File tree

5 files changed

+15
-90
lines changed

5 files changed

+15
-90
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ iex> flush()
5151

5252
Users are not supposed to examine these messages. Instead, Mint provides a `stream/2` function that turns messages into HTTP responses. Mint streams responses back to the user in parts through response parts such as `:status`, `:headers`, `:data`, and `:done`.
5353

54-
5554
```elixir
5655
iex> {:ok, conn} = Mint.HTTP.connect(:https, "httpbin.org", 443)
5756
iex> {:ok, conn, request_ref} = Mint.HTTP.request(conn, "GET", "/", [], "")
@@ -151,7 +150,6 @@ Copyright 2018 Eric Meadows-Jönsson and Andrea Leopardi
151150
See the License for the specific language governing permissions and
152151
limitations under the License.
153152

154-
[castore]: https://github.com/elixir-mint/castore
155153
[documentation]: https://hexdocs.pm/mint
156154
[issues]: https://github.com/elixir-mint/mint/issues
157155
[mint_web_socket]: https://github.com/elixir-mint/mint_web_socket

test/mint/http1/integration_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ defmodule Mint.HTTP1.IntegrationTest do
185185
HTTP1.connect(
186186
:https,
187187
"localhost",
188-
8443,
188+
Mint.HttpBin.https_port(),
189189
transport_opts: [cacerts: [], log_alert: false, reuse_sessions: false]
190190
)
191191

test/mint/http2/integration_test.exs

Lines changed: 2 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -77,80 +77,22 @@ defmodule HTTP2.IntegrationTest do
7777
assert conn.buffer == ""
7878
assert HTTP2.open?(conn)
7979
end
80-
end
81-
82-
describe "http2.golang.org" do
83-
@describetag skip: """
84-
http2.golang.org has been decommisioned.
85-
Re-enable these tests in the future if we figure out a test server that supports
86-
a similar set of features.
87-
"""
88-
89-
test "GET /clockstream", %{conn: conn} do
90-
assert {:ok, %HTTP2{} = conn, req_id} = HTTP2.request(conn, "GET", "/clockstream", [], nil)
91-
92-
assert {:ok, %HTTP2{} = conn, responses} = stream_messages_until_response(conn)
93-
assert [{:status, ^req_id, 200}, {:headers, ^req_id, _headers} | rest] = responses
94-
95-
conn =
96-
if rest != [] do
97-
assert [{:data, ^req_id, data}] = rest
98-
assert data =~ "# ~1KB of junk to force browsers to start rendering immediately"
99-
conn
100-
else
101-
assert_receive message, 5000
102-
assert {:ok, %HTTP2{} = conn, responses} = HTTP2.stream(conn, message)
103-
assert [{:data, ^req_id, data}] = responses
104-
assert data =~ "# ~1KB of junk to force browsers to start rendering immediately"
105-
conn
106-
end
107-
108-
assert_receive message, 5000
109-
assert {:ok, %HTTP2{} = conn, responses} = HTTP2.stream(conn, message)
110-
assert [{:data, ^req_id, data}] = responses
111-
assert data =~ ~r/\A\d{4}-\d{2}-\d{2}/
112-
113-
assert HTTP2.open?(conn)
114-
end
115-
116-
test "PUT /ECHO", %{conn: conn} do
117-
assert {:ok, %HTTP2{} = conn, req_id} =
118-
HTTP2.request(conn, "PUT", "/ECHO", [], "hello world")
119-
120-
assert {:ok, %HTTP2{} = conn, responses} = receive_stream(conn)
121-
122-
assert [
123-
{:status, ^req_id, 200},
124-
{:headers, ^req_id, headers},
125-
{:data, ^req_id, data},
126-
{:data, ^req_id, ""},
127-
{:done, ^req_id}
128-
] = responses
12980

130-
assert is_list(headers)
131-
assert data == "HELLO WORLD"
132-
133-
assert conn.buffer == ""
134-
assert HTTP2.open?(conn)
135-
end
136-
137-
test "GET /file/gopher.png", %{conn: conn} do
138-
assert {:ok, %HTTP2{} = conn, ref} = HTTP2.request(conn, "GET", "/file/gopher.png", [], nil)
81+
test "GET /image/png", %{conn: conn} do
82+
assert {:ok, %HTTP2{} = conn, ref} = HTTP2.request(conn, "GET", "/image/png", [], nil)
13983
assert {:ok, %HTTP2{} = conn, responses} = receive_stream(conn)
14084

14185
assert [
14286
{:status, ^ref, 200},
14387
{:headers, ^ref, headers},
14488
{:data, ^ref, data1},
14589
{:data, ^ref, data2},
146-
{:data, ^ref, data3},
14790
{:done, ^ref}
14891
] = responses
14992

15093
assert is_list(headers)
15194
assert is_binary(data1)
15295
assert is_binary(data2)
153-
assert is_binary(data3)
15496

15597
assert conn.buffer == ""
15698
assert HTTP2.open?(conn)
@@ -162,19 +104,6 @@ defmodule HTTP2.IntegrationTest do
162104
assert conn.buffer == ""
163105
assert HTTP2.open?(conn)
164106
end
165-
166-
test "GET /serverpush", %{conn: conn} do
167-
assert {:ok, %HTTP2{} = conn, req_id} = HTTP2.request(conn, "GET", "/serverpush", [], nil)
168-
assert {:ok, %HTTP2{} = _conn, responses} = receive_stream(conn)
169-
170-
# TODO: improve this test by improving receive_stream/1.
171-
assert [
172-
{:push_promise, ^req_id, _promised_req_id1, _headers1},
173-
{:push_promise, ^req_id, _promised_req_id2, _headers2},
174-
{:push_promise, ^req_id, _promised_req_id3, _headers3},
175-
{:push_promise, ^req_id, _promised_req_id4, _headers4} | _
176-
] = responses
177-
end
178107
end
179108

180109
describe "twitter.com" do
@@ -329,14 +258,5 @@ defmodule HTTP2.IntegrationTest do
329258
end
330259
end
331260

332-
defp stream_messages_until_response(conn) do
333-
assert_receive message, 1000
334-
335-
case HTTP2.stream(conn, message) do
336-
{:ok, %HTTP2{} = conn, []} -> stream_messages_until_response(conn)
337-
other -> other
338-
end
339-
end
340-
341261
# TODO: certificate verification; badssl.com does not seem to support HTTP2
342262
end

test/mint/integration_test.exs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ defmodule Mint.IntegrationTest do
99

1010
describe "nghttp2.org" do
1111
test "SSL - select HTTP1" do
12-
assert {:ok, conn} = HTTP.connect(:https, "nghttp2.org", 443, protocols: [:http1])
12+
assert {:ok, conn} =
13+
HTTP.connect(:https, HttpBin.host(), HttpBin.https_port(),
14+
transport_opts: HttpBin.https_transport_opts(),
15+
protocols: [:http1]
16+
)
1317

1418
assert conn.__struct__ == Mint.HTTP1
15-
assert {:ok, conn, request} = HTTP.request(conn, "GET", "/httpbin/bytes/1", [], nil)
19+
assert {:ok, conn, request} = HTTP.request(conn, "GET", "/bytes/1", [], nil)
1620
assert {:ok, _conn, responses} = receive_stream(conn)
1721

1822
assert [
@@ -24,10 +28,13 @@ defmodule Mint.IntegrationTest do
2428
end
2529

2630
test "SSL - select HTTP2" do
27-
assert {:ok, conn} = HTTP.connect(:https, "nghttp2.org", 443)
31+
assert {:ok, conn} =
32+
HTTP.connect(:https, HttpBin.host(), HttpBin.https_port(),
33+
transport_opts: HttpBin.https_transport_opts()
34+
)
2835

2936
assert conn.__struct__ == Mint.HTTP2
30-
assert {:ok, conn, request} = HTTP.request(conn, "GET", "/httpbin/bytes/1", [], nil)
37+
assert {:ok, conn, request} = HTTP.request(conn, "GET", "/bytes/1", [], nil)
3138
assert {:ok, _conn, responses} = receive_stream(conn)
3239

3340
assert [

test/mint/unix_socket_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
defmodule Mint.UnitSocketTest do
1+
defmodule Mint.UnixSocketTest do
22
use ExUnit.Case, async: true
33

44
alias Mint.{HTTP, TestSocketServer}

0 commit comments

Comments
 (0)