diff options
author | Noah Kantrowitz <noah@coderanger.net> | 2015-09-22 13:28:50 -0700 |
---|---|---|
committer | Noah Kantrowitz <noah@coderanger.net> | 2015-09-22 13:28:50 -0700 |
commit | 48cc7a968c861db91c1b1b2a627c5672240c2e80 (patch) | |
tree | 2651818a5c39e1e460575bfe65a8b9e2837285c4 /spec/functional | |
parent | 064e0a6b90d1e9a1e00e0c9ef4d18eb1ecc33a3e (diff) | |
parent | 30ff3159f1d8d4c4a704241fa76b9b75f62c2663 (diff) | |
download | chef-48cc7a968c861db91c1b1b2a627c5672240c2e80.tar.gz |
Merge pull request #3857 from coderanger/gateway-key
Refactor knife ssh options stuff
Diffstat (limited to 'spec/functional')
-rw-r--r-- | spec/functional/knife/cookbook_delete_spec.rb | 24 | ||||
-rw-r--r-- | spec/functional/knife/ssh_spec.rb | 16 |
2 files changed, 33 insertions, 7 deletions
diff --git a/spec/functional/knife/cookbook_delete_spec.rb b/spec/functional/knife/cookbook_delete_spec.rb index 15ac8f55ab..bffad8cbed 100644 --- a/spec/functional/knife/cookbook_delete_spec.rb +++ b/spec/functional/knife/cookbook_delete_spec.rb @@ -40,20 +40,30 @@ describe Chef::Knife::CookbookDelete do end context "when the cookbook doesn't exist" do - before do - @log_output = StringIO.new - - Chef::Log.logger = Logger.new(@log_output) - Chef::Log.level = :debug + let(:log_output) { StringIO.new } + before do @knife.name_args = %w{no-such-cookbook} @api.get("/cookbooks/no-such-cookbook", 404, Chef::JSONCompat.to_json({'error'=>'dear Tim, no. -Sent from my iPad'})) end + around do |ex| + old_logger = Chef::Log.logger + old_level = Chef::Log.level + begin + Chef::Log.logger = Logger.new(log_output) + Chef::Log.level = :debug + ex.run + ensure + Chef::Log.logger = old_logger + Chef::Log.level = old_level + end + end + it "logs an error and exits" do - allow(@knife.ui).to receive(:stderr).and_return(@log_output) + allow(@knife.ui).to receive(:stderr).and_return(log_output) expect {@knife.run}.to raise_error(SystemExit) - expect(@log_output.string).to match(/Cannot find a cookbook named no-such-cookbook to delete/) + expect(log_output.string).to match(/Cannot find a cookbook named no-such-cookbook to delete/) end end diff --git a/spec/functional/knife/ssh_spec.rb b/spec/functional/knife/ssh_spec.rb index 6608d05771..51524b7009 100644 --- a/spec/functional/knife/ssh_spec.rb +++ b/spec/functional/knife/ssh_spec.rb @@ -31,6 +31,22 @@ describe Chef::Knife::Ssh do @server.stop end + let(:ssh_config) { Hash.new } + before do + allow(Net::SSH).to receive(:configuration_for).and_return(ssh_config) + end + + # Force log level to info. + around do |ex| + old_level = Chef::Log.level + begin + Chef::Log.level = :info + ex.run + ensure + Chef::Log.level = old_level + end + end + describe "identity file" do context "when knife[:ssh_identity_file] is set" do before do |