sus-fixtures-async-http 0.2.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e7272272c20a88d6753e4392968fdba12e49d4d9f76829ff8083c36cbe75bc6
4
- data.tar.gz: 706d1f590f248501e7ad7642f92796c7677ac54bc6f8e91b86acfef28f53dec5
3
+ metadata.gz: 37b083cf427b4788520de2955f48e1ce9025a361f3e5c92aaf534fb455db47b8
4
+ data.tar.gz: a0afbc0322271a71d7ca8c2ae916fb3591db006b3614991e4f850262c6a362fb
5
5
  SHA512:
6
- metadata.gz: c41cc744c499c0e07ddf94b86221304a33914ededd510f9f6a0084c37ec735a62115993005349fa9f71c8f22f9d1efe01e9f028dfc2c4fff58ae8ccf77935cc0
7
- data.tar.gz: 446348d7ac72dcab88e9c51828976fa8a93ba5ef70abaada6fe81ede8d200fb2556584f16a3632c406d3b49c54a1dbdd8c55e1ef7b980c3d4eb8580a0927c048
6
+ metadata.gz: f7634e13a74f666d2e6f7e360d204471a7dcc83bbd412cd00ee33110be84038f8f582ba3f2dec28f80e5355c1f8e10d3fcb082ff6a4856078093c23ec6820676
7
+ data.tar.gz: 35526b7e3c8f7260dafa66d0da738253cf5945b23fd950633525f8beb411070871c60ec9b4f034564ec6c4c9d1ee02b146d96b2f8f4e107cd22b0dab043d7378
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,5 +1,7 @@
1
- # Copyright, 2022, by Samuel Williams.
1
+ # frozen_string_literal: true
2
+
2
3
  # Released under the MIT License.
4
+ # Copyright, 2022-2023, by Samuel Williams.
3
5
 
4
6
  require 'sus/fixtures/async/reactor_context'
5
7
 
@@ -18,8 +20,37 @@ module Sus::Fixtures
18
20
  ::Async::HTTP::Protocol::HTTP1
19
21
  end
20
22
 
23
+ def url
24
+ 'http://localhost:0'
25
+ end
26
+
27
+ def bound_urls
28
+ urls = []
29
+
30
+ @client_endpoint.each do |address_endpoint|
31
+ address = address_endpoint.address
32
+
33
+ host = address.ip_address
34
+ if address.ipv6?
35
+ host = "[#{host}]"
36
+ end
37
+
38
+ port = address.ip_port
39
+
40
+ urls << "#{endpoint.scheme}://#{host}:#{port}"
41
+ end
42
+
43
+ urls.sort!
44
+
45
+ return urls
46
+ end
47
+
48
+ def bound_url
49
+ bound_urls.first
50
+ end
51
+
21
52
  def endpoint
22
- ::Async::HTTP::Endpoint.parse('http://localhost:0', timeout: 0.8, reuse_port: true, protocol: protocol)
53
+ ::Async::HTTP::Endpoint.parse(url, timeout: 0.8, reuse_port: true, protocol: protocol)
23
54
  end
24
55
 
25
56
  def retries
@@ -34,10 +65,18 @@ module Sus::Fixtures
34
65
  app
35
66
  end
36
67
 
37
- def server
68
+ def make_server_endpoint(bound_endpoint)
69
+ bound_endpoint
70
+ end
71
+
72
+ def make_server(endpoint)
38
73
  ::Async::HTTP::Server.new(middleware, @bound_endpoint)
39
74
  end
40
75
 
76
+ def server
77
+ @server
78
+ end
79
+
41
80
  def client
42
81
  @client
43
82
  end
@@ -46,35 +85,48 @@ module Sus::Fixtures
46
85
  @client_endpoint
47
86
  end
48
87
 
88
+ def make_client_endpoint(bound_endpoint)
89
+ bound_endpoint.local_address_endpoint
90
+ end
91
+
92
+
49
93
  def before
94
+ super
95
+
50
96
  # We bind the endpoint before running the server so that we know incoming connections will be accepted:
51
97
  @bound_endpoint = ::Async::IO::SharedEndpoint.bound(endpoint)
52
- @client_endpoint = @bound_endpoint.local_address_endpoint
53
98
 
54
- # I feel a dedicated class might be better than this hack:
55
- mock(@bound_endpoint) do |mock|
56
- mock.replace(:protocol) {endpoint.protocol}
57
- mock.replace(:scheme) {endpoint.scheme}
99
+ @server_endpoint = make_server_endpoint(@bound_endpoint)
100
+ mock(@server_endpoint) do |wrapper|
101
+ wrapper.replace(:protocol) {endpoint.protocol}
102
+ wrapper.replace(:scheme) {endpoint.scheme}
103
+ wrapper.replace(:authority) {endpoint.authority}
104
+ wrapper.replace(:path) {endpoint.path}
58
105
  end
59
106
 
60
- mock(@client_endpoint) do |mock|
61
- mock.replace(:protocol) {endpoint.protocol}
62
- mock.replace(:scheme) {endpoint.scheme}
63
- mock.replace(:authority) {endpoint.authority}
64
- mock.replace(:path) {endpoint.path}
65
- end
107
+ @server = make_server(@server_endpoint)
66
108
 
67
109
  @server_task = Async do
68
- server.run
110
+ @server.run
69
111
  end
70
112
 
71
- @client = ::Async::HTTP::Client.new(@client_endpoint, protocol: endpoint.protocol, retries: retries)
113
+ @client_endpoint = make_client_endpoint(@bound_endpoint)
114
+ mock(@client_endpoint) do |wrapper|
115
+ wrapper.replace(:protocol) {endpoint.protocol}
116
+ wrapper.replace(:scheme) {endpoint.scheme}
117
+ wrapper.replace(:authority) {endpoint.authority}
118
+ wrapper.replace(:path) {endpoint.path}
119
+ end
120
+
121
+ @client = ::Async::HTTP::Client.new(@client_endpoint, retries: retries)
72
122
  end
73
123
 
74
124
  def after
75
125
  @client&.close
76
126
  @server_task&.stop
77
127
  @bound_endpoint&.close
128
+
129
+ super
78
130
  end
79
131
  end
80
132
  end
@@ -1,12 +1,14 @@
1
- # Copyright, 2022, by Samuel Williams.
2
- # Released under the MIT License.
1
+ # frozen_string_literal: true
3
2
 
4
- require 'sus/fixtures'
3
+ # Released under the MIT License.
4
+ # Copyright, 2022-2023, by Samuel Williams.
5
5
 
6
- module Sus::Fixtures
7
- module Async
8
- module HTTP
9
- VERSION = "0.2.3"
6
+ module Sus
7
+ module Fixtures
8
+ module Async
9
+ module HTTP
10
+ VERSION = "0.4.0"
11
+ end
10
12
  end
11
13
  end
12
14
  end
@@ -1,5 +1,7 @@
1
- # Copyright, 2022, by Samuel Williams.
1
+ # frozen_string_literal: true
2
+
2
3
  # Released under the MIT License.
4
+ # Copyright, 2022-2023, by Samuel Williams.
3
5
 
4
6
  require_relative 'http/server_context'
5
7
  require_relative 'http/version'
data/license.md ADDED
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright, 2022-2023, by Samuel Williams.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/readme.md ADDED
@@ -0,0 +1,23 @@
1
+ # Sus::Fixtures::Async::HTTP
2
+
3
+ Provides a convenient fixture for running a web server.
4
+
5
+ [![Development Status](https://github.com/socketry/sus-fixtures-async-http/workflows/Test/badge.svg)](https://github.com/socketry/sus-fixtures-async-http/actions?workflow=Test)
6
+
7
+ ## Installation
8
+
9
+ ``` bash
10
+ $ bundle add sus-fixtures-async-http
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ``` ruby
16
+ include Sus::Fixtures::Async::HTTP::ServerContext
17
+
18
+ let(:response) {client.get("/")}
19
+
20
+ it 'can perform a reqeust' do
21
+ expect(response.read).to be == "Hello World!"
22
+ end
23
+ ```
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sus-fixtures-async-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -37,8 +37,22 @@ cert_chain:
37
37
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
38
38
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
39
39
  -----END CERTIFICATE-----
40
- date: 2022-08-28 00:00:00.000000000 Z
40
+ date: 2023-09-10 00:00:00.000000000 Z
41
41
  dependencies:
42
+ - !ruby/object:Gem::Dependency
43
+ name: async-http
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '0.54'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '0.54'
42
56
  - !ruby/object:Gem::Dependency
43
57
  name: async-io
44
58
  requirement: !ruby/object:Gem::Requirement
@@ -81,6 +95,20 @@ dependencies:
81
95
  - - "~>"
82
96
  - !ruby/object:Gem::Version
83
97
  version: '0.1'
98
+ - !ruby/object:Gem::Dependency
99
+ name: covered
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '0.20'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '0.20'
84
112
  description:
85
113
  email:
86
114
  executables: []
@@ -90,7 +118,9 @@ files:
90
118
  - lib/sus/fixtures/async/http.rb
91
119
  - lib/sus/fixtures/async/http/server_context.rb
92
120
  - lib/sus/fixtures/async/http/version.rb
93
- homepage: https://github.com/ioquatix/sus-fixtures-async
121
+ - license.md
122
+ - readme.md
123
+ homepage: https://github.com/socketry/sus-fixtures-async-http
94
124
  licenses:
95
125
  - MIT
96
126
  metadata:
@@ -110,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
140
  - !ruby/object:Gem::Version
111
141
  version: '0'
112
142
  requirements: []
113
- rubygems_version: 3.3.7
143
+ rubygems_version: 3.4.10
114
144
  signing_key:
115
145
  specification_version: 4
116
146
  summary: Test fixtures for running in Async::HTTP.
metadata.gz.sig CHANGED
Binary file