# # Author:: John Keiser () # Copyright:: Copyright (c) 2013 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 'support/shared/integration/integration_helper' require 'chef/knife/delete' require 'chef/knife/list' require 'chef/knife/raw' describe 'knife delete', :workstation do include IntegrationSupport include KnifeSupport let :everything do < '{}' } environment 'x', '{}' node 'x', '{}' role 'x', '{}' user 'x', '{}' end when_the_repository 'also has one of each thing' do before do file 'clients/x.json', {} file 'cookbooks/x/metadata.rb', '' file 'data_bags/x/y.json', {} file 'environments/_default.json', {} file 'environments/x.json', {} file 'nodes/x.json', {} file 'roles/x.json', {} file 'users/x.json', {} end it 'knife delete --both /cookbooks/x fails' do knife('delete --both /cookbooks/x').should_fail < "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_everything knife('list -Rf --local /').should_succeed < "ERROR: /environments/_default.json (remote) cannot be deleted (default environment cannot be modified).\n" knife('list -Rf /').should_succeed server_everything knife('list -Rf --local /').should_succeed nothing end it 'knife delete --both / fails' do knife('delete --both /').should_fail "ERROR: / (remote) cannot be deleted.\nERROR: / (local) cannot be deleted.\n" knife('list -Rf /').should_succeed server_everything knife('list -Rf --local /').should_succeed nothing end it 'knife delete --both -r /* fails' do knife('delete --both -r /*').should_fail < /USAGE/ knife('list -Rf /').should_succeed < "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 < /USAGE/ knife('list -Rf /').should_succeed < '' } cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => 'hi' } end # TODO this seems wrong it 'knife delete --both -r /cookbooks/x deletes the latest version on the server and the local version' do knife('delete --both -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n" knife('raw /cookbooks/x').should_succeed(/1.0.0/) knife('list --local /cookbooks').should_succeed '' end end when_the_chef_server 'has an earlier version for the cookbook' do before do cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => ''} cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => 'hi' } end it 'knife delete --both /cookbooks/x deletes the latest version on the server and the local version' do knife('delete --both -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n" knife('raw /cookbooks/x').should_succeed(/0.9.9/) knife('list --local /cookbooks').should_succeed '' end end when_the_chef_server 'has a later version for the cookbook, and no current version' do before { cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => 'hi' } } it 'knife delete --both /cookbooks/x deletes the server and client version of the cookbook' do knife('delete --both -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n" knife('raw /cookbooks/x').should_fail(/404/) knife('list --local /cookbooks').should_succeed '' end end when_the_chef_server 'has an earlier version for the cookbook, and no current version' do before { cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => 'hi' } } it 'knife delete --both /cookbooks/x deletes the server and client version of the cookbook' do knife('delete --both -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n" knife('raw /cookbooks/x').should_fail(/404/) knife('list --local /cookbooks').should_succeed '' end end end when_the_repository 'is empty' do when_the_chef_server 'has two versions of a cookbook' do before do cookbook 'x', '2.0.11' cookbook 'x', '11.0.0' end it 'knife delete deletes the latest version' do knife('delete --both -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n" knife('raw /cookbooks/x').should_succeed( /2.0.11/ ) end end end when_the_chef_server "is in Enterprise mode", :osc_compat => false, :single_org => false do before do organization 'foo' do container 'x', {} group 'x', {} end end before :each do Chef::Config.chef_server_url = URI.join(Chef::Config.chef_server_url, '/organizations/foo') end it 'knife delete /acls/containers/environments.json fails with a reasonable error' do knife('delete /acls/containers/environments.json').should_fail "ERROR: /acls/containers/environments.json (remote) cannot be deleted.\n" end it 'knife delete /containers/x.json succeeds' do knife('delete /containers/x.json').should_succeed "Deleted /containers/x.json\n" knife('raw /containers/x.json').should_fail(/404/) end it 'knife delete /groups/x.json succeeds' do knife('delete /groups/x.json').should_succeed "Deleted /groups/x.json\n" knife('raw /groups/x.json').should_fail(/404/) end it 'knife delete /org.json fails with a reasonable error' do knife('delete /org.json').should_fail "ERROR: /org.json (remote) cannot be deleted.\n" end it 'knife delete /invitations.json fails with a reasonable error' do knife('delete /invitations.json').should_fail "ERROR: /invitations.json (remote) cannot be deleted.\n" end it 'knife delete /members.json fails with a reasonable error' do knife('delete /members.json').should_fail "ERROR: /members.json (remote) cannot be deleted.\n" end end end