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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/sus/fixtures/async/http/server_context.rb +68 -16
- data/lib/sus/fixtures/async/http/version.rb +9 -7
- data/lib/sus/fixtures/async/http.rb +3 -1
- data/license.md +21 -0
- data/readme.md +23 -0
- data.tar.gz.sig +0 -0
- metadata +34 -4
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37b083cf427b4788520de2955f48e1ce9025a361f3e5c92aaf534fb455db47b8
|
4
|
+
data.tar.gz: a0afbc0322271a71d7ca8c2ae916fb3591db006b3614991e4f850262c6a362fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7634e13a74f666d2e6f7e360d204471a7dcc83bbd412cd00ee33110be84038f8f582ba3f2dec28f80e5355c1f8e10d3fcb082ff6a4856078093c23ec6820676
|
7
|
+
data.tar.gz: 35526b7e3c8f7260dafa66d0da738253cf5945b23fd950633525f8beb411070871c60ec9b4f034564ec6c4c9d1ee02b146d96b2f8f4e107cd22b0dab043d7378
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -1,5 +1,7 @@
|
|
1
|
-
#
|
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(
|
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
|
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
|
-
|
55
|
-
mock(@
|
56
|
-
|
57
|
-
|
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
|
-
|
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
|
-
@
|
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
|
-
#
|
2
|
-
# Released under the MIT License.
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2022-2023, by Samuel Williams.
|
5
5
|
|
6
|
-
module Sus
|
7
|
-
module
|
8
|
-
module
|
9
|
-
|
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
|
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
|
+
[](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.
|
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:
|
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
|
-
|
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.
|
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
|