require 'support/integration_helper' require 'chef/knife/delete_essentials' require 'chef/knife/list_essentials' require 'chef/knife/raw_essentials' describe 'knife delete' do extend IntegrationSupport include KnifeSupport let :everything do < 'version "1.0.0"' } data_bag 'x', { 'y' => '{}' } environment 'x', '{}' node 'x', '{}' role 'x', '{}' user 'x', '{}' when_the_repository 'also has one of each thing' 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', {} it 'knife delete /cookbooks/x fails' do knife('delete /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 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 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 --local /').should_succeed nothing end it 'knife delete -r /* fails' do knife('delete -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 < 'version "1.0.0"', 'onlyin1.0.0.rb' => '' } cookbook 'x', '1.0.1', { 'metadata.rb' => 'version "1.0.1"', 'onlyin1.0.1.rb' => 'hi' } # TODO this seems wrong it 'knife delete /cookbooks/x deletes the latest version on the server and the local version' do knife('delete -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 cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"', 'onlyin1.0.0.rb' => ''} cookbook 'x', '0.9.9', { 'metadata.rb' => 'version "0.9.9"', 'onlyin0.9.9.rb' => 'hi' } it 'knife delete /cookbooks/x deletes the latest version on the server and the local version' do knife('delete -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 cookbook 'x', '1.0.1', { 'metadata.rb' => 'version "1.0.1"', 'onlyin1.0.1.rb' => 'hi' } it 'knife delete /cookbooks/x deletes the server and client version of the cookbook' do knife('delete -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 cookbook 'x', '0.9.9', { 'metadata.rb' => 'version "0.9.9"', 'onlyin0.9.9.rb' => 'hi' } it 'knife delete /cookbooks/x deletes the server and client version of the cookbook' do knife('delete -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 cookbook 'x', '2.0.11', { 'metadata.rb' => 'version "2.0.11"' } cookbook 'x', '11.0.0', { 'metadata.rb' => 'version "11.0.0"' } it 'knife delete deletes the latest version' do knife('delete -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n" knife('raw /cookbooks/x').should_succeed /2.0.11/ end end end end