diff options
author | Vivek Singh <vivek.singh@msystechnologies.com> | 2019-10-27 14:46:55 +0530 |
---|---|---|
committer | Vivek Singh <vivek.singh@msystechnologies.com> | 2019-10-27 14:46:55 +0530 |
commit | a0bc42e094593da343e6471cd1ba744560fdb5c8 (patch) | |
tree | aeab7c2c6d8608cd9d812f59a9b8d728abec44b3 | |
parent | 18fa2a105001a053be46fd3be1b4dd3f7e2a74ce (diff) | |
download | chef-a0bc42e094593da343e6471cd1ba744560fdb5c8.tar.gz |
Fix Exception: NoMethodError: undefined method join for nil:NilClass
Signed-off-by: Vivek Singh <vivek.singh@msystechnologies.com>
-rw-r--r-- | lib/chef/knife/ssh.rb | 6 | ||||
-rw-r--r-- | spec/unit/knife/ssh_spec.rb | 44 |
2 files changed, 33 insertions, 17 deletions
diff --git a/lib/chef/knife/ssh.rb b/lib/chef/knife/ssh.rb index 28c83a9bde..c270de6514 100644 --- a/lib/chef/knife/ssh.rb +++ b/lib/chef/knife/ssh.rb @@ -593,6 +593,12 @@ class Chef def run @longest = 0 + if @name_args.length < 1 + show_usage + ui.fatal("You must specify the SEARCH QUERY.") + exit(1) + end + configure_user configure_password @password = config[:ssh_password] if config[:ssh_password] diff --git a/spec/unit/knife/ssh_spec.rb b/spec/unit/knife/ssh_spec.rb index 9cefcba84f..ea957ee5f9 100644 --- a/spec/unit/knife/ssh_spec.rb +++ b/spec/unit/knife/ssh_spec.rb @@ -360,29 +360,39 @@ describe Chef::Knife::Ssh do end describe "#run" do - before do - @query = Chef::Search::Query.new - expect(@query).to receive(:search).and_yield(@node_foo) - allow(Chef::Search::Query).to receive(:new).and_return(@query) - allow(@knife).to receive(:ssh_command).and_return(exit_code) - @knife.name_args = ["*:*", "false"] + + it "should print usage and exit when a SEARCH QUERY is not provided" do + @knife.name_args = [] + expect(@knife).to receive(:show_usage) + expect(@knife.ui).to receive(:fatal).with(/You must specify the SEARCH QUERY./) + expect { @knife.run }.to raise_error(SystemExit) end - context "with an error" do - let(:exit_code) { 1 } + context "exit" do + before do + @query = Chef::Search::Query.new + expect(@query).to receive(:search).and_yield(@node_foo) + allow(Chef::Search::Query).to receive(:new).and_return(@query) + allow(@knife).to receive(:ssh_command).and_return(exit_code) + @knife.name_args = ["*:*", "false"] + end + + context "with an error" do + let(:exit_code) { 1 } - it "should exit with a non-zero exit code" do - expect(@knife).to receive(:exit).with(exit_code) - @knife.run + it "should exit with a non-zero exit code" do + expect(@knife).to receive(:exit).with(exit_code) + @knife.run + end end - end - context "with no error" do - let(:exit_code) { 0 } + context "with no error" do + let(:exit_code) { 0 } - it "should not exit" do - expect(@knife).not_to receive(:exit) - @knife.run + it "should not exit" do + expect(@knife).not_to receive(:exit) + @knife.run + end end end end |