diff options
author | Thom May <thom@chef.io> | 2015-12-02 12:19:33 +0000 |
---|---|---|
committer | Thom May <thom@chef.io> | 2016-01-11 15:40:42 +0000 |
commit | d99e306a41b1402209d320cb7119b12a3bbb962f (patch) | |
tree | f65940702826deb991e6198967d3e9e96cb2857a /spec/unit/knife | |
parent | 1b71aeb423b009f6d1a44215c89e9976957b47e9 (diff) | |
download | chef-d99e306a41b1402209d320cb7119b12a3bbb962f.tar.gz |
Convert all uses of Chef::REST to Chef::ServerAPItm/no_more_rest
In the process, stop auto-expanding JSON in the HTTP client, and let
individual classes control that themselves.
Fixes #2737, Fixes #3518
Diffstat (limited to 'spec/unit/knife')
-rw-r--r-- | spec/unit/knife/bootstrap/client_builder_spec.rb | 26 | ||||
-rw-r--r-- | spec/unit/knife/configure_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/knife/cookbook_bulk_delete_spec.rb | 16 | ||||
-rw-r--r-- | spec/unit/knife/cookbook_delete_spec.rb | 6 | ||||
-rw-r--r-- | spec/unit/knife/cookbook_download_spec.rb | 7 | ||||
-rw-r--r-- | spec/unit/knife/cookbook_list_spec.rb | 8 | ||||
-rw-r--r-- | spec/unit/knife/cookbook_show_spec.rb | 30 | ||||
-rw-r--r-- | spec/unit/knife/cookbook_site_download_spec.rb | 10 | ||||
-rw-r--r-- | spec/unit/knife/cookbook_site_share_spec.rb | 10 | ||||
-rw-r--r-- | spec/unit/knife/cookbook_site_unshare_spec.rb | 12 | ||||
-rw-r--r-- | spec/unit/knife/data_bag_create_spec.rb | 12 | ||||
-rw-r--r-- | spec/unit/knife/data_bag_edit_spec.rb | 4 | ||||
-rw-r--r-- | spec/unit/knife/data_bag_from_file_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/knife/data_bag_show_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/knife/environment_compare_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/knife/index_rebuild_spec.rb | 6 |
16 files changed, 77 insertions, 78 deletions
diff --git a/spec/unit/knife/bootstrap/client_builder_spec.rb b/spec/unit/knife/bootstrap/client_builder_spec.rb index f17a6af878..6812a24c91 100644 --- a/spec/unit/knife/bootstrap/client_builder_spec.rb +++ b/spec/unit/knife/bootstrap/client_builder_spec.rb @@ -32,7 +32,7 @@ describe Chef::Knife::Bootstrap::ClientBuilder do let(:node_name) { "bevell.wat" } - let(:rest) { double("Chef::REST") } + let(:rest) { double("Chef::ServerAPI") } let(:client_builder) { client_builder = Chef::Knife::Bootstrap::ClientBuilder.new(knife_config: knife_config, chef_config: chef_config, ui: ui) @@ -53,14 +53,14 @@ describe Chef::Knife::Bootstrap::ClientBuilder do end it "exits when the node exists and the user does not want to delete" do - expect(rest).to receive(:get_rest).with("nodes/#{node_name}") + expect(rest).to receive(:get).with("nodes/#{node_name}") expect(ui.stdin).to receive(:readline).and_return('n') expect { client_builder.run }.to raise_error(SystemExit) end it "exits when the client exists and the user does not want to delete" do - expect(rest).to receive(:get_rest).with("nodes/#{node_name}").and_raise(exception_404) - expect(rest).to receive(:get_rest).with("clients/#{node_name}") + expect(rest).to receive(:get).with("nodes/#{node_name}").and_raise(exception_404) + expect(rest).to receive(:get).with("clients/#{node_name}") expect(ui.stdin).to receive(:readline).and_return('n') expect { client_builder.run }.to raise_error(SystemExit) end @@ -74,30 +74,30 @@ describe Chef::Knife::Bootstrap::ClientBuilder do end it "when both the client and node do not exist it succeeds" do - expect(rest).to receive(:get_rest).with("nodes/#{node_name}").and_raise(exception_404) - expect(rest).to receive(:get_rest).with("clients/#{node_name}").and_raise(exception_404) + expect(rest).to receive(:get).with("nodes/#{node_name}").and_raise(exception_404) + expect(rest).to receive(:get).with("clients/#{node_name}").and_raise(exception_404) expect { client_builder.run }.not_to raise_error end it "when we are allowed to delete an old node" do - expect(rest).to receive(:get_rest).with("nodes/#{node_name}") + expect(rest).to receive(:get).with("nodes/#{node_name}") expect(ui.stdin).to receive(:readline).and_return('y') - expect(rest).to receive(:get_rest).with("clients/#{node_name}").and_raise(exception_404) + expect(rest).to receive(:get).with("clients/#{node_name}").and_raise(exception_404) expect(rest).to receive(:delete).with("nodes/#{node_name}") expect { client_builder.run }.not_to raise_error end it "when we are allowed to delete an old client" do - expect(rest).to receive(:get_rest).with("nodes/#{node_name}").and_raise(exception_404) - expect(rest).to receive(:get_rest).with("clients/#{node_name}") + expect(rest).to receive(:get).with("nodes/#{node_name}").and_raise(exception_404) + expect(rest).to receive(:get).with("clients/#{node_name}") expect(ui.stdin).to receive(:readline).and_return('y') expect(rest).to receive(:delete).with("clients/#{node_name}") expect { client_builder.run }.not_to raise_error end it "when we are are allowed to delete both an old client and node" do - expect(rest).to receive(:get_rest).with("nodes/#{node_name}") - expect(rest).to receive(:get_rest).with("clients/#{node_name}") + expect(rest).to receive(:get).with("nodes/#{node_name}") + expect(rest).to receive(:get).with("clients/#{node_name}") expect(ui.stdin).to receive(:readline).twice.and_return('y') expect(rest).to receive(:delete).with("nodes/#{node_name}") expect(rest).to receive(:delete).with("clients/#{node_name}") @@ -143,7 +143,7 @@ describe Chef::Knife::Bootstrap::ClientBuilder do expect(node).to receive(:save) end - let(:client_rest) { double("Chef::REST (client)") } + let(:client_rest) { double("Chef::ServerAPI (client)") } let(:node) { double("Chef::Node") } diff --git a/spec/unit/knife/configure_spec.rb b/spec/unit/knife/configure_spec.rb index e3ea1f052c..89874cfdf9 100644 --- a/spec/unit/knife/configure_spec.rb +++ b/spec/unit/knife/configure_spec.rb @@ -6,7 +6,7 @@ describe Chef::Knife::Configure do Chef::Config[:node_name] = "webmonkey.example.com" @knife = Chef::Knife::Configure.new - @rest_client = double("null rest client", :post_rest => { :result => :true }) + @rest_client = double("null rest client", :post => { :result => :true }) allow(@knife).to receive(:rest).and_return(@rest_client) @out = StringIO.new diff --git a/spec/unit/knife/cookbook_bulk_delete_spec.rb b/spec/unit/knife/cookbook_bulk_delete_spec.rb index 98cd06bbbc..7d6e851589 100644 --- a/spec/unit/knife/cookbook_bulk_delete_spec.rb +++ b/spec/unit/knife/cookbook_bulk_delete_spec.rb @@ -36,9 +36,9 @@ describe Chef::Knife::CookbookBulkDelete do cookbook = Chef::CookbookVersion.new(cookbook_name) @cookbooks[cookbook_name] = cookbook end - @rest = double("Chef::REST") - allow(@rest).to receive(:get_rest).and_return(@cookbooks) - allow(@rest).to receive(:delete_rest).and_return(true) + @rest = double("Chef::ServerAPI") + allow(@rest).to receive(:get).and_return(@cookbooks) + allow(@rest).to receive(:delete).and_return(true) allow(@knife).to receive(:rest).and_return(@rest) allow(Chef::CookbookVersion).to receive(:list).and_return(@cookbooks) @@ -49,11 +49,11 @@ describe Chef::Knife::CookbookBulkDelete do describe "when there are several cookbooks on the server" do before do @cheezburger = {'cheezburger' => {"url" => "file:///dev/null", "versions" => [{"url" => "file:///dev/null-cheez", "version" => "1.0.0"}]}} - allow(@rest).to receive(:get_rest).with('cookbooks/cheezburger').and_return(@cheezburger) + allow(@rest).to receive(:get).with('cookbooks/cheezburger').and_return(@cheezburger) @pizza = {'pizza' => {"url" => "file:///dev/null", "versions" => [{"url" => "file:///dev/null-pizza", "version" => "2.0.0"}]}} - allow(@rest).to receive(:get_rest).with('cookbooks/pizza').and_return(@pizza) + allow(@rest).to receive(:get).with('cookbooks/pizza').and_return(@pizza) @lasagna = {'lasagna' => {"url" => "file:///dev/null", "versions" => [{"url" => "file:///dev/null-lasagna", "version" => "3.0.0"}]}} - allow(@rest).to receive(:get_rest).with('cookbooks/lasagna').and_return(@lasagna) + allow(@rest).to receive(:get).with('cookbooks/lasagna').and_return(@lasagna) end it "should print the cookbooks you are about to delete" do @@ -69,14 +69,14 @@ describe Chef::Knife::CookbookBulkDelete do it "should delete each cookbook" do {"cheezburger" => "1.0.0", "pizza" => "2.0.0", "lasagna" => '3.0.0'}.each do |cookbook_name, version| - expect(@rest).to receive(:delete_rest).with("cookbooks/#{cookbook_name}/#{version}") + expect(@rest).to receive(:delete).with("cookbooks/#{cookbook_name}/#{version}") end @knife.run end it "should only delete cookbooks that match the regex" do @knife.name_args = ["cheezburger"] - expect(@rest).to receive(:delete_rest).with('cookbooks/cheezburger/1.0.0') + expect(@rest).to receive(:delete).with('cookbooks/cheezburger/1.0.0') @knife.run end end diff --git a/spec/unit/knife/cookbook_delete_spec.rb b/spec/unit/knife/cookbook_delete_spec.rb index 4e75a689e3..e9085e9512 100644 --- a/spec/unit/knife/cookbook_delete_spec.rb +++ b/spec/unit/knife/cookbook_delete_spec.rb @@ -134,19 +134,19 @@ describe Chef::Knife::CookbookDelete do end it 'should return the list of versions of the cookbook' do - expect(@rest_mock).to receive(:get_rest).with('cookbooks/foobar').and_return(@cookbook_data) + expect(@rest_mock).to receive(:get).with('cookbooks/foobar').and_return(@cookbook_data) expect(@knife.available_versions).to eq(['1.0.0', '1.1.0', '2.0.0']) end it 'should raise if an error other than HTTP 404 is returned' do exception = Net::HTTPServerException.new('500 Internal Server Error', '500') - expect(@rest_mock).to receive(:get_rest).and_raise(exception) + expect(@rest_mock).to receive(:get).and_raise(exception) expect { @knife.available_versions }.to raise_error Net::HTTPServerException end describe "if the cookbook can't be found" do before(:each) do - expect(@rest_mock).to receive(:get_rest). + expect(@rest_mock).to receive(:get). and_raise(Net::HTTPServerException.new('404 Not Found', '404')) end diff --git a/spec/unit/knife/cookbook_download_spec.rb b/spec/unit/knife/cookbook_download_spec.rb index 7ca1adfcb5..8b85e52b75 100644 --- a/spec/unit/knife/cookbook_download_spec.rb +++ b/spec/unit/knife/cookbook_download_spec.rb @@ -69,8 +69,8 @@ describe Chef::Knife::CookbookDownload do @cookbook_mock = double('cookbook') allow(@cookbook_mock).to receive(:version).and_return('1.0.0') allow(@cookbook_mock).to receive(:manifest).and_return(@manifest_data) - expect(@rest_mock).to receive(:get_rest).with('cookbooks/foobar/1.0.0'). - and_return(@cookbook_mock) + expect(Chef::CookbookVersion).to receive(:load).with("foobar", "1.0.0"). + and_return(@cookbook_mock) end it 'should determine which version if one was not explicitly specified'do @@ -106,11 +106,10 @@ describe Chef::Knife::CookbookDownload do end @files_mocks.each_pair do |file, mock| - expect(@rest_mock).to receive(:get_rest).with("http://example.org/files/#{file}", true). + expect(@rest_mock).to receive(:streaming_request).with("http://example.org/files/#{file}"). and_return(mock) end - expect(@rest_mock).to receive(:sign_on_redirect=).with(false).at_least(:once) @files.each do |f| expect(FileUtils).to receive(:mv). with("/var/tmp/#{File.basename(f)}", "/var/tmp/chef/foobar-1.0.0/#{f}") diff --git a/spec/unit/knife/cookbook_list_spec.rb b/spec/unit/knife/cookbook_list_spec.rb index 559f700bb4..fc07c8af3f 100644 --- a/spec/unit/knife/cookbook_list_spec.rb +++ b/spec/unit/knife/cookbook_list_spec.rb @@ -37,7 +37,7 @@ describe Chef::Knife::CookbookList do describe 'run' do it 'should display the latest version of the cookbooks' do - expect(@rest_mock).to receive(:get_rest).with('/cookbooks?num_versions=1'). + expect(@rest_mock).to receive(:get).with('/cookbooks?num_versions=1'). and_return(@cookbook_data) @knife.run @cookbook_names.each do |item| @@ -47,7 +47,7 @@ describe Chef::Knife::CookbookList do it 'should query cookbooks for the configured environment' do @knife.config[:environment] = 'production' - expect(@rest_mock).to receive(:get_rest). + expect(@rest_mock).to receive(:get). with('/environments/production/cookbooks?num_versions=1'). and_return(@cookbook_data) @knife.run @@ -56,7 +56,7 @@ describe Chef::Knife::CookbookList do describe 'with -w or --with-uri' do it 'should display the cookbook uris' do @knife.config[:with_uri] = true - allow(@rest_mock).to receive(:get_rest).and_return(@cookbook_data) + allow(@rest_mock).to receive(:get).and_return(@cookbook_data) @knife.run @cookbook_names.each do |item| pattern = /#{Regexp.escape(@cookbook_data[item]['versions'].first['url'])}/ @@ -75,7 +75,7 @@ describe Chef::Knife::CookbookList do it 'should display all versions of the cookbooks' do @knife.config[:all_versions] = true - expect(@rest_mock).to receive(:get_rest).with('/cookbooks?num_versions=all'). + expect(@rest_mock).to receive(:get).with('/cookbooks?num_versions=all'). and_return(@cookbook_data) @knife.run @cookbook_names.each do |item| diff --git a/spec/unit/knife/cookbook_show_spec.rb b/spec/unit/knife/cookbook_show_spec.rb index bf480e3678..a06e53b9a1 100644 --- a/spec/unit/knife/cookbook_show_spec.rb +++ b/spec/unit/knife/cookbook_show_spec.rb @@ -25,7 +25,7 @@ describe Chef::Knife::CookbookShow do @knife = Chef::Knife::CookbookShow.new @knife.config = { } @knife.name_args = [ "cookbook_name" ] - @rest = double(Chef::REST) + @rest = double(Chef::ServerAPI) allow(@knife).to receive(:rest).and_return(@rest) allow(@knife).to receive(:pretty_print).and_return(true) allow(@knife).to receive(:output).and_return(true) @@ -56,14 +56,14 @@ describe Chef::Knife::CookbookShow do end it "should show the raw cookbook data" do - expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name").and_return(@response) + expect(@rest).to receive(:get).with("cookbooks/cookbook_name").and_return(@response) expect(@knife).to receive(:format_cookbook_list_for_display).with(@response) @knife.run end it "should respect the user-supplied environment" do @knife.config[:environment] = "foo" - expect(@rest).to receive(:get_rest).with("environments/foo/cookbooks/cookbook_name").and_return(@response) + expect(@rest).to receive(:get).with("environments/foo/cookbooks/cookbook_name").and_return(@response) expect(@knife).to receive(:format_cookbook_list_for_display).with(@response) @knife.run end @@ -76,7 +76,7 @@ describe Chef::Knife::CookbookShow do end it "should show the specific part of a cookbook" do - expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@response) + expect(@rest).to receive(:get).with("cookbooks/cookbook_name/0.1.0").and_return(@response) expect(@knife).to receive(:output).with(@response) @knife.run end @@ -101,7 +101,7 @@ describe Chef::Knife::CookbookShow do end it "should print the json of the part" do - expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response) + expect(@rest).to receive(:get).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response) expect(@knife).to receive(:output).with(@cookbook_response.manifest["recipes"]) @knife.run end @@ -125,8 +125,8 @@ describe Chef::Knife::CookbookShow do end it "should print the raw result of the request (likely a file!)" do - expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response) - expect(@rest).to receive(:get_rest).with("http://example.org/files/default.rb", true).and_return(StringIO.new(@response)) + expect(@rest).to receive(:get).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response) + expect(@rest).to receive(:get).with("http://example.org/files/default.rb", true).and_return(StringIO.new(@response)) expect(@knife).to receive(:pretty_print).with(@response) @knife.run end @@ -177,8 +177,8 @@ describe Chef::Knife::CookbookShow do @knife.config[:platform] = "example_platform" @knife.config[:platform_version] = "1.0" @knife.config[:fqdn] = "examplehost.example.org" - expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response) - expect(@rest).to receive(:get_rest).with("http://example.org/files/1111", true).and_return(StringIO.new(@response)) + expect(@rest).to receive(:get).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response) + expect(@rest).to receive(:get).with("http://example.org/files/1111", true).and_return(StringIO.new(@response)) expect(@knife).to receive(:pretty_print).with(@response) @knife.run end @@ -189,8 +189,8 @@ describe Chef::Knife::CookbookShow do @knife.config[:platform] = "ubuntu" @knife.config[:platform_version] = "1.0" @knife.config[:fqdn] = "differenthost.example.org" - expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response) - expect(@rest).to receive(:get_rest).with("http://example.org/files/3333", true).and_return(StringIO.new(@response)) + expect(@rest).to receive(:get).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response) + expect(@rest).to receive(:get).with("http://example.org/files/3333", true).and_return(StringIO.new(@response)) expect(@knife).to receive(:pretty_print).with(@response) @knife.run end @@ -201,8 +201,8 @@ describe Chef::Knife::CookbookShow do @knife.config[:platform] = "ubuntu" @knife.config[:platform_version] = "9.10" @knife.config[:fqdn] = "differenthost.example.org" - expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response) - expect(@rest).to receive(:get_rest).with("http://example.org/files/2222", true).and_return(StringIO.new(@response)) + expect(@rest).to receive(:get).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response) + expect(@rest).to receive(:get).with("http://example.org/files/2222", true).and_return(StringIO.new(@response)) expect(@knife).to receive(:pretty_print).with(@response) @knife.run end @@ -210,8 +210,8 @@ describe Chef::Knife::CookbookShow do describe "with none of the arguments, it should use the default" do it "should pass them all" do - expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response) - expect(@rest).to receive(:get_rest).with("http://example.org/files/4444", true).and_return(StringIO.new(@response)) + expect(@rest).to receive(:get).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response) + expect(@rest).to receive(:get).with("http://example.org/files/4444", true).and_return(StringIO.new(@response)) expect(@knife).to receive(:pretty_print).with(@response) @knife.run end diff --git a/spec/unit/knife/cookbook_site_download_spec.rb b/spec/unit/knife/cookbook_site_download_spec.rb index fdf4c2197b..35c6544d58 100644 --- a/spec/unit/knife/cookbook_site_download_spec.rb +++ b/spec/unit/knife/cookbook_site_download_spec.rb @@ -35,7 +35,7 @@ describe Chef::Knife::CookbookSiteDownload do allow(@knife.ui).to receive(:stderr).and_return(@stderr) allow(@knife).to receive(:noauth_rest).and_return(@noauth_rest) - expect(@noauth_rest).to receive(:get_rest). + expect(@noauth_rest).to receive(:get). with("#{@cookbook_api_url}/apache2"). and_return(@current_data) end @@ -66,10 +66,10 @@ describe Chef::Knife::CookbookSiteDownload do context 'downloading the latest version' do before do - expect(@noauth_rest).to receive(:get_rest). + expect(@noauth_rest).to receive(:get). with(@current_data['latest_version']). and_return(@cookbook_data) - expect(@noauth_rest).to receive(:get_rest). + expect(@noauth_rest).to receive(:get). with(@cookbook_data['file'], true). and_return(@temp_file) end @@ -131,10 +131,10 @@ describe Chef::Knife::CookbookSiteDownload do end it 'should download the desired version' do - expect(@noauth_rest).to receive(:get_rest). + expect(@noauth_rest).to receive(:get). with("#{@cookbook_api_url}/apache2/versions/#{@version_us}"). and_return(@cookbook_data) - expect(@noauth_rest).to receive(:get_rest). + expect(@noauth_rest).to receive(:get). with(@cookbook_data['file'], true). and_return(@temp_file) expect(FileUtils).to receive(:cp).with(@temp_file.path, @file) diff --git a/spec/unit/knife/cookbook_site_share_spec.rb b/spec/unit/knife/cookbook_site_share_spec.rb index a7caca9744..1b2ffd10fb 100644 --- a/spec/unit/knife/cookbook_site_share_spec.rb +++ b/spec/unit/knife/cookbook_site_share_spec.rb @@ -36,7 +36,7 @@ describe Chef::Knife::CookbookSiteShare do allow(@cookbook_loader).to receive(:[]).and_return(@cookbook) allow(Chef::CookbookLoader).to receive(:new).and_return(@cookbook_loader) - @noauth_rest = double(Chef::REST) + @noauth_rest = double(Chef::ServerAPI) allow(@knife).to receive(:noauth_rest).and_return(@noauth_rest) @cookbook_uploader = Chef::CookbookUploader.new('herpderp', :rest => "norest") @@ -78,21 +78,21 @@ describe Chef::Knife::CookbookSiteShare do it 'should not fail when given only 1 argument and can determine category' do @knife.name_args = ['cookbook_name'] - expect(@noauth_rest).to receive(:get_rest).with("https://supermarket.chef.io/api/v1/cookbooks/cookbook_name").and_return(@category_response) + expect(@noauth_rest).to receive(:get).with("https://supermarket.chef.io/api/v1/cookbooks/cookbook_name").and_return(@category_response) expect(@knife).to receive(:do_upload) @knife.run end it 'should print error and exit when given only 1 argument and cannot determine category' do @knife.name_args = ['cookbook_name'] - expect(@noauth_rest).to receive(:get_rest).with("https://supermarket.chef.io/api/v1/cookbooks/cookbook_name").and_return(@bad_category_response) + expect(@noauth_rest).to receive(:get).with("https://supermarket.chef.io/api/v1/cookbooks/cookbook_name").and_return(@bad_category_response) expect(@knife.ui).to receive(:fatal) expect { @knife.run }.to raise_error(SystemExit) end - it 'should print error and exit when given only 1 argument and Chef::REST throws an exception' do + it 'should print error and exit when given only 1 argument and Chef::ServerAPI throws an exception' do @knife.name_args = ['cookbook_name'] - expect(@noauth_rest).to receive(:get_rest).with("https://supermarket.chef.io/api/v1/cookbooks/cookbook_name") { raise Errno::ECONNREFUSED, "Connection refused" } + expect(@noauth_rest).to receive(:get).with("https://supermarket.chef.io/api/v1/cookbooks/cookbook_name") { raise Errno::ECONNREFUSED, "Connection refused" } expect(@knife.ui).to receive(:fatal) expect { @knife.run }.to raise_error(SystemExit) end diff --git a/spec/unit/knife/cookbook_site_unshare_spec.rb b/spec/unit/knife/cookbook_site_unshare_spec.rb index ec46a8705c..aafb7c1507 100644 --- a/spec/unit/knife/cookbook_site_unshare_spec.rb +++ b/spec/unit/knife/cookbook_site_unshare_spec.rb @@ -26,8 +26,8 @@ describe Chef::Knife::CookbookSiteUnshare do @knife.name_args = ['cookbook_name'] allow(@knife).to receive(:confirm).and_return(true) - @rest = double('Chef::REST') - allow(@rest).to receive(:delete_rest).and_return(true) + @rest = double('Chef::ServerAPI') + allow(@rest).to receive(:delete).and_return(true) allow(@knife).to receive(:rest).and_return(@rest) @stdout = StringIO.new allow(@knife.ui).to receive(:stdout).and_return(@stdout) @@ -50,20 +50,20 @@ describe Chef::Knife::CookbookSiteUnshare do end it 'should send a delete request to the cookbook site' do - expect(@rest).to receive(:delete_rest) + expect(@rest).to receive(:delete) @knife.run end it 'should log an error and exit when forbidden' do exception = double('403 "Forbidden"', :code => '403') - allow(@rest).to receive(:delete_rest).and_raise(Net::HTTPServerException.new('403 "Forbidden"', exception)) + allow(@rest).to receive(:delete).and_raise(Net::HTTPServerException.new('403 "Forbidden"', exception)) expect(@knife.ui).to receive(:error) expect { @knife.run }.to raise_error(SystemExit) end - it 'should re-raise any non-forbidden errors on delete_rest' do + it 'should re-raise any non-forbidden errors on delete' do exception = double('500 "Application Error"', :code => '500') - allow(@rest).to receive(:delete_rest).and_raise(Net::HTTPServerException.new('500 "Application Error"', exception)) + allow(@rest).to receive(:delete).and_raise(Net::HTTPServerException.new('500 "Application Error"', exception)) expect { @knife.run }.to raise_error(Net::HTTPServerException) end diff --git a/spec/unit/knife/data_bag_create_spec.rb b/spec/unit/knife/data_bag_create_spec.rb index c31c88577d..d022cc7f7d 100644 --- a/spec/unit/knife/data_bag_create_spec.rb +++ b/spec/unit/knife/data_bag_create_spec.rb @@ -28,7 +28,7 @@ describe Chef::Knife::DataBagCreate do k end - let(:rest) { double("Chef::REST") } + let(:rest) { double("Chef::ServerAPI") } let(:stdout) { StringIO.new } let(:bag_name) { "sudoing_admins" } @@ -58,7 +58,7 @@ describe Chef::Knife::DataBagCreate do end it "creates a data bag" do - expect(rest).to receive(:post_rest).with("data", {"name" => bag_name}) + expect(rest).to receive(:post).with("data", {"name" => bag_name}) expect(knife.ui).to receive(:info).with("Created data_bag[#{bag_name}]") knife.run @@ -75,8 +75,8 @@ describe Chef::Knife::DataBagCreate do it "creates a data bag item" do expect(knife).to receive(:create_object).and_yield(raw_hash) expect(knife).to receive(:encryption_secret_provided?).and_return(false) - expect(rest).to receive(:post_rest).with("data", {'name' => bag_name}).ordered - expect(rest).to receive(:post_rest).with("data/#{bag_name}", item).ordered + expect(rest).to receive(:post).with("data", {'name' => bag_name}).ordered + expect(rest).to receive(:post).with("data/#{bag_name}", item).ordered knife.run end @@ -99,8 +99,8 @@ describe Chef::Knife::DataBagCreate do .to receive(:encrypt_data_bag_item) .with(raw_hash, secret) .and_return(encoded_data) - expect(rest).to receive(:post_rest).with("data", {"name" => bag_name}).ordered - expect(rest).to receive(:post_rest).with("data/#{bag_name}", item).ordered + expect(rest).to receive(:post).with("data", {"name" => bag_name}).ordered + expect(rest).to receive(:post).with("data/#{bag_name}", item).ordered knife.run end diff --git a/spec/unit/knife/data_bag_edit_spec.rb b/spec/unit/knife/data_bag_edit_spec.rb index 6f19b5e63e..f1bcae990b 100644 --- a/spec/unit/knife/data_bag_edit_spec.rb +++ b/spec/unit/knife/data_bag_edit_spec.rb @@ -37,7 +37,7 @@ describe Chef::Knife::DataBagEdit do let(:db) { Chef::DataBagItem.from_hash(raw_hash)} let(:raw_edited_hash) { {"login_name" => "rho", "id" => "item_name", "new_key" => "new_value"} } - let(:rest) { double("Chef::REST") } + let(:rest) { double("Chef::ServerAPI") } let(:stdout) { StringIO.new } let(:bag_name) { "sudoing_admins" } @@ -56,7 +56,7 @@ describe Chef::Knife::DataBagEdit do expect(Chef::DataBagItem).to receive(:load).with(bag_name, item_name).and_return(db) expect(knife).to receive(:encrypted?).with(db.raw_data).and_return(is_encrypted?) expect(knife).to receive(:edit_data).with(data_to_edit).and_return(raw_edited_hash) - expect(rest).to receive(:put_rest).with("data/#{bag_name}/#{item_name}", transmitted_hash).ordered + expect(rest).to receive(:put).with("data/#{bag_name}/#{item_name}", transmitted_hash).ordered knife.run end diff --git a/spec/unit/knife/data_bag_from_file_spec.rb b/spec/unit/knife/data_bag_from_file_spec.rb index 8b6502145c..dc65a3e64c 100644 --- a/spec/unit/knife/data_bag_from_file_spec.rb +++ b/spec/unit/knife/data_bag_from_file_spec.rb @@ -79,7 +79,7 @@ describe Chef::Knife::DataBagFromFile do } } let(:enc_data) { Chef::EncryptedDataBagItem.encrypt_data_bag_item(plain_data, secret) } - let(:rest) { double("Chef::REST") } + let(:rest) { double("Chef::ServerAPI") } let(:stdout) { StringIO.new } let(:bag_name) { "sudoing_admins" } diff --git a/spec/unit/knife/data_bag_show_spec.rb b/spec/unit/knife/data_bag_show_spec.rb index 1125d99c2a..48a0071b49 100644 --- a/spec/unit/knife/data_bag_show_spec.rb +++ b/spec/unit/knife/data_bag_show_spec.rb @@ -39,7 +39,7 @@ describe Chef::Knife::DataBagShow do k end - let(:rest) { double("Chef::REST") } + let(:rest) { double("Chef::ServerAPI") } let(:stdout) { StringIO.new } let(:bag_name) { "sudoing_admins" } diff --git a/spec/unit/knife/environment_compare_spec.rb b/spec/unit/knife/environment_compare_spec.rb index 6d4d3ead52..81ec19d7af 100644 --- a/spec/unit/knife/environment_compare_spec.rb +++ b/spec/unit/knife/environment_compare_spec.rb @@ -51,7 +51,7 @@ describe Chef::Knife::EnvironmentCompare do 'url' => "#{@base_url}/#{item}/1.0.1"}]} end - allow(@rest_double).to receive(:get_rest).with("/cookbooks?num_versions=1").and_return(@cookbook_data) + allow(@rest_double).to receive(:get).with("/cookbooks?num_versions=1").and_return(@cookbook_data) @stdout = StringIO.new allow(@knife.ui).to receive(:stdout).and_return(@stdout) diff --git a/spec/unit/knife/index_rebuild_spec.rb b/spec/unit/knife/index_rebuild_spec.rb index 6c3b60bd88..d8a0dd72d7 100644 --- a/spec/unit/knife/index_rebuild_spec.rb +++ b/spec/unit/knife/index_rebuild_spec.rb @@ -21,7 +21,7 @@ require 'spec_helper' describe Chef::Knife::IndexRebuild do let(:knife){Chef::Knife::IndexRebuild.new} - let(:rest_client){double(Chef::REST)} + let(:rest_client){double(Chef::ServerAPI)} let(:stub_rest!) do expect(knife).to receive(:rest).and_return(rest_client) @@ -45,7 +45,7 @@ describe Chef::Knife::IndexRebuild do before(:each) do stub_rest! - allow(rest_client).to receive(:get_rest).and_raise(http_server_exception) + allow(rest_client).to receive(:get).and_raise(http_server_exception) end context "against a Chef 11 server" do @@ -110,7 +110,7 @@ describe Chef::Knife::IndexRebuild do let(:api_info){ {} } let(:server_specific_stubs!) do stub_rest! - expect(rest_client).to receive(:post_rest).with("/search/reindex", {}).and_return("representative output") + expect(rest_client).to receive(:post).with("/search/reindex", {}).and_return("representative output") expect(knife).not_to receive(:unsupported_server_message) expect(knife).to receive(:deprecated_server_message) expect(knife).to receive(:nag) |