diff options
-rw-r--r-- | CHANGELOG.md | 8 | ||||
-rw-r--r-- | Gemfile.lock | 36 | ||||
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | chef-bin/lib/chef-bin/version.rb | 2 | ||||
-rw-r--r-- | chef-config/lib/chef-config/version.rb | 2 | ||||
-rw-r--r-- | chef-utils/lib/chef-utils/version.rb | 2 | ||||
-rw-r--r-- | knife/lib/chef/knife/version.rb | 2 | ||||
-rw-r--r-- | lib/chef/provider/http_request.rb | 20 | ||||
-rw-r--r-- | lib/chef/version.rb | 2 | ||||
-rw-r--r-- | spec/unit/provider/http_request_spec.rb | 132 | ||||
-rw-r--r-- | tasks/rspec.rb | 2 |
11 files changed, 101 insertions, 109 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e7e19fd6d..78c0d55220 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,17 +1,19 @@ <!-- usage documentation: http://expeditor-docs.es.chef.io/configuration/changelog/ --> This changelog lists individual merged pull requests to Chef Infra Client and geared towards developers. For a list of significant changes per release see the [Chef Infra Client Release Notes](https://docs.chef.io/release_notes_client/). -<!-- latest_release 18.0.65 --> -## [v18.0.65](https://github.com/chef/chef/tree/v18.0.65) (2022-03-02) +<!-- latest_release 18.0.67 --> +## [v18.0.67](https://github.com/chef/chef/tree/v18.0.67) (2022-03-15) #### Merged Pull Requests -- turn off caching for adhoc pipelines [#12661](https://github.com/chef/chef/pull/12661) ([lamont-granquist](https://github.com/lamont-granquist)) +- Modernize the http_request resource code and specs [#12682](https://github.com/chef/chef/pull/12682) ([lamont-granquist](https://github.com/lamont-granquist)) <!-- latest_release --> <!-- release_rollup since=17.9.26 --> ### Changes not yet released to stable #### Merged Pull Requests +- Modernize the http_request resource code and specs [#12682](https://github.com/chef/chef/pull/12682) ([lamont-granquist](https://github.com/lamont-granquist)) <!-- 18.0.67 --> +- Updated Rspec to add verbose logging [#12683](https://github.com/chef/chef/pull/12683) ([johnmccrae](https://github.com/johnmccrae)) <!-- 18.0.66 --> - turn off caching for adhoc pipelines [#12661](https://github.com/chef/chef/pull/12661) ([lamont-granquist](https://github.com/lamont-granquist)) <!-- 18.0.65 --> - Add OMNITRUCK_URL dist constant [#12654](https://github.com/chef/chef/pull/12654) ([ramereth](https://github.com/ramereth)) <!-- 18.0.64 --> - Update to libffi 3.4.2 [#12658](https://github.com/chef/chef/pull/12658) ([tas50](https://github.com/tas50)) <!-- 18.0.63 --> diff --git a/Gemfile.lock b/Gemfile.lock index c929a8ec4a..c6ea13d32f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -35,12 +35,12 @@ GIT PATH remote: . specs: - chef (18.0.65) + chef (18.0.67) addressable aws-sdk-s3 (~> 1.91) aws-sdk-secretsmanager (~> 1.46) - chef-config (= 18.0.65) - chef-utils (= 18.0.65) + chef-config (= 18.0.67) + chef-utils (= 18.0.67) chef-vault chef-zero (>= 14.0.11) corefoundation (~> 0.3.4) @@ -68,13 +68,13 @@ PATH train-winrm (>= 0.2.5) uuidtools (>= 2.1.5, < 3.0) vault (~> 0.16) - chef (18.0.65-universal-mingw32) + chef (18.0.67-universal-mingw32) addressable aws-sdk-s3 (~> 1.91) aws-sdk-secretsmanager (~> 1.46) - chef-config (= 18.0.65) + chef-config (= 18.0.67) chef-powershell (~> 1.0.12) - chef-utils (= 18.0.65) + chef-utils (= 18.0.67) chef-vault chef-zero (>= 14.0.11) corefoundation (~> 0.3.4) @@ -117,15 +117,15 @@ PATH PATH remote: chef-bin specs: - chef-bin (18.0.65) - chef (= 18.0.65) + chef-bin (18.0.67) + chef (= 18.0.67) PATH remote: chef-config specs: - chef-config (18.0.65) + chef-config (18.0.67) addressable - chef-utils (= 18.0.65) + chef-utils (= 18.0.67) fuzzyurl mixlib-config (>= 2.2.12, < 4.0) mixlib-shellout (>= 2.0, < 4.0) @@ -134,7 +134,7 @@ PATH PATH remote: chef-utils specs: - chef-utils (18.0.65) + chef-utils (18.0.67) concurrent-ruby GEM @@ -147,8 +147,8 @@ GEM mixlib-shellout (>= 2.0, < 4.0) ast (2.4.2) aws-eventstream (1.2.0) - aws-partitions (1.561.0) - aws-sdk-core (3.127.0) + aws-partitions (1.567.0) + aws-sdk-core (3.130.0) aws-eventstream (~> 1, >= 1.0.2) aws-partitions (~> 1, >= 1.525.0) aws-sigv4 (~> 1.1) @@ -160,7 +160,7 @@ GEM aws-sdk-core (~> 3, >= 3.127.0) aws-sdk-kms (~> 1) aws-sigv4 (~> 1.4) - aws-sdk-secretsmanager (1.58.0) + aws-sdk-secretsmanager (1.59.0) aws-sdk-core (~> 3, >= 3.127.0) aws-sigv4 (~> 1.1) aws-sigv4 (1.4.0) @@ -267,7 +267,7 @@ GEM io-wait (0.2.1) ipaddress (0.8.3) iso8601 (0.13.0) - jmespath (1.6.0) + jmespath (1.6.1) json (2.6.1) libyajl2 (2.1.0) license-acceptance (2.1.13) @@ -434,9 +434,9 @@ GEM tty-screen (~> 0.8) unf (0.1.4) unf_ext - unf_ext (0.0.8) - unf_ext (0.0.8-x64-mingw32) - unf_ext (0.0.8-x86-mingw32) + unf_ext (0.0.8.1) + unf_ext (0.0.8.1-x64-mingw32) + unf_ext (0.0.8.1-x86-mingw32) unicode-display_width (2.1.0) unicode_utils (1.4.0) uuidtools (2.2.0) @@ -1 +1 @@ -18.0.65
\ No newline at end of file +18.0.67
\ No newline at end of file diff --git a/chef-bin/lib/chef-bin/version.rb b/chef-bin/lib/chef-bin/version.rb index 1ec4f36b60..13ab925ba6 100644 --- a/chef-bin/lib/chef-bin/version.rb +++ b/chef-bin/lib/chef-bin/version.rb @@ -21,7 +21,7 @@ module ChefBin CHEFBIN_ROOT = File.expand_path("..", __dir__) - VERSION = "18.0.65".freeze + VERSION = "18.0.67".freeze end # diff --git a/chef-config/lib/chef-config/version.rb b/chef-config/lib/chef-config/version.rb index 532274ba55..35f9d97c87 100644 --- a/chef-config/lib/chef-config/version.rb +++ b/chef-config/lib/chef-config/version.rb @@ -15,5 +15,5 @@ module ChefConfig CHEFCONFIG_ROOT = File.expand_path("..", __dir__) - VERSION = "18.0.65".freeze + VERSION = "18.0.67".freeze end diff --git a/chef-utils/lib/chef-utils/version.rb b/chef-utils/lib/chef-utils/version.rb index b9c2a3ab87..42dde4931e 100644 --- a/chef-utils/lib/chef-utils/version.rb +++ b/chef-utils/lib/chef-utils/version.rb @@ -16,5 +16,5 @@ module ChefUtils CHEFUTILS_ROOT = File.expand_path("..", __dir__) - VERSION = "18.0.65" + VERSION = "18.0.67" end diff --git a/knife/lib/chef/knife/version.rb b/knife/lib/chef/knife/version.rb index 6c44bcdabf..110d1d9a1e 100644 --- a/knife/lib/chef/knife/version.rb +++ b/knife/lib/chef/knife/version.rb @@ -17,7 +17,7 @@ class Chef class Knife KNIFE_ROOT = File.expand_path("../..", __dir__) - VERSION = "18.0.65".freeze + VERSION = "18.0.67".freeze end end diff --git a/lib/chef/provider/http_request.rb b/lib/chef/provider/http_request.rb index 8e7a7f1fc9..0b25c728cf 100644 --- a/lib/chef/provider/http_request.rb +++ b/lib/chef/provider/http_request.rb @@ -25,18 +25,20 @@ class Chef provides :http_request - attr_accessor :http + attr_writer :http - def load_current_resource - @http = Chef::HTTP::Simple.new(new_resource.url) + def http + @http ||= Chef::HTTP::Simple.new(new_resource.url) end + def load_current_resource; end + # Send a HEAD request to new_resource.url action :head do message = check_message(new_resource.message) # CHEF-4762: we expect a nil return value from Chef::HTTP for a "200 Success" response # and false for a "304 Not Modified" response - modified = @http.head( + modified = http.head( (new_resource.url).to_s, new_resource.headers ) @@ -53,7 +55,7 @@ class Chef converge_by("#{new_resource} GET to #{new_resource.url}") do message = check_message(new_resource.message) - body = @http.get( + body = http.get( (new_resource.url).to_s, new_resource.headers ) @@ -66,7 +68,7 @@ class Chef action :patch do converge_by("#{new_resource} PATCH to #{new_resource.url}") do message = check_message(new_resource.message) - body = @http.patch( + body = http.patch( (new_resource.url).to_s, message, new_resource.headers @@ -80,7 +82,7 @@ class Chef action :put do converge_by("#{new_resource} PUT to #{new_resource.url}") do message = check_message(new_resource.message) - body = @http.put( + body = http.put( (new_resource.url).to_s, message, new_resource.headers @@ -94,7 +96,7 @@ class Chef action :post do converge_by("#{new_resource} POST to #{new_resource.url}") do message = check_message(new_resource.message) - body = @http.post( + body = http.post( (new_resource.url).to_s, message, new_resource.headers @@ -107,7 +109,7 @@ class Chef # Send a DELETE request to new_resource.url action :delete do converge_by("#{new_resource} DELETE to #{new_resource.url}") do - body = @http.delete( + body = http.delete( (new_resource.url).to_s, new_resource.headers ) diff --git a/lib/chef/version.rb b/lib/chef/version.rb index 3d2e499340..1668b194b2 100644 --- a/lib/chef/version.rb +++ b/lib/chef/version.rb @@ -23,7 +23,7 @@ require_relative "version_string" class Chef CHEF_ROOT = File.expand_path("..", __dir__) - VERSION = Chef::VersionString.new("18.0.65") + VERSION = Chef::VersionString.new("18.0.67") end # diff --git a/spec/unit/provider/http_request_spec.rb b/spec/unit/provider/http_request_spec.rb index b30ed2dd30..595b1f4295 100644 --- a/spec/unit/provider/http_request_spec.rb +++ b/spec/unit/provider/http_request_spec.rb @@ -19,87 +19,75 @@ require "spec_helper" describe Chef::Provider::HttpRequest do - before(:each) do - @node = Chef::Node.new - @events = Chef::EventDispatch::Dispatcher.new - @run_context = Chef::RunContext.new(@node, {}, @events) - - @new_resource = Chef::Resource::HttpRequest.new("adam") - @new_resource.name "adam" - @new_resource.url "http://www.opscode.com/" - @new_resource.message "is cool" - - @provider = Chef::Provider::HttpRequest.new(@new_resource, @run_context) - end - - describe "load_current_resource" do - - it "should set up a Chef::ServerAPI client, with no authentication" do - expect(Chef::HTTP::Simple).to receive(:new).with(@new_resource.url) - @provider.load_current_resource + let(:node) { Chef::Node.new } + let(:events) { Chef::EventDispatch::Dispatcher.new } + let(:run_context) { Chef::RunContext.new(node, {}, events) } + let(:new_resource) do + Chef::Resource::HttpRequest.new("adam").tap do |new_resource| + new_resource.name "adam" + new_resource.url "http://www.opscode.com/" + new_resource.message "is cool" end end + let(:provider) { Chef::Provider::HttpRequest.new(new_resource, run_context) } + describe "when making REST calls" do - before(:each) do - # run_action(x) forces load_current_resource to run; - # that would overwrite our supplied mock Chef::Rest # object - allow(@provider).to receive(:load_current_resource).and_return(true) - @http = double("Chef::ServerAPI") - @provider.http = @http + let(:http) do + provider.http = double("Chef::ServerAPI") end describe "action_get" do it "should inflate a message block at runtime" do - @new_resource.message { "return" } - expect(@http).to receive(:get).with("http://www.opscode.com/", {}) - @provider.run_action(:get) - expect(@new_resource).to be_updated + new_resource.message { "return" } + expect(http).to receive(:get).with("http://www.opscode.com/", {}) + provider.run_action(:get) + expect(new_resource).to be_updated end it "should run a GET request" do - expect(@http).to receive(:get).with("http://www.opscode.com/", {}) - @provider.run_action(:get) - expect(@new_resource).to be_updated + expect(http).to receive(:get).with("http://www.opscode.com/", {}) + provider.run_action(:get) + expect(new_resource).to be_updated end end describe "action_put" do it "should run a PUT request with the message as the payload" do - expect(@http).to receive(:put).with("http://www.opscode.com/", @new_resource.message, {}) - @provider.run_action(:put) - expect(@new_resource).to be_updated + expect(http).to receive(:put).with("http://www.opscode.com/", new_resource.message, {}) + provider.run_action(:put) + expect(new_resource).to be_updated end it "should inflate a message block at runtime" do - @new_resource.message(lambda { "return" }) - expect(@http).to receive(:put).with("http://www.opscode.com/", "return", {}) - @provider.run_action(:put) - expect(@new_resource).to be_updated + new_resource.message(lambda { "return" }) + expect(http).to receive(:put).with("http://www.opscode.com/", "return", {}) + provider.run_action(:put) + expect(new_resource).to be_updated end end describe "action_post" do it "should run a PUT request with the message as the payload" do - expect(@http).to receive(:post).with("http://www.opscode.com/", @new_resource.message, {}) - @provider.run_action(:post) - expect(@new_resource).to be_updated + expect(http).to receive(:post).with("http://www.opscode.com/", new_resource.message, {}) + provider.run_action(:post) + expect(new_resource).to be_updated end it "should inflate a message block at runtime" do - @new_resource.message { "return" } - expect(@http).to receive(:post).with("http://www.opscode.com/", "return", {}) - @provider.run_action(:post) - expect(@new_resource).to be_updated + new_resource.message { "return" } + expect(http).to receive(:post).with("http://www.opscode.com/", "return", {}) + provider.run_action(:post) + expect(new_resource).to be_updated end end describe "action_delete" do it "should run a DELETE request" do - expect(@http).to receive(:delete).with("http://www.opscode.com/", {}) - @provider.run_action(:delete) - expect(@new_resource).to be_updated + expect(http).to receive(:delete).with("http://www.opscode.com/", {}) + provider.run_action(:delete) + expect(new_resource).to be_updated end end @@ -107,52 +95,52 @@ describe Chef::Provider::HttpRequest do # and false for a "304 Not Modified" response describe "action_head" do before do - @provider.http = @http + provider.http = http end it "should inflate a message block at runtime" do - @new_resource.message { "return" } - expect(@http).to receive(:head).with("http://www.opscode.com/", {}).and_return(nil) - @provider.run_action(:head) - expect(@new_resource).to be_updated + new_resource.message { "return" } + expect(http).to receive(:head).with("http://www.opscode.com/", {}).and_return(nil) + provider.run_action(:head) + expect(new_resource).to be_updated end it "should run a HEAD request" do - expect(@http).to receive(:head).with("http://www.opscode.com/", {}).and_return(nil) - @provider.run_action(:head) - expect(@new_resource).to be_updated + expect(http).to receive(:head).with("http://www.opscode.com/", {}).and_return(nil) + provider.run_action(:head) + expect(new_resource).to be_updated end it "should update a HEAD request with empty string response body (CHEF-4762)" do - expect(@http).to receive(:head).with("http://www.opscode.com/", {}).and_return("") - @provider.run_action(:head) - expect(@new_resource).to be_updated + expect(http).to receive(:head).with("http://www.opscode.com/", {}).and_return("") + provider.run_action(:head) + expect(new_resource).to be_updated end it "should update a HEAD request with nil response body (CHEF-4762)" do - expect(@http).to receive(:head).with("http://www.opscode.com/", {}).and_return(nil) - @provider.run_action(:head) - expect(@new_resource).to be_updated + expect(http).to receive(:head).with("http://www.opscode.com/", {}).and_return(nil) + provider.run_action(:head) + expect(new_resource).to be_updated end it "should not update a HEAD request if a not modified response (CHEF-4762)" do if_modified_since = File.mtime(__FILE__).httpdate - @new_resource.headers "If-Modified-Since" => if_modified_since - expect(@http).to receive(:head).with("http://www.opscode.com/", { "If-Modified-Since" => if_modified_since }).and_return(false) - @provider.run_action(:head) - expect(@new_resource).not_to be_updated + new_resource.headers "If-Modified-Since" => if_modified_since + expect(http).to receive(:head).with("http://www.opscode.com/", { "If-Modified-Since" => if_modified_since }).and_return(false) + provider.run_action(:head) + expect(new_resource).not_to be_updated end it "should run a HEAD request with If-Modified-Since header" do - @new_resource.headers "If-Modified-Since" => File.mtime(__FILE__).httpdate - expect(@http).to receive(:head).with("http://www.opscode.com/", @new_resource.headers) - @provider.run_action(:head) + new_resource.headers "If-Modified-Since" => File.mtime(__FILE__).httpdate + expect(http).to receive(:head).with("http://www.opscode.com/", new_resource.headers) + provider.run_action(:head) end it "doesn't call converge_by if HEAD does not return modified" do - expect(@http).to receive(:head).and_return(false) - expect(@provider).not_to receive(:converge_by) - @provider.run_action(:head) + expect(http).to receive(:head).and_return(false) + expect(provider).not_to receive(:converge_by) + provider.run_action(:head) end end end diff --git a/tasks/rspec.rb b/tasks/rspec.rb index 18f3318e55..f6038d6b9a 100644 --- a/tasks/rspec.rb +++ b/tasks/rspec.rb @@ -77,7 +77,7 @@ begin RSpec::Core::RakeTask.new(sub) do |t| puts "--- Running chef #{sub} specs" t.verbose = false - t.rspec_opts = %w{--profile} + t.rspec_opts = %w{--profile --format doc} t.pattern = FileList["spec/#{sub}/**/*_spec.rb"] end end |