spec/integration/delete_spec.rb in knife-essentials-0.9.8 vs spec/integration/delete_spec.rb in knife-essentials-1.0.0.beta1

- old
+ new

@@ -7,40 +7,79 @@ extend IntegrationSupport include KnifeSupport let :everything do <<EOM +/clients +/clients/x.json /cookbooks /cookbooks/x /cookbooks/x/metadata.rb /data_bags /data_bags/x /data_bags/x/y.json /environments /environments/_default.json /environments/x.json +/nodes +/nodes/x.json /roles /roles/x.json +/users +/users/x.json EOM end + let :server_everything do + <<EOM +/clients +/clients/chef-validator.json +/clients/chef-webui.json +/clients/x.json +/cookbooks +/cookbooks/x +/cookbooks/x/metadata.rb +/data_bags +/data_bags/x +/data_bags/x/y.json +/environments +/environments/_default.json +/environments/x.json +/nodes +/nodes/x.json +/roles +/roles/x.json +/users +/users/admin.json +/users/x.json +EOM + end let :server_nothing do <<EOM +/clients +/clients/chef-validator.json +/clients/chef-webui.json /cookbooks /data_bags /environments /environments/_default.json +/nodes /roles +/users +/users/admin.json EOM end let :nothing do <<EOM +/clients /cookbooks /data_bags /environments +/nodes /roles +/users EOM end when_the_chef_server "has one of each thing" do client 'x', '{}' @@ -64,68 +103,98 @@ it 'knife delete /cookbooks/x fails' do knife('delete /cookbooks/x').should_fail <<EOM ERROR: /cookbooks/x (remote) must be deleted recursively! Pass -r to knife delete. ERROR: /cookbooks/x (local) must be deleted recursively! Pass -r to knife delete. EOM - knife('list -Rf /').should_succeed everything + knife('list -Rf /').should_succeed server_everything knife('list -Rf --local /').should_succeed everything end it 'knife delete -r /cookbooks/x deletes x' do knife('delete -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n" knife('list -Rf /').should_succeed <<EOM +/clients +/clients/chef-validator.json +/clients/chef-webui.json +/clients/x.json /cookbooks /data_bags /data_bags/x /data_bags/x/y.json /environments /environments/_default.json /environments/x.json +/nodes +/nodes/x.json /roles /roles/x.json +/users +/users/admin.json +/users/x.json EOM knife('list -Rf --local /').should_succeed <<EOM +/clients +/clients/x.json /cookbooks /data_bags /data_bags/x /data_bags/x/y.json /environments /environments/_default.json /environments/x.json +/nodes +/nodes/x.json /roles /roles/x.json +/users +/users/x.json EOM end it 'knife delete -r --local-only /cookbooks/x deletes x locally but not remotely' do knife('delete -r --local-only /cookbooks/x').should_succeed "Deleted /cookbooks/x\n" - knife('list -Rf /').should_succeed everything + knife('list -Rf /').should_succeed server_everything knife('list -Rf --local /').should_succeed <<EOM +/clients +/clients/x.json /cookbooks /data_bags /data_bags/x /data_bags/x/y.json /environments /environments/_default.json /environments/x.json +/nodes +/nodes/x.json /roles /roles/x.json +/users +/users/x.json EOM end it 'knife delete -r --remote-only /cookbooks/x deletes x remotely but not locally' do knife('delete -r --remote-only /cookbooks/x').should_succeed "Deleted /cookbooks/x\n" knife('list -Rf /').should_succeed <<EOM +/clients +/clients/chef-validator.json +/clients/chef-webui.json +/clients/x.json /cookbooks /data_bags /data_bags/x /data_bags/x/y.json /environments /environments/_default.json /environments/x.json +/nodes +/nodes/x.json /roles /roles/x.json +/users +/users/admin.json +/users/x.json EOM knife('list -Rf --local /').should_succeed everything end # TODO delete empty data bag (particularly different on local side) @@ -136,177 +205,249 @@ knife('delete /data_bags/empty').should_fail <<EOM ERROR: /data_bags/empty (remote) must be deleted recursively! Pass -r to knife delete. ERROR: /data_bags/empty (local) must be deleted recursively! Pass -r to knife delete. EOM knife('list -Rf /').should_succeed <<EOM +/clients +/clients/chef-validator.json +/clients/chef-webui.json +/clients/x.json /cookbooks /cookbooks/x /cookbooks/x/metadata.rb /data_bags /data_bags/empty /data_bags/x /data_bags/x/y.json /environments /environments/_default.json /environments/x.json +/nodes +/nodes/x.json /roles /roles/x.json +/users +/users/admin.json +/users/x.json EOM knife('list -Rf --local /').should_succeed <<EOM +/clients +/clients/x.json /cookbooks /cookbooks/x /cookbooks/x/metadata.rb /data_bags /data_bags/empty /data_bags/x /data_bags/x/y.json /environments /environments/_default.json /environments/x.json +/nodes +/nodes/x.json /roles /roles/x.json +/users +/users/x.json EOM end end it 'knife delete /data_bags/x fails' do knife('delete /data_bags/x').should_fail <<EOM ERROR: /data_bags/x (remote) must be deleted recursively! Pass -r to knife delete. ERROR: /data_bags/x (local) must be deleted recursively! Pass -r to knife delete. EOM - knife('list -Rf /').should_succeed everything + knife('list -Rf /').should_succeed server_everything knife('list -Rf --local /').should_succeed everything end it 'knife delete -r /data_bags/x deletes x' do knife('delete -r /data_bags/x').should_succeed "Deleted /data_bags/x\n" knife('list -Rf /').should_succeed <<EOM +/clients +/clients/chef-validator.json +/clients/chef-webui.json +/clients/x.json /cookbooks /cookbooks/x /cookbooks/x/metadata.rb /data_bags /environments /environments/_default.json /environments/x.json +/nodes +/nodes/x.json /roles /roles/x.json +/users +/users/admin.json +/users/x.json EOM knife('list -Rf --local /').should_succeed <<EOM +/clients +/clients/x.json /cookbooks /cookbooks/x /cookbooks/x/metadata.rb /data_bags /environments /environments/_default.json /environments/x.json +/nodes +/nodes/x.json /roles /roles/x.json +/users +/users/x.json EOM end it 'knife delete /environments/x.json deletes x' do knife('delete /environments/x.json').should_succeed "Deleted /environments/x.json\n" knife('list -Rf /').should_succeed <<EOM +/clients +/clients/chef-validator.json +/clients/chef-webui.json +/clients/x.json /cookbooks /cookbooks/x /cookbooks/x/metadata.rb /data_bags /data_bags/x /data_bags/x/y.json /environments /environments/_default.json +/nodes +/nodes/x.json /roles /roles/x.json +/users +/users/admin.json +/users/x.json EOM knife('list -Rf --local /').should_succeed <<EOM +/clients +/clients/x.json /cookbooks /cookbooks/x /cookbooks/x/metadata.rb /data_bags /data_bags/x /data_bags/x/y.json /environments /environments/_default.json +/nodes +/nodes/x.json /roles /roles/x.json +/users +/users/x.json EOM end it 'knife delete /roles/x.json deletes x' do knife('delete /roles/x.json').should_succeed "Deleted /roles/x.json\n" knife('list -Rf /').should_succeed <<EOM +/clients +/clients/chef-validator.json +/clients/chef-webui.json +/clients/x.json /cookbooks /cookbooks/x /cookbooks/x/metadata.rb /data_bags /data_bags/x /data_bags/x/y.json /environments /environments/_default.json /environments/x.json +/nodes +/nodes/x.json /roles +/users +/users/admin.json +/users/x.json EOM knife('list -Rf --local /').should_succeed <<EOM +/clients +/clients/x.json /cookbooks /cookbooks/x /cookbooks/x/metadata.rb /data_bags /data_bags/x /data_bags/x/y.json /environments /environments/_default.json /environments/x.json +/nodes +/nodes/x.json /roles +/users +/users/x.json EOM end it 'knife delete /environments/_default.json fails but still deletes the local copy' do knife('delete /environments/_default.json').should_fail :stderr => "ERROR: /environments/_default.json (remote) cannot be deleted (default environment cannot be modified).\n", :stdout => "Deleted /environments/_default.json\n" - knife('list -Rf /').should_succeed everything + knife('list -Rf /').should_succeed server_everything knife('list -Rf --local /').should_succeed <<EOM +/clients +/clients/x.json /cookbooks /cookbooks/x /cookbooks/x/metadata.rb /data_bags /data_bags/x /data_bags/x/y.json /environments /environments/x.json +/nodes +/nodes/x.json /roles /roles/x.json +/users +/users/x.json EOM end it 'knife delete /environments/nonexistent.json fails' do knife('delete /environments/nonexistent.json').should_fail "ERROR: /environments/nonexistent.json: No such file or directory\n" - knife('list -Rf /').should_succeed everything + knife('list -Rf /').should_succeed server_everything knife('list -Rf --local /').should_succeed everything end it 'knife delete / fails' do knife('delete /').should_fail <<EOM ERROR: / (remote) cannot be deleted. ERROR: / (local) cannot be deleted. EOM - knife('list -Rf /').should_succeed everything + knife('list -Rf /').should_succeed server_everything knife('list -Rf --local /').should_succeed everything end it 'knife delete -r /* fails' do knife('delete -r /*').should_fail <<EOM ERROR: / (remote) cannot be deleted. ERROR: / (local) cannot be deleted. +ERROR: /clients (remote) cannot be deleted. +ERROR: /clients (local) cannot be deleted. ERROR: /cookbooks (remote) cannot be deleted. ERROR: /cookbooks (local) cannot be deleted. ERROR: /data_bags (remote) cannot be deleted. ERROR: /data_bags (local) cannot be deleted. ERROR: /environments (remote) cannot be deleted. ERROR: /environments (local) cannot be deleted. +ERROR: /nodes (remote) cannot be deleted. +ERROR: /nodes (local) cannot be deleted. ERROR: /roles (remote) cannot be deleted. ERROR: /roles (local) cannot be deleted. +ERROR: /users (remote) cannot be deleted. +ERROR: /users (local) cannot be deleted. EOM - knife('list -Rf /').should_succeed everything + knife('list -Rf /').should_succeed server_everything knife('list -Rf --local /').should_succeed everything end end when_the_repository 'has only top-level directories' do @@ -318,143 +459,197 @@ directory 'roles' directory 'users' it 'knife delete /cookbooks/x fails' do knife('delete /cookbooks/x').should_fail "ERROR: /cookbooks/x (remote) must be deleted recursively! Pass -r to knife delete.\n" - knife('list -Rf /').should_succeed everything + knife('list -Rf /').should_succeed server_everything knife('list -Rf --local /').should_succeed nothing end it 'knife delete -r /cookbooks/x deletes x' do knife('delete -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n" knife('list -Rf /').should_succeed <<EOM +/clients +/clients/chef-validator.json +/clients/chef-webui.json +/clients/x.json /cookbooks /data_bags /data_bags/x /data_bags/x/y.json /environments /environments/_default.json /environments/x.json +/nodes +/nodes/x.json /roles /roles/x.json +/users +/users/admin.json +/users/x.json EOM knife('list -Rf --local /').should_succeed nothing end it 'knife delete /data_bags/x fails' do knife('delete /data_bags/x').should_fail "ERROR: /data_bags/x (remote) must be deleted recursively! Pass -r to knife delete.\n" - knife('list -Rf /').should_succeed everything + knife('list -Rf /').should_succeed server_everything knife('list -Rf --local /').should_succeed nothing end it 'knife delete -r /data_bags/x deletes x' do knife('delete -r /data_bags/x').should_succeed "Deleted /data_bags/x\n" knife('list -Rf /').should_succeed <<EOM +/clients +/clients/chef-validator.json +/clients/chef-webui.json +/clients/x.json /cookbooks /cookbooks/x /cookbooks/x/metadata.rb /data_bags /environments /environments/_default.json /environments/x.json +/nodes +/nodes/x.json /roles /roles/x.json +/users +/users/admin.json +/users/x.json EOM knife('list -Rf --local /').should_succeed nothing end it 'knife delete /environments/x.json deletes x' do knife('delete /environments/x.json').should_succeed "Deleted /environments/x.json\n" knife('list -Rf /').should_succeed <<EOM +/clients +/clients/chef-validator.json +/clients/chef-webui.json +/clients/x.json /cookbooks /cookbooks/x /cookbooks/x/metadata.rb /data_bags /data_bags/x /data_bags/x/y.json /environments /environments/_default.json +/nodes +/nodes/x.json /roles /roles/x.json +/users +/users/admin.json +/users/x.json EOM knife('list -Rf --local /').should_succeed nothing end it 'knife delete /roles/x.json deletes x' do knife('delete /roles/x.json').should_succeed "Deleted /roles/x.json\n" knife('list -Rf /').should_succeed <<EOM +/clients +/clients/chef-validator.json +/clients/chef-webui.json +/clients/x.json /cookbooks /cookbooks/x /cookbooks/x/metadata.rb /data_bags /data_bags/x /data_bags/x/y.json /environments /environments/_default.json /environments/x.json +/nodes +/nodes/x.json /roles +/users +/users/admin.json +/users/x.json EOM knife('list -Rf --local /').should_succeed nothing end it 'knife delete /environments/_default.json fails' do knife('delete /environments/_default.json').should_fail "", :stderr => "ERROR: /environments/_default.json (remote) cannot be deleted (default environment cannot be modified).\n" - knife('list -Rf /').should_succeed everything + knife('list -Rf /').should_succeed server_everything knife('list -Rf --local /').should_succeed nothing end it 'knife delete / fails' do knife('delete /').should_fail "ERROR: / (remote) cannot be deleted.\nERROR: / (local) cannot be deleted.\n" - knife('list -Rf /').should_succeed everything + knife('list -Rf /').should_succeed server_everything knife('list -Rf --local /').should_succeed nothing end it 'knife delete -r /* fails' do knife('delete -r /*').should_fail <<EOM ERROR: / (remote) cannot be deleted. ERROR: / (local) cannot be deleted. +ERROR: /clients (remote) cannot be deleted. +ERROR: /clients (local) cannot be deleted. ERROR: /cookbooks (remote) cannot be deleted. ERROR: /cookbooks (local) cannot be deleted. ERROR: /data_bags (remote) cannot be deleted. ERROR: /data_bags (local) cannot be deleted. ERROR: /environments (remote) cannot be deleted. ERROR: /environments (local) cannot be deleted. +ERROR: /nodes (remote) cannot be deleted. +ERROR: /nodes (local) cannot be deleted. ERROR: /roles (remote) cannot be deleted. ERROR: /roles (local) cannot be deleted. +ERROR: /users (remote) cannot be deleted. +ERROR: /users (local) cannot be deleted. EOM - knife('list -Rf /').should_succeed everything + knife('list -Rf /').should_succeed server_everything knife('list -Rf --local /').should_succeed nothing end it 'knife delete /environments/nonexistent.json fails' do knife('delete /environments/nonexistent.json').should_fail "ERROR: /environments/nonexistent.json: No such file or directory\n" - knife('list -Rf /').should_succeed everything + knife('list -Rf /').should_succeed server_everything knife('list -Rf --local /').should_succeed nothing end context 'and cwd is at the top level' do cwd '.' it 'knife delete fails' do knife('delete').should_fail "FATAL: Must specify at least one argument. If you want to delete everything in this directory, type \"knife delete --recurse .\"\n", :stdout => /USAGE/ knife('list -Rf /').should_succeed <<EOM +clients +clients/chef-validator.json +clients/chef-webui.json +clients/x.json cookbooks cookbooks/x cookbooks/x/metadata.rb data_bags data_bags/x data_bags/x/y.json environments environments/_default.json environments/x.json +nodes +nodes/x.json roles roles/x.json +users +users/admin.json +users/x.json EOM knife('list -Rf --local /').should_succeed <<EOM +clients cookbooks data_bags environments +nodes roles +users EOM end end end end @@ -478,19 +673,25 @@ it 'knife delete -r /cookbooks/x deletes x' do knife('delete -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n" knife('list -Rf /').should_succeed server_nothing knife('list -Rf --local /').should_succeed <<EOM +/clients +/clients/x.json /cookbooks /data_bags /data_bags/x /data_bags/x/y.json /environments /environments/_default.json /environments/x.json +/nodes +/nodes/x.json /roles /roles/x.json +/users +/users/x.json EOM end it 'knife delete /data_bags/x fails' do knife('delete /data_bags/x').should_fail "ERROR: /data_bags/x (local) must be deleted recursively! Pass -r to knife delete.\n" @@ -500,70 +701,94 @@ it 'knife delete -r /data_bags/x deletes x' do knife('delete -r /data_bags/x').should_succeed "Deleted /data_bags/x\n" knife('list -Rf /').should_succeed server_nothing knife('list -Rf --local /').should_succeed <<EOM +/clients +/clients/x.json /cookbooks /cookbooks/x /cookbooks/x/metadata.rb /data_bags /environments /environments/_default.json /environments/x.json +/nodes +/nodes/x.json /roles /roles/x.json +/users +/users/x.json EOM end it 'knife delete /environments/x.json deletes x' do knife('delete /environments/x.json').should_succeed "Deleted /environments/x.json\n" knife('list -Rf /').should_succeed server_nothing knife('list -Rf --local /').should_succeed <<EOM +/clients +/clients/x.json /cookbooks /cookbooks/x /cookbooks/x/metadata.rb /data_bags /data_bags/x /data_bags/x/y.json /environments /environments/_default.json +/nodes +/nodes/x.json /roles /roles/x.json +/users +/users/x.json EOM end it 'knife delete /roles/x.json deletes x' do knife('delete /roles/x.json').should_succeed "Deleted /roles/x.json\n" knife('list -Rf /').should_succeed server_nothing knife('list -Rf --local /').should_succeed <<EOM +/clients +/clients/x.json /cookbooks /cookbooks/x /cookbooks/x/metadata.rb /data_bags /data_bags/x /data_bags/x/y.json /environments /environments/_default.json /environments/x.json +/nodes +/nodes/x.json /roles +/users +/users/x.json EOM end it 'knife delete /environments/_default.json fails but still deletes the local copy' do knife('delete /environments/_default.json').should_fail :stderr => "ERROR: /environments/_default.json (remote) cannot be deleted (default environment cannot be modified).\n", :stdout => "Deleted /environments/_default.json\n" knife('list -Rf /').should_succeed server_nothing knife('list -Rf --local /').should_succeed <<EOM +/clients +/clients/x.json /cookbooks /cookbooks/x /cookbooks/x/metadata.rb /data_bags /data_bags/x /data_bags/x/y.json /environments /environments/x.json +/nodes +/nodes/x.json /roles /roles/x.json +/users +/users/x.json EOM end it 'knife delete / fails' do knife('delete /').should_fail "ERROR: / (remote) cannot be deleted.\nERROR: / (local) cannot be deleted.\n" @@ -573,18 +798,24 @@ it 'knife delete -r /* fails' do knife('delete -r /*').should_fail <<EOM ERROR: / (remote) cannot be deleted. ERROR: / (local) cannot be deleted. +ERROR: /clients (remote) cannot be deleted. +ERROR: /clients (local) cannot be deleted. ERROR: /cookbooks (remote) cannot be deleted. ERROR: /cookbooks (local) cannot be deleted. ERROR: /data_bags (remote) cannot be deleted. ERROR: /data_bags (local) cannot be deleted. ERROR: /environments (remote) cannot be deleted. ERROR: /environments (local) cannot be deleted. +ERROR: /nodes (remote) cannot be deleted. +ERROR: /nodes (local) cannot be deleted. ERROR: /roles (remote) cannot be deleted. ERROR: /roles (local) cannot be deleted. +ERROR: /users (remote) cannot be deleted. +ERROR: /users (local) cannot be deleted. EOM knife('list -Rf /').should_succeed server_nothing knife('list -Rf --local /').should_succeed everything end @@ -597,27 +828,39 @@ context 'and cwd is at the top level' do cwd '.' it 'knife delete fails' do knife('delete').should_fail "FATAL: Must specify at least one argument. If you want to delete everything in this directory, type \"knife delete --recurse .\"\n", :stdout => /USAGE/ knife('list -Rf /').should_succeed <<EOM +clients +clients/chef-validator.json +clients/chef-webui.json cookbooks data_bags environments environments/_default.json +nodes roles +users +users/admin.json EOM knife('list -Rf --local /').should_succeed <<EOM +clients +clients/x.json cookbooks cookbooks/x cookbooks/x/metadata.rb data_bags data_bags/x data_bags/x/y.json environments environments/_default.json environments/x.json +nodes +nodes/x.json roles roles/x.json +users +users/x.json EOM end end end end