summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2016-08-11 13:14:32 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2016-08-11 13:14:32 -0700
commit8208d088a4bba794dbf5a0d5b39e1732edc2aec4 (patch)
tree66f2037f4d997f78e587d08cd9eba84e07139f75
parentc6659b70deb4b1f81bc5c20ed237b7637ff20930 (diff)
downloadchef-8208d088a4bba794dbf5a0d5b39e1732edc2aec4.tar.gz
specs and lazying net-http client building
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--.rubocop.yml1
-rw-r--r--lib/chef/http/basic_client.rb5
-rw-r--r--spec/unit/cookbook/synchronizer_spec.rb7
-rw-r--r--spec/unit/http/basic_client_spec.rb20
4 files changed, 32 insertions, 1 deletions
diff --git a/.rubocop.yml b/.rubocop.yml
index 3c2a48e548..2379a7b0a3 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -1,4 +1,5 @@
AllCops:
+ TargetRubyVersion: 2.2
Exclude:
- "spec/data/**/*"
- "vendor/**/*"
diff --git a/lib/chef/http/basic_client.rb b/lib/chef/http/basic_client.rb
index 921a28cad0..460744ea2a 100644
--- a/lib/chef/http/basic_client.rb
+++ b/lib/chef/http/basic_client.rb
@@ -45,7 +45,10 @@ class Chef
@url = url
@ssl_policy = opts[:ssl_policy] || DefaultSSLPolicy
@keepalives = opts[:keepalives] || false
- @http_client = build_http_client
+ end
+
+ def http_client
+ @http_client ||= build_http_client
end
def host
diff --git a/spec/unit/cookbook/synchronizer_spec.rb b/spec/unit/cookbook/synchronizer_spec.rb
index 3f5624f3b0..82876273e7 100644
--- a/spec/unit/cookbook/synchronizer_spec.rb
+++ b/spec/unit/cookbook/synchronizer_spec.rb
@@ -414,6 +414,13 @@ describe Chef::CookbookSynchronizer do
and_return("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb")
end
+ describe "#server_api" do
+ it "sets keepalive to true" do
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], keepalives: true)
+ synchronizer.server_api
+ end
+ end
+
describe "when syncing cookbooks with the server" do
let(:server_api) { double("Chef::ServerAPI (mock)") }
diff --git a/spec/unit/http/basic_client_spec.rb b/spec/unit/http/basic_client_spec.rb
index 8cf63d4441..79fd4ec042 100644
--- a/spec/unit/http/basic_client_spec.rb
+++ b/spec/unit/http/basic_client_spec.rb
@@ -29,6 +29,26 @@ describe "HTTP Connection" do
end
end
+ describe "#initialize" do
+ it "calls .start when doing keepalives" do
+ basic_client = Chef::HTTP::BasicClient.new(uri, keepalives: true)
+ expect(basic_client).to receive(:configure_ssl)
+ net_http_mock = instance_double(Net::HTTP, proxy_address: nil, "proxy_port=": nil, "read_timeout=": nil, "open_timeout=": nil)
+ expect(net_http_mock).to receive(:start).and_return(net_http_mock)
+ expect(Net::HTTP).to receive(:new).and_return(net_http_mock)
+ expect(basic_client.http_client).to eql(net_http_mock)
+ end
+
+ it "does not call .start when not doing keepalives" do
+ basic_client = Chef::HTTP::BasicClient.new(uri)
+ expect(basic_client).to receive(:configure_ssl)
+ net_http_mock = instance_double(Net::HTTP, proxy_address: nil, "proxy_port=": nil, "read_timeout=": nil, "open_timeout=": nil)
+ expect(net_http_mock).not_to receive(:start)
+ expect(Net::HTTP).to receive(:new).and_return(net_http_mock)
+ expect(basic_client.http_client).to eql(net_http_mock)
+ end
+ end
+
describe "#build_http_client" do
it "should build an http client" do
subject.build_http_client