diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2021-09-22 14:53:45 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2021-09-22 14:53:45 -0700 |
commit | f889bd464296ffc96dc2fd27fbccdab409f732b8 (patch) | |
tree | 4718b4cf72136be5ab8a1eea43091de48f6b79db /spec | |
parent | 53e3465cea3eb349ee5fcdba65a147ef5d805b7b (diff) | |
download | chef-f889bd464296ffc96dc2fd27fbccdab409f732b8.tar.gz |
Add ability to modify net-http settings
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/http/basic_client_spec.rb | 30 | ||||
-rw-r--r-- | spec/unit/http_spec.rb | 10 |
2 files changed, 38 insertions, 2 deletions
diff --git a/spec/unit/http/basic_client_spec.rb b/spec/unit/http/basic_client_spec.rb index 0def00a220..57177ceac1 100644 --- a/spec/unit/http/basic_client_spec.rb +++ b/spec/unit/http/basic_client_spec.rb @@ -47,6 +47,36 @@ describe "HTTP Connection" do expect(Net::HTTP).to receive(:new).and_return(net_http_mock) expect(basic_client.http_client).to eql(net_http_mock) end + + it "allows setting net-http accessor options" do + basic_client = Chef::HTTP::BasicClient.new(uri, nethttp_opts: { + "continue_timeout" => 5, + "max_retries" => 5, + "read_timeout" => 5, + "write_timeout" => 5, + "ssl_timeout" => 5, + }) + expect(basic_client.http_client.continue_timeout).to eql(5) + expect(basic_client.http_client.max_retries).to eql(5) + expect(basic_client.http_client.read_timeout).to eql(5) + expect(basic_client.http_client.write_timeout).to eql(5) + expect(basic_client.http_client.ssl_timeout).to eql(5) + end + + it "allows setting net-http accssor options as symbols" do + basic_client = Chef::HTTP::BasicClient.new(uri, nethttp_opts: { + continue_timeout: 5, + max_retries: 5, + read_timeout: 5, + write_timeout: 5, + ssl_timeout: 5, + }) + expect(basic_client.http_client.continue_timeout).to eql(5) + expect(basic_client.http_client.max_retries).to eql(5) + expect(basic_client.http_client.read_timeout).to eql(5) + expect(basic_client.http_client.write_timeout).to eql(5) + expect(basic_client.http_client.ssl_timeout).to eql(5) + end end describe "#build_http_client" do diff --git a/spec/unit/http_spec.rb b/spec/unit/http_spec.rb index bb52db60fd..d7e2488440 100644 --- a/spec/unit/http_spec.rb +++ b/spec/unit/http_spec.rb @@ -46,13 +46,19 @@ describe Chef::HTTP do describe "#initialize" do it "accepts a keepalive option and passes it to the http_client" do http = Chef::HTTP.new(uri, keepalives: true) - expect(Chef::HTTP::BasicClient).to receive(:new).with(uri, ssl_policy: Chef::HTTP::APISSLPolicy, keepalives: true).and_call_original + expect(Chef::HTTP::BasicClient).to receive(:new).with(uri, ssl_policy: Chef::HTTP::APISSLPolicy, nethttp_opts: {}, keepalives: true).and_call_original expect(http.http_client).to be_a_kind_of(Chef::HTTP::BasicClient) end it "the default is not to use keepalives" do http = Chef::HTTP.new(uri) - expect(Chef::HTTP::BasicClient).to receive(:new).with(uri, ssl_policy: Chef::HTTP::APISSLPolicy, keepalives: false).and_call_original + expect(Chef::HTTP::BasicClient).to receive(:new).with(uri, ssl_policy: Chef::HTTP::APISSLPolicy, nethttp_opts: {}, keepalives: false).and_call_original + expect(http.http_client).to be_a_kind_of(Chef::HTTP::BasicClient) + end + + it "allows setting the nethttp options hash" do + http = Chef::HTTP.new(uri, { nethttp: { "continue_timeout" => 5 } }) + expect(Chef::HTTP::BasicClient).to receive(:new).with(uri, ssl_policy: Chef::HTTP::APISSLPolicy, nethttp_opts: { "continue_timeout" => 5 }, keepalives: false).and_call_original expect(http.http_client).to be_a_kind_of(Chef::HTTP::BasicClient) end end |