diff options
author | Jose Asuncion <jeunito@gmail.com> | 2016-11-21 21:52:54 -0800 |
---|---|---|
committer | Jose Asuncion <jose.asuncion@gmail.com> | 2016-11-29 08:43:51 -0800 |
commit | c50418a71f793e2d2daa729962ccf0ed4a9e0628 (patch) | |
tree | 68e9249ce124f70b50cb1b63cc305ee7cd145e5a | |
parent | 7155ed0447bf558536ed76f109e28fe72848dbe4 (diff) | |
download | chef-c50418a71f793e2d2daa729962ccf0ed4a9e0628.tar.gz |
add multiple node delete
Signed-off-by: Jose Asuncion <jeunito@gmail.com>
-rw-r--r-- | lib/chef/knife/node_delete.rb | 12 | ||||
-rw-r--r-- | spec/unit/knife/node_delete_spec.rb | 29 |
2 files changed, 25 insertions, 16 deletions
diff --git a/lib/chef/knife/node_delete.rb b/lib/chef/knife/node_delete.rb index 4dd7d764a1..370f2d5ba9 100644 --- a/lib/chef/knife/node_delete.rb +++ b/lib/chef/knife/node_delete.rb @@ -30,15 +30,15 @@ class Chef banner "knife node delete NODE (options)" def run - @node_name = @name_args[0] - - if @node_name.nil? + if @name_args.length == 0 show_usage - ui.fatal("You must specify a node name") + ui.fatal("You must specify at least one node name") exit 1 end - - delete_object(Chef::Node, @node_name) + + @name_args.each do |node_name| + delete_object(Chef::Node, node_name) + end end end diff --git a/spec/unit/knife/node_delete_spec.rb b/spec/unit/knife/node_delete_spec.rb index d4ef32bccf..46a6b4a1a0 100644 --- a/spec/unit/knife/node_delete_spec.rb +++ b/spec/unit/knife/node_delete_spec.rb @@ -25,12 +25,17 @@ describe Chef::Knife::NodeDelete do @knife.config = { :print_after => nil, } - @knife.name_args = [ "adam" ] + @knife.name_args = [ "adam", "ben" ] allow(@knife).to receive(:output).and_return(true) allow(@knife).to receive(:confirm).and_return(true) - @node = Chef::Node.new() - allow(@node).to receive(:destroy).and_return(true) - allow(Chef::Node).to receive(:load).and_return(@node) + + @adam_node = Chef::Node.new() + @ben_node = Chef::Node.new() + allow(@ben_node).to receive(:destroy).and_return(true) + allow(@adam_node).to receive(:destroy).and_return(true) + allow(Chef::Node).to receive(:load).with("adam").and_return(@adam_node) + allow(Chef::Node).to receive(:load).with("ben").and_return(@ben_node) + @stdout = StringIO.new allow(@knife.ui).to receive(:stdout).and_return(@stdout) end @@ -41,13 +46,15 @@ describe Chef::Knife::NodeDelete do @knife.run end - it "should load the node" do - expect(Chef::Node).to receive(:load).with("adam").and_return(@node) + it "should load the nodes" do + expect(Chef::Node).to receive(:load).with("adam").and_return(@adam_node) + expect(Chef::Node).to receive(:load).with("ben").and_return(@ben_node) @knife.run end - it "should delete the node" do - expect(@node).to receive(:destroy).and_return(@node) + it "should delete the nodes" do + expect(@adam_node).to receive(:destroy).and_return(@adam_node) + expect(@ben_node).to receive(:destroy).and_return(@ben_node) @knife.run end @@ -59,8 +66,10 @@ describe Chef::Knife::NodeDelete do describe "with -p or --print-after" do it "should pretty print the node, formatted for display" do @knife.config[:print_after] = true - expect(@knife).to receive(:format_for_display).with(@node).and_return("poop") - expect(@knife).to receive(:output).with("poop") + expect(@knife).to receive(:format_for_display).with(@adam_node).and_return("adam") + expect(@knife).to receive(:format_for_display).with(@ben_node).and_return("ben") + expect(@knife).to receive(:output).with("adam") + expect(@knife).to receive(:output).with("ben") @knife.run end end |