hearth 1.0.0.pre1 → 1.0.0.pre3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -4
- data/VERSION +1 -1
- data/lib/hearth/anonymous_auth_resolver.rb +11 -0
- data/lib/hearth/api_error.rb +15 -1
- data/lib/hearth/auth_option.rb +21 -0
- data/lib/hearth/auth_schemes/anonymous.rb +21 -0
- data/lib/hearth/auth_schemes/http_api_key.rb +16 -0
- data/lib/hearth/auth_schemes/http_basic.rb +16 -0
- data/lib/hearth/auth_schemes/http_bearer.rb +16 -0
- data/lib/hearth/auth_schemes/http_digest.rb +16 -0
- data/lib/hearth/auth_schemes.rb +32 -0
- data/lib/hearth/checksums.rb +31 -0
- data/lib/hearth/client.rb +66 -0
- data/lib/hearth/client_stubs.rb +128 -0
- data/lib/hearth/config/env_provider.rb +53 -0
- data/lib/hearth/config/resolver.rb +53 -0
- data/lib/hearth/configuration.rb +15 -0
- data/lib/hearth/connection_pool.rb +77 -0
- data/lib/hearth/context.rb +29 -4
- data/lib/hearth/dns/host_address.rb +27 -0
- data/lib/hearth/dns/host_resolver.rb +92 -0
- data/lib/hearth/dns.rb +48 -0
- data/lib/hearth/endpoint_rules.rb +154 -0
- data/lib/hearth/http/api_error.rb +4 -8
- data/lib/hearth/http/client.rb +206 -59
- data/lib/hearth/http/error_inspector.rb +85 -0
- data/lib/hearth/http/error_parser.rb +18 -20
- data/lib/hearth/http/field.rb +49 -0
- data/lib/hearth/http/fields.rb +117 -0
- data/lib/hearth/http/header_list_builder.rb +42 -0
- data/lib/hearth/http/header_list_parser.rb +92 -0
- data/lib/hearth/http/middleware/content_length.rb +7 -4
- data/lib/hearth/http/middleware/content_md5.rb +30 -0
- data/lib/hearth/http/middleware/request_compression.rb +154 -0
- data/lib/hearth/http/middleware.rb +12 -0
- data/lib/hearth/http/networking_error.rb +1 -14
- data/lib/hearth/http/request.rb +83 -56
- data/lib/hearth/http/response.rb +42 -13
- data/lib/hearth/http.rb +16 -5
- data/lib/hearth/identities/anonymous.rb +8 -0
- data/lib/hearth/identities/http_api_key.rb +16 -0
- data/lib/hearth/identities/http_bearer.rb +16 -0
- data/lib/hearth/identities/http_login.rb +20 -0
- data/lib/hearth/identities.rb +21 -0
- data/lib/hearth/identity_provider.rb +17 -0
- data/lib/hearth/interceptor.rb +506 -0
- data/lib/hearth/interceptor_context.rb +40 -0
- data/lib/hearth/interceptor_list.rb +48 -0
- data/lib/hearth/interceptors.rb +76 -0
- data/lib/hearth/json.rb +4 -4
- data/lib/hearth/middleware/auth.rb +103 -0
- data/lib/hearth/middleware/build.rb +32 -1
- data/lib/hearth/middleware/endpoint.rb +79 -0
- data/lib/hearth/middleware/host_prefix.rb +11 -8
- data/lib/hearth/middleware/initialize.rb +57 -0
- data/lib/hearth/middleware/parse.rb +45 -7
- data/lib/hearth/middleware/retry.rb +105 -24
- data/lib/hearth/middleware/send.rb +137 -26
- data/lib/hearth/middleware/sign.rb +65 -0
- data/lib/hearth/middleware/validate.rb +11 -1
- data/lib/hearth/middleware.rb +20 -8
- data/lib/hearth/middleware_stack.rb +2 -44
- data/lib/hearth/networking_error.rb +18 -0
- data/lib/hearth/number_helper.rb +3 -3
- data/lib/hearth/output.rb +8 -4
- data/lib/hearth/plugin_list.rb +53 -0
- data/lib/hearth/query/param.rb +56 -0
- data/lib/hearth/query/param_list.rb +54 -0
- data/lib/hearth/query/param_matcher.rb +31 -0
- data/lib/hearth/refreshing_identity_provider.rb +63 -0
- data/lib/hearth/request.rb +22 -0
- data/lib/hearth/response.rb +36 -0
- data/lib/hearth/retry/adaptive.rb +60 -0
- data/lib/hearth/retry/capacity_not_available_error.rb +9 -0
- data/lib/hearth/retry/client_rate_limiter.rb +145 -0
- data/lib/hearth/retry/exponential_backoff.rb +15 -0
- data/lib/hearth/retry/retry_quota.rb +56 -0
- data/lib/hearth/retry/standard.rb +46 -0
- data/lib/hearth/retry.rb +29 -0
- data/lib/hearth/signers/anonymous.rb +16 -0
- data/lib/hearth/signers/http_api_key.rb +29 -0
- data/lib/hearth/signers/http_basic.rb +23 -0
- data/lib/hearth/signers/http_bearer.rb +19 -0
- data/lib/hearth/signers/http_digest.rb +19 -0
- data/lib/hearth/signers.rb +23 -0
- data/lib/hearth/structure.rb +7 -3
- data/lib/hearth/stubs.rb +38 -0
- data/lib/hearth/time_helper.rb +6 -5
- data/lib/hearth/validator.rb +60 -5
- data/lib/hearth/waiters/poller.rb +10 -9
- data/lib/hearth/waiters/waiter.rb +23 -9
- data/lib/hearth/xml/formatter.rb +11 -2
- data/lib/hearth/xml/node.rb +2 -3
- data/lib/hearth/xml/node_matcher.rb +0 -1
- data/lib/hearth.rb +37 -6
- data/sig/lib/hearth/aliases.rbs +6 -0
- data/sig/lib/hearth/anonymous_auth_resolver.rbs +5 -0
- data/sig/lib/hearth/api_error.rbs +13 -0
- data/sig/lib/hearth/auth_option.rbs +11 -0
- data/sig/lib/hearth/auth_schemes/anonymous.rbs +7 -0
- data/sig/lib/hearth/auth_schemes/http_api_key.rbs +7 -0
- data/sig/lib/hearth/auth_schemes/http_basic.rbs +7 -0
- data/sig/lib/hearth/auth_schemes/http_bearer.rbs +7 -0
- data/sig/lib/hearth/auth_schemes/http_digest.rbs +7 -0
- data/sig/lib/hearth/auth_schemes.rbs +13 -0
- data/sig/lib/hearth/block_io.rbs +9 -0
- data/sig/lib/hearth/client.rbs +9 -0
- data/sig/lib/hearth/client_stubs.rbs +5 -0
- data/sig/lib/hearth/configuration.rbs +7 -0
- data/sig/lib/hearth/dns/host_address.rbs +11 -0
- data/sig/lib/hearth/dns/host_resolver.rbs +19 -0
- data/sig/lib/hearth/endpoint_rules.rbs +17 -0
- data/sig/lib/hearth/http/api_error.rbs +13 -0
- data/sig/lib/hearth/http/client.rbs +9 -0
- data/sig/lib/hearth/http/field.rbs +19 -0
- data/sig/lib/hearth/http/fields.rbs +43 -0
- data/sig/lib/hearth/http/header_list_builder.rbs +15 -0
- data/sig/lib/hearth/http/header_list_parser.rbs +19 -0
- data/sig/lib/hearth/http/networking_error.rbs +6 -0
- data/sig/lib/hearth/http/request.rbs +25 -0
- data/sig/lib/hearth/http/response.rbs +21 -0
- data/sig/lib/hearth/identities/anonymous.rbs +6 -0
- data/sig/lib/hearth/identities/http_api_key.rbs +9 -0
- data/sig/lib/hearth/identities/http_bearer.rbs +9 -0
- data/sig/lib/hearth/identities/http_login.rbs +11 -0
- data/sig/lib/hearth/identities.rbs +9 -0
- data/sig/lib/hearth/identity_provider.rbs +7 -0
- data/sig/lib/hearth/interceptor.rbs +9 -0
- data/sig/lib/hearth/interceptor_context.rbs +17 -0
- data/sig/lib/hearth/interceptor_list.rbs +16 -0
- data/sig/lib/hearth/interfaces.rbs +87 -0
- data/sig/lib/hearth/json/parse_error.rbs +9 -0
- data/sig/lib/hearth/networking_error.rbs +7 -0
- data/sig/lib/hearth/output.rbs +11 -0
- data/sig/lib/hearth/plugin_list.rbs +13 -0
- data/sig/lib/hearth/query/param.rbs +17 -0
- data/sig/lib/hearth/query/param_list.rbs +25 -0
- data/sig/lib/hearth/refreshing_identity_provider.rbs +10 -0
- data/sig/lib/hearth/request.rbs +9 -0
- data/sig/lib/hearth/response.rbs +11 -0
- data/sig/lib/hearth/retry/adaptive.rbs +13 -0
- data/sig/lib/hearth/retry/exponential_backoff.rbs +7 -0
- data/sig/lib/hearth/retry/standard.rbs +13 -0
- data/sig/lib/hearth/retry/strategy.rbs +11 -0
- data/sig/lib/hearth/retry.rbs +9 -0
- data/sig/lib/hearth/signers/anonymous.rbs +9 -0
- data/sig/lib/hearth/signers/http_api_key.rbs +9 -0
- data/sig/lib/hearth/signers/http_basic.rbs +9 -0
- data/sig/lib/hearth/signers/http_bearer.rbs +9 -0
- data/sig/lib/hearth/signers/http_digest.rbs +9 -0
- data/sig/lib/hearth/signers.rbs +9 -0
- data/sig/lib/hearth/structure.rbs +6 -0
- data/sig/lib/hearth/stubs.rbs +9 -0
- data/sig/lib/hearth/union.rbs +5 -0
- data/sig/lib/hearth/waiters/waiter.rbs +17 -0
- data/sig/lib/hearth/xml/parse_error.rbs +9 -0
- metadata +151 -25
- data/lib/hearth/http/headers.rb +0 -70
- data/lib/hearth/middleware/around_handler.rb +0 -24
- data/lib/hearth/middleware/request_handler.rb +0 -24
- data/lib/hearth/middleware/response_handler.rb +0 -25
- data/lib/hearth/middleware_builder.rb +0 -246
- data/lib/hearth/stubbing/client_stubs.rb +0 -115
- data/lib/hearth/stubbing/stubs.rb +0 -32
- data/lib/hearth/waiters/errors.rb +0 -15
- data/sig/lib/seahorse/api_error.rbs +0 -10
- data/sig/lib/seahorse/document.rbs +0 -2
- data/sig/lib/seahorse/http/api_error.rbs +0 -21
- data/sig/lib/seahorse/http/headers.rbs +0 -47
- data/sig/lib/seahorse/http/response.rbs +0 -21
- data/sig/lib/seahorse/simple_delegator.rbs +0 -3
- data/sig/lib/seahorse/structure.rbs +0 -18
- data/sig/lib/seahorse/stubbing/client_stubs.rbs +0 -103
- data/sig/lib/seahorse/stubbing/stubs.rbs +0 -14
- data/sig/lib/seahorse/union.rbs +0 -6
@@ -1,115 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'stubs'
|
4
|
-
|
5
|
-
module Hearth
|
6
|
-
# This module provides the ability to specify the data and/or errors to
|
7
|
-
# return when a client is using stubbed responses.
|
8
|
-
# This module should be included in generated service clients.
|
9
|
-
#
|
10
|
-
# Pass `stub_responses: true` to a client constructor to enable this
|
11
|
-
# behavior.
|
12
|
-
module ClientStubs
|
13
|
-
# Configures what data / errors should be returned from the named operation
|
14
|
-
# when response stubbing is enabled.
|
15
|
-
#
|
16
|
-
# ## Basic usage
|
17
|
-
#
|
18
|
-
# When you enable response stubbing, the client will generate fake
|
19
|
-
# responses and will not make any HTTP requests.
|
20
|
-
#
|
21
|
-
# client = Service::Client.new(stub_responses: true)
|
22
|
-
# client.operation
|
23
|
-
# #=> #<struct Service:Types::Operation param1=[], param2=nil>
|
24
|
-
#
|
25
|
-
# You can specify the stub data using {#stub_responses}
|
26
|
-
#
|
27
|
-
# client = Service::Client.new(stub_responses: true)
|
28
|
-
# client.stub_responses(:operation, {
|
29
|
-
# param1: [{ name: 'value1' }]
|
30
|
-
# })
|
31
|
-
#
|
32
|
-
# client.operation.param1.map(&:name)
|
33
|
-
# #=> ['value1']
|
34
|
-
#
|
35
|
-
# ## Stubbing Errors
|
36
|
-
#
|
37
|
-
# When stubbing is enabled, the SDK will default to generate
|
38
|
-
# fake responses with placeholder values. You can override the data
|
39
|
-
# returned. You can also specify errors it should raise.
|
40
|
-
#
|
41
|
-
# # to simulate errors, give the error class, you must
|
42
|
-
# # be able to construct an instance with `.new`
|
43
|
-
# client.stub_responses(:operation, Timeout::Error)
|
44
|
-
# client.operation(param1: 'value')
|
45
|
-
# #=> raises new Timeout::Error
|
46
|
-
#
|
47
|
-
# # or you can give an instance of an error class
|
48
|
-
# client.stub_responses(:operation, RuntimeError.new('custom message'))
|
49
|
-
# client.operation(param1: 'value')
|
50
|
-
# #=> raises the given runtime error object
|
51
|
-
#
|
52
|
-
# ## Dynamic Stubbing
|
53
|
-
#
|
54
|
-
# In addition to creating static stubs, it's also possible to generate
|
55
|
-
# stubs dynamically based on the parameters with which operations were
|
56
|
-
# called, by passing a `Proc` object:
|
57
|
-
#
|
58
|
-
# client.stub_responses(:operation, -> (context) {
|
59
|
-
# if context.params[:param] == 'foo'
|
60
|
-
# # return a stub
|
61
|
-
# { param1: [{ name: 'value1'}]}
|
62
|
-
# else
|
63
|
-
# # return an error
|
64
|
-
# Services::Errors::NotFound
|
65
|
-
# end
|
66
|
-
# })
|
67
|
-
#
|
68
|
-
# ## Stubbing Raw Protocol Responses
|
69
|
-
#
|
70
|
-
# As an alternative to providing the response data, you can modify the
|
71
|
-
# response object provided by the `Proc` object and then
|
72
|
-
# return nil.
|
73
|
-
#
|
74
|
-
# client.stub_responses(:operation, -> (context) {
|
75
|
-
# context.response.status = 404 # simulate an error
|
76
|
-
# nil
|
77
|
-
# })
|
78
|
-
#
|
79
|
-
# ## Stubbing Multiple Responses
|
80
|
-
#
|
81
|
-
# Calling an operation multiple times will return similar responses.
|
82
|
-
# You can configure multiple stubs and they will be returned in sequence.
|
83
|
-
#
|
84
|
-
# client.stub_responses(:operation, [
|
85
|
-
# Errors::NotFound,
|
86
|
-
# { content_length: 150 },
|
87
|
-
# ])
|
88
|
-
#
|
89
|
-
# client.operation(param1: 'value1')
|
90
|
-
# #=> raises Errors::NotFound
|
91
|
-
#
|
92
|
-
# resp = client.operation(param1: 'value2')
|
93
|
-
# resp.content_length #=> 150
|
94
|
-
#
|
95
|
-
# @param [Symbol] operation_name
|
96
|
-
#
|
97
|
-
# @param [Mixed] stubs One or more responses to return from the named
|
98
|
-
# operation.
|
99
|
-
#
|
100
|
-
# @return [void]
|
101
|
-
#
|
102
|
-
# @raise [RuntimeError] Raises a runtime error when called
|
103
|
-
# on a client that has not enabled response stubbing via
|
104
|
-
# `:stub_responses => true`.
|
105
|
-
def stub_responses(operation_name, *stubs)
|
106
|
-
if @stub_responses
|
107
|
-
@stubs.add_stubs(operation_name, stubs.flatten)
|
108
|
-
else
|
109
|
-
msg = 'Stubbing is not enabled. Enable stubbing in the constructor '\
|
110
|
-
'with `stub_responses: true`'
|
111
|
-
raise ArgumentError, msg
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Hearth
|
4
|
-
# @api private
|
5
|
-
module Stubbing
|
6
|
-
# Provides a thread safe data structure for adding and getting stubs
|
7
|
-
# per operation.
|
8
|
-
class Stubs
|
9
|
-
def initialize
|
10
|
-
@stubs = {}
|
11
|
-
@stub_mutex = Mutex.new
|
12
|
-
end
|
13
|
-
|
14
|
-
def add_stubs(operation_name, stubs)
|
15
|
-
@stub_mutex.synchronize do
|
16
|
-
@stubs[operation_name.to_sym] = stubs
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def next(operation_name)
|
21
|
-
@stub_mutex.synchronize do
|
22
|
-
stubs = @stubs[operation_name] || []
|
23
|
-
case stubs.length
|
24
|
-
when 0 then nil
|
25
|
-
when 1 then stubs.first
|
26
|
-
else stubs.shift
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Hearth
|
4
|
-
module Waiters
|
5
|
-
module Errors
|
6
|
-
class WaiterFailed < StandardError; end
|
7
|
-
|
8
|
-
class FailureStateError < StandardError; end
|
9
|
-
|
10
|
-
class UnexpectedError < StandardError; end
|
11
|
-
|
12
|
-
class MaxWaitTimeExceeded < StandardError; end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
module Hearth
|
2
|
-
# Base class for errors returned from an API. This excludes networking
|
3
|
-
# errors and errors generated on the client-side.
|
4
|
-
class ApiError < StandardError
|
5
|
-
def initialize: (error_code: String, ?message: String) -> ApiError
|
6
|
-
|
7
|
-
# @return [String]
|
8
|
-
attr_reader error_code: String
|
9
|
-
end
|
10
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Hearth
|
2
|
-
module HTTP
|
3
|
-
# Base class for HTTP errors returned from an API. Inherits from
|
4
|
-
# {Hearth::ApiError}.
|
5
|
-
class ApiError < Hearth::ApiError
|
6
|
-
def initialize: (http_resp: Response, **untyped kwargs) -> ApiError
|
7
|
-
|
8
|
-
# @return [Integer]
|
9
|
-
attr_reader http_status: Integer
|
10
|
-
|
11
|
-
# @return [Hash<String, String>]
|
12
|
-
attr_reader http_headers: Hash[String, String]
|
13
|
-
|
14
|
-
# @return [String]
|
15
|
-
attr_reader http_body: String
|
16
|
-
|
17
|
-
# @return [String]
|
18
|
-
attr_reader request_id: String
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
module Hearth
|
2
|
-
module HTTP
|
3
|
-
# Provides Hash like access for Headers with key normalization
|
4
|
-
# @api private
|
5
|
-
class Headers
|
6
|
-
# @param [Hash<String,String>] headers
|
7
|
-
def initialize: (?headers: ::Hash[String, String] headers) -> Headers
|
8
|
-
|
9
|
-
# @param [String] key
|
10
|
-
def []: (String key) -> String
|
11
|
-
|
12
|
-
# @param [String] key
|
13
|
-
# @param [String] value
|
14
|
-
def []=: (String key, String value) -> String
|
15
|
-
|
16
|
-
# @param [String] key
|
17
|
-
# @return [Boolean] Returns `true` if there is a header with
|
18
|
-
# the given key.
|
19
|
-
def key?: (String key) -> bool
|
20
|
-
|
21
|
-
# @return [Array<String>]
|
22
|
-
def keys: () -> Array[String]
|
23
|
-
|
24
|
-
# @param [String] key
|
25
|
-
# @return [String, nil] Returns the value for the deleted key.
|
26
|
-
def delete: (String key) -> (String | nil)
|
27
|
-
|
28
|
-
# @return [Enumerable<String,String>]
|
29
|
-
def each_pair: () { () -> String } -> Enumerable[Array[String]]
|
30
|
-
|
31
|
-
alias each each_pair
|
32
|
-
|
33
|
-
# @return [Hash]
|
34
|
-
def to_hash: () -> Hash[String, String]
|
35
|
-
|
36
|
-
alias to_h to_hash
|
37
|
-
|
38
|
-
# @return [Integer] Returns the number of entries in the headers
|
39
|
-
# hash.
|
40
|
-
def size: () -> Integer
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def normalize: (String key) -> String
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Hearth
|
2
|
-
module HTTP
|
3
|
-
# Represents an HTTP Response.
|
4
|
-
# @api private
|
5
|
-
class Response
|
6
|
-
# @param [Integer] status
|
7
|
-
# @param [Headers] headers
|
8
|
-
# @param [IO] body
|
9
|
-
def initialize: (?status: ::Integer status, ?headers: Headers headers, ?body: IO body) -> Response
|
10
|
-
|
11
|
-
# @return [Integer]
|
12
|
-
attr_accessor status: Integer
|
13
|
-
|
14
|
-
# @return [Headers]
|
15
|
-
attr_accessor headers: Headers
|
16
|
-
|
17
|
-
# @return [IO]
|
18
|
-
attr_accessor body: IO
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module Hearth
|
2
|
-
# A module mixed into Structs that provides utility methods.
|
3
|
-
module Structure
|
4
|
-
# Deeply converts the Struct into a hash. Structure members that
|
5
|
-
# are `nil` are omitted from the resultant hash.
|
6
|
-
#
|
7
|
-
# @return [Hash]
|
8
|
-
def to_h: (?untyped obj) -> Hash[Symbol,untyped]
|
9
|
-
|
10
|
-
alias to_hash to_h
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def _to_h_struct: (untyped obj) -> untyped
|
15
|
-
|
16
|
-
def _to_h_hash: (untyped obj) -> untyped
|
17
|
-
end
|
18
|
-
end
|
@@ -1,103 +0,0 @@
|
|
1
|
-
module Hearth
|
2
|
-
# This module provides the ability to specify the data and/or errors to
|
3
|
-
# return when a client is using stubbed responses.
|
4
|
-
# This module should be included in generated service clients.
|
5
|
-
#
|
6
|
-
# Pass `stub_responses: true` to a client constructor to enable this
|
7
|
-
# behavior.
|
8
|
-
module ClientStubs
|
9
|
-
# Configures what data / errors should be returned from the named operation
|
10
|
-
# when response stubbing is enabled.
|
11
|
-
#
|
12
|
-
# ## Basic usage
|
13
|
-
#
|
14
|
-
# When you enable response stubbing, the client will generate fake
|
15
|
-
# responses and will not make any HTTP requests.
|
16
|
-
#
|
17
|
-
# client = Service::Client.new(stub_responses: true)
|
18
|
-
# client.operation
|
19
|
-
# #=> #<struct Service:Types::Operation param1=[], param2=nil>
|
20
|
-
#
|
21
|
-
# You can specify the stub data using {#stub_responses}
|
22
|
-
#
|
23
|
-
# client = Service::Client.new(stub_responses: true)
|
24
|
-
# client.stub_responses(:operation, {
|
25
|
-
# param1: [{ name: 'value1' }]
|
26
|
-
# })
|
27
|
-
#
|
28
|
-
# client.operation.param1.map(&:name)
|
29
|
-
# #=> ['value1']
|
30
|
-
#
|
31
|
-
# ## Stubbing Errors
|
32
|
-
#
|
33
|
-
# When stubbing is enabled, the SDK will default to generate
|
34
|
-
# fake responses with placeholder values. You can override the data
|
35
|
-
# returned. You can also specify errors it should raise.
|
36
|
-
#
|
37
|
-
# # to simulate errors, give the error class, you must
|
38
|
-
# # be able to construct an instance with `.new`
|
39
|
-
# client.stub_responses(:operation, Timeout::Error)
|
40
|
-
# client.operation(param1: 'value')
|
41
|
-
# #=> raises new Timeout::Error
|
42
|
-
#
|
43
|
-
# # or you can give an instance of an error class
|
44
|
-
# client.stub_responses(:operation, RuntimeError.new('custom message'))
|
45
|
-
# client.operation(param1: 'value')
|
46
|
-
# #=> raises the given runtime error object
|
47
|
-
#
|
48
|
-
# ## Dynamic Stubbing
|
49
|
-
#
|
50
|
-
# In addition to creating static stubs, it's also possible to generate
|
51
|
-
# stubs dynamically based on the parameters with which operations were
|
52
|
-
# called, by passing a `Proc` object:
|
53
|
-
#
|
54
|
-
# client.stub_responses(:operation, -> (context) {
|
55
|
-
# if context.params[:param] == 'foo'
|
56
|
-
# # return a stub
|
57
|
-
# { param1: [{ name: 'value1'}]}
|
58
|
-
# else
|
59
|
-
# # return an error
|
60
|
-
# Services::Errors::NotFound
|
61
|
-
# end
|
62
|
-
# })
|
63
|
-
#
|
64
|
-
# ## Stubbing Raw Protocol Responses
|
65
|
-
#
|
66
|
-
# As an alternative to providing the response data, you can modify the
|
67
|
-
# response object provided by the `Proc` object and then
|
68
|
-
# return nil.
|
69
|
-
#
|
70
|
-
# client.stub_responses(:operation, -> (context) {
|
71
|
-
# context.response.status = 404 # simulate an error
|
72
|
-
# nil
|
73
|
-
# })
|
74
|
-
#
|
75
|
-
# ## Stubbing Multiple Responses
|
76
|
-
#
|
77
|
-
# Calling an operation multiple times will return similar responses.
|
78
|
-
# You can configure multiple stubs and they will be returned in sequence.
|
79
|
-
#
|
80
|
-
# client.stub_responses(:operation, [
|
81
|
-
# Errors::NotFound,
|
82
|
-
# { content_length: 150 },
|
83
|
-
# ])
|
84
|
-
#
|
85
|
-
# client.operation(param1: 'value1')
|
86
|
-
# #=> raises Errors::NotFound
|
87
|
-
#
|
88
|
-
# resp = client.operation(param1: 'value2')
|
89
|
-
# resp.content_length #=> 150
|
90
|
-
#
|
91
|
-
# @param [Symbol] operation_name
|
92
|
-
#
|
93
|
-
# @param [Mixed] stubs One or more responses to return from the named
|
94
|
-
# operation.
|
95
|
-
#
|
96
|
-
# @return [void]
|
97
|
-
#
|
98
|
-
# @raise [RuntimeError] Raises a runtime error when called
|
99
|
-
# on a client that has not enabled response stubbing via
|
100
|
-
# `:stub_responses => true`.
|
101
|
-
def stub_responses: (Symbol operation_name, *Hearth::Stubbing::Stubs stubs) -> void
|
102
|
-
end
|
103
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Hearth
|
2
|
-
# @api private
|
3
|
-
module Stubbing
|
4
|
-
# Provides a thread safe data structure for adding and getting stubs
|
5
|
-
# per operation.
|
6
|
-
class Stubs
|
7
|
-
def initialize: () -> Stubs
|
8
|
-
|
9
|
-
def add_stubs: (Symbol operation_name, Array[Hash[Symbol, untyped]] | Proc | StandardError stubs) -> void
|
10
|
-
|
11
|
-
def next: (Symbol operation_name) -> Hash[Symbol, untyped]
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|