Skip to content

Commit 2d209ca

Browse files
author
Matt Muller
committed
Fix default endpoint for stub responses
1 parent e373f3d commit 2d209ca

4 files changed

Lines changed: 7 additions & 14 deletions

File tree

gems/smithy-client/lib/smithy-client/plugins/stub_responses.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@ def add_handlers(handlers, config)
2929
handlers.add(StubHandler, step: :send)
3030
end
3131

32-
def before_initialize(_client_class, options)
33-
return unless options[:stub_responses]
34-
return if options.key?(:endpoint) || options.key?(:endpoint_provider)
35-
36-
options[:endpoint] = 'http://stubbed-endpoint'
37-
end
38-
3932
def after_initialize(client)
4033
return unless client.config.stub_responses
4134

gems/smithy-client/spec/smithy-client/plugins/stub_responses_spec.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@ module Plugins
4141
expect(client.config.endpoint).to eq('https://example.com')
4242
end
4343

44-
it 'does not default the endpoint if a custom endpoint provider is set' do
45-
endpoint_provider = double('endpoint-provider')
46-
client = client_class.new(stub_responses: true, endpoint_provider: endpoint_provider)
47-
expect(client.config.endpoint_provider).to be(endpoint_provider)
48-
expect(client.config.endpoint).to be_nil
49-
end
50-
5144
it 'signals error for exceptions' do
5245
expect_any_instance_of(Http::Response).to receive(:signal_error)
5346
client.stub_responses(:operation, RuntimeError.new('error'))

gems/smithy/lib/smithy/templates/client/endpoint_plugin.erb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ module <%= module_name %>
3737
<%= endpoint_auth_scheme_bindings %>
3838
end
3939

40+
def before_initialize(_client_class, options)
41+
return unless options[:stub_responses]
42+
43+
options[:endpoint] = 'http://stubbed-endpoint' unless options.key?(:endpoint)
44+
end
45+
4046
# @api private
4147
class Handler < Smithy::Client::Handler
4248
def call(context)

gems/smithy/lib/smithy/templates/client/endpoint_provider_spec.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module <%= module_name %>
3232
it 'produces the correct output from the client when calling <%= operation_input.operation_name %>' do
3333
client = Client.new(
3434
stub_responses: true,
35+
endpoint: nil,
3536
endpoint_provider: subject,
3637
<% operation_input.client_params.each do |p| -%>
3738
<%= p.param %>: <%= p.value %>,

0 commit comments

Comments
 (0)