-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathclient.rb
73 lines (60 loc) · 1.67 KB
/
client.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# frozen_string_literal: true
# Released under the MIT License.
# Copyright, 2017-2024, by Samuel Williams.
require "async/http/server"
require "async/http/client"
require "async/reactor"
require "async/http/endpoint"
require "protocol/http/accept_encoding"
require "sus/fixtures/async"
require "sus/fixtures/async/http"
describe Async::HTTP::Client do
with "basic server" do
include Sus::Fixtures::Async::HTTP::ServerContext
it "client can get resource" do
response = client.get("/")
response.read
expect(response).to be(:success?)
end
with "client" do
with "#as_json" do
it "generates a JSON representation" do
expect(client.as_json).to be == {
endpoint: client.endpoint.to_s,
protocol: client.protocol,
retries: client.retries,
scheme: endpoint.scheme,
authority: endpoint.authority,
}
end
it "generates a JSON string" do
expect(JSON.dump(client)).to be == client.to_json
end
end
end
with "server" do
with "#as_json" do
it "generates a JSON representation" do
expect(server.as_json).to be == {
endpoint: server.endpoint.to_s,
protocol: server.protocol,
scheme: server.scheme,
}
end
it "generates a JSON string" do
expect(JSON.dump(server)).to be == server.to_json
end
end
end
end
with "non-existant host" do
include Sus::Fixtures::Async::ReactorContext
let(:endpoint) {Async::HTTP::Endpoint.parse("http://the.future")}
let(:client) {Async::HTTP::Client.new(endpoint)}
it "should fail to connect" do
expect do
client.get("/")
end.to raise_exception(SocketError, message: be =~ /not known/)
end
end
end