sus-fixtures-async-http 0.10.0 → 0.11.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 +60 -9
- data/lib/sus/fixtures/async/http/version.rb +1 -1
- data/lib/sus/fixtures/async/http.rb +15 -2
- data/license.md +1 -1
- data.tar.gz.sig +0 -0
- metadata +4 -9
- 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: f94ff88eb42debcc5eb56e473fdfa6a52166b669f6242c749bf63776bd9dadc9
|
4
|
+
data.tar.gz: ed0c8fc27e8a94c8c827bc8e1a17bf230551bfd29c7ea9722d2f5f9c21d9b941
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b59cf0cae7ccf666984842e884979279e639243e5be7d4380249cb6df60e8734b0dcb82e1a6aa88811fa56fb6ead7afb871db1cddb04f13d44f284953d6dfaf7
|
7
|
+
data.tar.gz: 8e75129db355cafbd6a8469737b84c52451f6b21aec977967236b92bd542b7693c8bfa43861287212e93af81f9b8895a27cf4ddfa374e452f0d290b0358844f1
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -1,28 +1,44 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2022-
|
4
|
+
# Copyright, 2022-2025, by Samuel Williams.
|
5
5
|
|
6
|
-
require
|
6
|
+
require "sus/fixtures/async/reactor_context"
|
7
7
|
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
8
|
+
require "async/http/server"
|
9
|
+
require "async/http/client"
|
10
|
+
require "async/http/endpoint"
|
11
11
|
|
12
12
|
module Sus::Fixtures
|
13
13
|
module Async
|
14
14
|
module HTTP
|
15
|
+
# ServerContext provides a test fixture for HTTP server and client testing.
|
16
|
+
# It sets up an HTTP server with a bound endpoint and provides a corresponding client
|
17
|
+
# for making requests. This context handles the lifecycle of both server and client,
|
18
|
+
# ensuring proper setup and teardown.
|
19
|
+
#
|
20
|
+
# The context automatically:
|
21
|
+
# - Binds to an available port
|
22
|
+
# - Starts an HTTP server with configurable middleware
|
23
|
+
# - Creates a client configured to connect to the server
|
24
|
+
# - Handles cleanup of resources after tests
|
15
25
|
module ServerContext
|
16
26
|
include ReactorContext
|
17
27
|
|
28
|
+
# The HTTP protocol version to use for the server.
|
29
|
+
# @returns [Class] The protocol class (defaults to HTTP/1.1).
|
18
30
|
def protocol
|
19
31
|
::Async::HTTP::Protocol::HTTP1
|
20
32
|
end
|
21
33
|
|
34
|
+
# The base URL for the HTTP server.
|
35
|
+
# @returns [String] The URL string with host and port (defaults to localhost:0 for auto-assigned port).
|
22
36
|
def url
|
23
|
-
|
37
|
+
"http://localhost:0"
|
24
38
|
end
|
25
39
|
|
40
|
+
# Get all bound URLs for the server endpoints.
|
41
|
+
# @returns [Array(String)] Array of URLs the server is bound to, sorted alphabetically.
|
26
42
|
def bound_urls
|
27
43
|
urls = []
|
28
44
|
|
@@ -44,61 +60,94 @@ module Sus::Fixtures
|
|
44
60
|
return urls
|
45
61
|
end
|
46
62
|
|
63
|
+
# Get the first bound URL for the server.
|
64
|
+
# @returns [String] The first bound URL, typically used for single-endpoint testing.
|
47
65
|
def bound_url
|
48
66
|
bound_urls.first
|
49
67
|
end
|
50
68
|
|
69
|
+
# Options for configuring the HTTP endpoint.
|
70
|
+
# @returns [Hash] Hash of endpoint options including port reuse and protocol settings.
|
51
71
|
def endpoint_options
|
52
72
|
{reuse_port: true, protocol: protocol}
|
53
73
|
end
|
54
74
|
|
75
|
+
# The HTTP endpoint configuration.
|
76
|
+
# @returns [Async::HTTP::Endpoint] Parsed endpoint with configured options.
|
55
77
|
def endpoint
|
56
78
|
::Async::HTTP::Endpoint.parse(url, **endpoint_options)
|
57
79
|
end
|
58
80
|
|
81
|
+
# Number of retries for client requests.
|
82
|
+
# @returns [Integer] Number of retry attempts (defaults to 1).
|
59
83
|
def retries
|
60
84
|
1
|
61
85
|
end
|
62
86
|
|
87
|
+
# The HTTP application/middleware to serve.
|
88
|
+
# @returns [Object] The application object that handles HTTP requests (defaults to HelloWorld middleware).
|
63
89
|
def app
|
64
90
|
::Protocol::HTTP::Middleware::HelloWorld
|
65
91
|
end
|
66
92
|
|
93
|
+
# The middleware stack for the HTTP server.
|
94
|
+
# @returns [Object] The middleware configuration (defaults to the app).
|
67
95
|
def middleware
|
68
96
|
app
|
69
97
|
end
|
70
98
|
|
99
|
+
# Create the server endpoint from a bound endpoint.
|
100
|
+
# @parameter bound_endpoint [Async::HTTP::Endpoint] The bound endpoint.
|
101
|
+
# @returns [Async::HTTP::Endpoint] The server endpoint configuration.
|
71
102
|
def make_server_endpoint(bound_endpoint)
|
72
103
|
bound_endpoint
|
73
104
|
end
|
74
105
|
|
106
|
+
# Create an HTTP server instance.
|
107
|
+
# @parameter endpoint [Async::HTTP::Endpoint] The endpoint to bind the server to.
|
108
|
+
# @returns [Async::HTTP::Server] The configured HTTP server.
|
75
109
|
def make_server(endpoint)
|
76
110
|
::Async::HTTP::Server.new(middleware, endpoint)
|
77
111
|
end
|
78
112
|
|
113
|
+
# The HTTP server instance.
|
114
|
+
# @returns [Async::HTTP::Server] The running HTTP server.
|
79
115
|
def server
|
80
116
|
@server
|
81
117
|
end
|
82
118
|
|
119
|
+
# The HTTP client instance.
|
120
|
+
# @returns [Async::HTTP::Client] The HTTP client configured to connect to the server.
|
83
121
|
def client
|
84
122
|
@client
|
85
123
|
end
|
86
124
|
|
125
|
+
# The client endpoint configuration.
|
126
|
+
# @returns [Async::HTTP::Endpoint] The endpoint the client uses to connect to the server.
|
87
127
|
def client_endpoint
|
88
128
|
@client_endpoint
|
89
129
|
end
|
90
130
|
|
131
|
+
# Create a client endpoint from a bound endpoint.
|
132
|
+
# @parameter bound_endpoint [Async::HTTP::Endpoint] The bound server endpoint.
|
133
|
+
# @returns [Async::HTTP::Endpoint] The client endpoint with local address and timeout.
|
91
134
|
def make_client_endpoint(bound_endpoint)
|
92
135
|
# Pass through the timeout:
|
93
136
|
bound_endpoint.local_address_endpoint(timeout: endpoint.timeout)
|
94
137
|
end
|
95
138
|
|
139
|
+
# Create an HTTP client instance.
|
140
|
+
# @parameter endpoint [Async::HTTP::Endpoint] The endpoint to connect to.
|
141
|
+
# @parameter options [Hash] Additional client options.
|
142
|
+
# @returns [Async::HTTP::Client] The configured HTTP client.
|
96
143
|
def make_client(endpoint, **options)
|
97
144
|
options[:retries] = retries unless options.key?(:retries)
|
98
145
|
|
99
146
|
::Async::HTTP::Client.new(endpoint, **options)
|
100
147
|
end
|
101
148
|
|
149
|
+
# Set up the server and client before running tests.
|
150
|
+
# This method binds the endpoint, starts the server, and creates a client.
|
102
151
|
def before
|
103
152
|
super
|
104
153
|
|
@@ -115,9 +164,7 @@ module Sus::Fixtures
|
|
115
164
|
|
116
165
|
@server = make_server(@server_endpoint)
|
117
166
|
|
118
|
-
@server_task =
|
119
|
-
@server.run
|
120
|
-
end
|
167
|
+
@server_task = @server.run
|
121
168
|
|
122
169
|
@client_endpoint = make_client_endpoint(@bound_endpoint)
|
123
170
|
mock(@client_endpoint) do |wrapper|
|
@@ -130,11 +177,15 @@ module Sus::Fixtures
|
|
130
177
|
@client = make_client(@client_endpoint)
|
131
178
|
end
|
132
179
|
|
180
|
+
# Clean up resources after running tests.
|
181
|
+
# This method closes the client, stops the server, and closes the bound endpoint.
|
182
|
+
# @parameter error [Exception | Nil] Any error that occurred during the test.
|
133
183
|
def after(error = nil)
|
134
184
|
# We add a timeout here, to avoid hanging in `@client.close`:
|
135
185
|
::Async::Task.current.with_timeout(1) do
|
136
186
|
@client&.close
|
137
187
|
@server_task&.stop
|
188
|
+
@server_task&.wait
|
138
189
|
@bound_endpoint&.close
|
139
190
|
end
|
140
191
|
|
@@ -3,5 +3,18 @@
|
|
3
3
|
# Released under the MIT License.
|
4
4
|
# Copyright, 2022-2023, by Samuel Williams.
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
# @namespace
|
7
|
+
module Sus
|
8
|
+
# @namespace
|
9
|
+
module Fixtures
|
10
|
+
# @namespace
|
11
|
+
module Async
|
12
|
+
# @namespace
|
13
|
+
module HTTP
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
require_relative "http/server_context"
|
20
|
+
require_relative "http/version"
|
data/license.md
CHANGED
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,12 +1,11 @@
|
|
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.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
- Felix Yan
|
9
|
-
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain:
|
12
11
|
- |
|
@@ -38,7 +37,7 @@ cert_chain:
|
|
38
37
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
39
38
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
40
39
|
-----END CERTIFICATE-----
|
41
|
-
date:
|
40
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
42
41
|
dependencies:
|
43
42
|
- !ruby/object:Gem::Dependency
|
44
43
|
name: async-http
|
@@ -82,8 +81,6 @@ dependencies:
|
|
82
81
|
- - "~>"
|
83
82
|
- !ruby/object:Gem::Version
|
84
83
|
version: '0.1'
|
85
|
-
description:
|
86
|
-
email:
|
87
84
|
executables: []
|
88
85
|
extensions: []
|
89
86
|
extra_rdoc_files: []
|
@@ -100,7 +97,6 @@ metadata:
|
|
100
97
|
documentation_uri: https://suspecting.github.io/sus-fixtures-async-http/
|
101
98
|
funding_uri: https://github.com/sponsors/ioquatix/
|
102
99
|
source_code_uri: https://github.com/suspecting/sus-fixtures-async-http.git
|
103
|
-
post_install_message:
|
104
100
|
rdoc_options: []
|
105
101
|
require_paths:
|
106
102
|
- lib
|
@@ -108,15 +104,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
108
104
|
requirements:
|
109
105
|
- - ">="
|
110
106
|
- !ruby/object:Gem::Version
|
111
|
-
version: '3.
|
107
|
+
version: '3.2'
|
112
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
109
|
requirements:
|
114
110
|
- - ">="
|
115
111
|
- !ruby/object:Gem::Version
|
116
112
|
version: '0'
|
117
113
|
requirements: []
|
118
|
-
rubygems_version: 3.
|
119
|
-
signing_key:
|
114
|
+
rubygems_version: 3.6.7
|
120
115
|
specification_version: 4
|
121
116
|
summary: Test fixtures for running in Async::HTTP.
|
122
117
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|