summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2019-10-27 21:38:16 -0700
committerGitHub <noreply@github.com>2019-10-27 21:38:16 -0700
commit456b3f70db1bc20a9adecfbc950a79583d400794 (patch)
treec3d2714324c23948d05b85c993d761ba01a540e4
parent83acd8b256645efc86d87b4dee41c0ee192946d3 (diff)
parenta0bc42e094593da343e6471cd1ba744560fdb5c8 (diff)
downloadchef-456b3f70db1bc20a9adecfbc950a79583d400794.tar.gz
Merge pull request #9028 from MsysTechnologiesllc/VSingh/fix-knife-ssh-name-args
Fix Exception: NoMethodError: undefined method join for nil:NilClass
-rw-r--r--lib/chef/knife/ssh.rb6
-rw-r--r--spec/unit/knife/ssh_spec.rb44
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