summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Delano <stephen@opscode-stephen.local>2010-02-26 15:58:56 -0800
committerStephen Delano <stephen@opscode-stephen.local>2010-02-26 15:58:56 -0800
commitaf304516a8980c0dc2133ceed6943b6694d3bff7 (patch)
treef71894220db2c9f031082829a754a3c3530c3412
parentb6f1b78c6e40c67d6a46f4edd691ab1a83996c0e (diff)
downloadchef-af304516a8980c0dc2133ceed6943b6694d3bff7.tar.gz
CHEF-990: adding `knife (client/cookbook/role) bulk delete` spec tests
-rw-r--r--chef/lib/chef/knife/cookbook_bulk_delete.rb4
-rw-r--r--chef/spec/unit/knife/client_bulk_delete_spec.rb87
-rw-r--r--chef/spec/unit/knife/cookbook_bulk_delete_spec.rb88
-rw-r--r--chef/spec/unit/knife/node_bulk_delete_spec.rb2
-rw-r--r--chef/spec/unit/knife/role_bulk_delete_spec.rb87
5 files changed, 265 insertions, 3 deletions
diff --git a/chef/lib/chef/knife/cookbook_bulk_delete.rb b/chef/lib/chef/knife/cookbook_bulk_delete.rb
index 4770ddcbd5..e87effe534 100644
--- a/chef/lib/chef/knife/cookbook_bulk_delete.rb
+++ b/chef/lib/chef/knife/cookbook_bulk_delete.rb
@@ -29,8 +29,8 @@ class Chef
Chef::Log.fatal("You must supply a regular expression to match the results against")
exit 42
else
- bulk_delete(Chef::Cookbook, "cookbook", "cookbook", rest.get_rest("cookbooks"), @name_args[0]) do |item, uri|
- rest.delete_rest(uri)
+ bulk_delete(Chef::Cookbook, "cookbook", "cookbook", rest.get_rest("cookbooks"), @name_args[0]) do |name, cookbook|
+ rest.delete_rest(cookbook)
end
end
end
diff --git a/chef/spec/unit/knife/client_bulk_delete_spec.rb b/chef/spec/unit/knife/client_bulk_delete_spec.rb
new file mode 100644
index 0000000000..a0c9b04e37
--- /dev/null
+++ b/chef/spec/unit/knife/client_bulk_delete_spec.rb
@@ -0,0 +1,87 @@
+#
+# Author:: Stephen Delano (<stephen@opscode.com>)
+# Copyright:: Copyright (c) 2010 Opscode, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
+
+describe Chef::Knife::ClientBulkDelete do
+ before(:each) do
+ @knife = Chef::Knife::ClientBulkDelete.new
+ @knife.config = {
+ :print_after => nil
+ }
+ @knife.name_args = ["."]
+ @knife.stub!(:json_pretty_print).and_return(:true)
+ @knife.stub!(:confirm).and_return(true)
+ @clients = Hash.new
+ %w{tim dan stephen}.each do |client_name|
+ client = Chef::ApiClient.new()
+ client.name(client_name)
+ client.stub!(:destroy).and_return(true)
+ @clients[client_name] = client
+ end
+ Chef::ApiClient.stub!(:list).and_return(@clients)
+ end
+
+ describe "run" do
+
+ it "should get the list of the clients" do
+ Chef::ApiClient.should_receive(:list).and_return(@clients)
+ @knife.run
+ end
+
+ it "should print the clients you are about to delete" do
+ @knife.should_receive(:json_pretty_print).with(@knife.format_list_for_display(@clients))
+ @knife.run
+ end
+
+ it "should confirm you really want to delete them" do
+ @knife.should_receive(:confirm)
+ @knife.run
+ end
+
+ it "should delete each client" do
+ @clients.each_value do |c|
+ c.should_receive(:destroy)
+ end
+ @knife.run
+ end
+
+ it "should only delete clients that match the regex" do
+ @knife.name_args = ["tim"]
+ @clients["tim"].should_receive(:destroy)
+ @clients["stephen"].should_not_receive(:destroy)
+ @clients["dan"].should_not_receive(:destroy)
+ @knife.run
+ end
+
+ it "should exit if the regex is not provided" do
+ @knife.name_args = []
+ lambda { @knife.run }.should raise_error(SystemExit)
+ end
+
+ describe "with -p or --print_after" do
+ it "should pretty_print the client, formatted for display" do
+ @knife.config[:print_after] = true
+ @clients.each_value do |n|
+ @knife.should_receive(:json_pretty_print).with(@knife.format_for_display(n))
+ end
+ @knife.run
+ end
+ end
+ end
+end
diff --git a/chef/spec/unit/knife/cookbook_bulk_delete_spec.rb b/chef/spec/unit/knife/cookbook_bulk_delete_spec.rb
new file mode 100644
index 0000000000..a0e3abd696
--- /dev/null
+++ b/chef/spec/unit/knife/cookbook_bulk_delete_spec.rb
@@ -0,0 +1,88 @@
+#
+# Author:: Stephen Delano (<stephen@opscode.com>)
+# Copyright:: Copyright (c) 2010 Opscode, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
+
+describe Chef::Knife::CookbookBulkDelete do
+ before(:each) do
+ @knife = Chef::Knife::CookbookBulkDelete.new
+ @knife.config = {
+ :print_after => nil
+ }
+ @knife.name_args = ["."]
+ @knife.stub!(:json_pretty_print).and_return(:true)
+ @knife.stub!(:confirm).and_return(true)
+ @cookbooks = Hash.new
+ %w{cheezburger pizza lasagna}.each do |cookbook_name|
+ cookbook = Chef::Cookbook.new(cookbook_name)
+ @cookbooks[cookbook_name] = cookbook
+ end
+ @rest = mock("Chef::REST")
+ @rest.stub!(:get_rest).and_return(@cookbooks)
+ @rest.stub!(:delete_rest).and_return(true)
+ @knife.stub!(:rest).and_return(@rest)
+ end
+
+ describe "run" do
+
+ it "should get the list of the cookbooks" do
+ @rest.should_receive(:get_rest).with("cookbooks").and_return(@cookbooks)
+ @knife.run
+ end
+
+ it "should print the cookbooks you are about to delete" do
+ @knife.should_receive(:json_pretty_print).with(@knife.format_list_for_display(@cookbooks))
+ @knife.run
+ end
+
+ it "should confirm you really want to delete them" do
+ @knife.should_receive(:confirm)
+ @knife.run
+ end
+
+ it "should delete each cookbook" do
+ @cookbooks.each_value do |c|
+ @rest.should_receive(:delete_rest).with(c)
+ end
+ @knife.run
+ end
+
+ it "should only delete cookbooks that match the regex" do
+ @knife.name_args = ["cheezburger"]
+ @rest.should_receive(:delete_rest).with(@cookbooks["cheezburger"])
+ @rest.should_not_receive(:delete_rest).with(@cookbooks["pizza"])
+ @rest.should_not_receive(:delete_rest).with(@cookbooks["lasagna"])
+ @knife.run
+ end
+
+ it "should exit if the regex is not provided" do
+ @knife.name_args = []
+ lambda { @knife.run }.should raise_error(SystemExit)
+ end
+
+ describe "with -p or --print_after" do
+ it "should pretty_print the node, formatted for display" do
+ @knife.config[:print_after] = true
+ @cookbooks.each_value do |n|
+ @knife.should_receive(:json_pretty_print).with(@knife.format_for_display(n))
+ end
+ @knife.run
+ end
+ end
+ end
+end
diff --git a/chef/spec/unit/knife/node_bulk_delete_spec.rb b/chef/spec/unit/knife/node_bulk_delete_spec.rb
index 6734d4de49..ab99583728 100644
--- a/chef/spec/unit/knife/node_bulk_delete_spec.rb
+++ b/chef/spec/unit/knife/node_bulk_delete_spec.rb
@@ -69,7 +69,7 @@ describe Chef::Knife::NodeBulkDelete do
@knife.run
end
- it "should exit with 42 if the regex is not matched" do
+ it "should exit if the regex is not provided" do
@knife.name_args = []
lambda { @knife.run }.should raise_error(SystemExit)
end
diff --git a/chef/spec/unit/knife/role_bulk_delete_spec.rb b/chef/spec/unit/knife/role_bulk_delete_spec.rb
new file mode 100644
index 0000000000..2468728474
--- /dev/null
+++ b/chef/spec/unit/knife/role_bulk_delete_spec.rb
@@ -0,0 +1,87 @@
+#
+# Author:: Stephen Delano (<stephen@opscode.com>)
+# Copyright:: Copyright (c) 2010 Opscode, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
+
+describe Chef::Knife::RoleBulkDelete do
+ before(:each) do
+ @knife = Chef::Knife::RoleBulkDelete.new
+ @knife.config = {
+ :print_after => nil
+ }
+ @knife.name_args = ["."]
+ @knife.stub!(:json_pretty_print).and_return(:true)
+ @knife.stub!(:confirm).and_return(true)
+ @roles = Hash.new
+ %w{dev staging production}.each do |role_name|
+ role = Chef::Role.new()
+ role.name(role_name)
+ role.stub!(:destroy).and_return(true)
+ @roles[role_name] = role
+ end
+ Chef::Role.stub!(:list).and_return(@roles)
+ end
+
+ describe "run" do
+
+ it "should get the list of the roles" do
+ Chef::Role.should_receive(:list).and_return(@roles)
+ @knife.run
+ end
+
+ it "should print the roles you are about to delete" do
+ @knife.should_receive(:json_pretty_print).with(@knife.format_list_for_display(@roles))
+ @knife.run
+ end
+
+ it "should confirm you really want to delete them" do
+ @knife.should_receive(:confirm)
+ @knife.run
+ end
+
+ it "should delete each role" do
+ @roles.each_value do |r|
+ r.should_receive(:destroy)
+ end
+ @knife.run
+ end
+
+ it "should only delete roles that match the regex" do
+ @knife.name_args = ["dev"]
+ @roles["dev"].should_receive(:destroy)
+ @roles["staging"].should_not_receive(:destroy)
+ @roles["production"].should_not_receive(:destroy)
+ @knife.run
+ end
+
+ it "should exit if the regex is not provided" do
+ @knife.name_args = []
+ lambda { @knife.run }.should raise_error(SystemExit)
+ end
+
+ describe "with -p or --print_after" do
+ it "should pretty_print the roles, formatted for display" do
+ @knife.config[:print_after] = true
+ @roles.each_value do |n|
+ @knife.should_receive(:json_pretty_print).with(@knife.format_for_display(n))
+ end
+ @knife.run
+ end
+ end
+ end
+end