require 'support/integration_helper' require 'chef/knife/upload_essentials' require 'chef/knife/diff_essentials' describe 'knife upload' do extend IntegrationSupport include KnifeSupport when_the_chef_server "has one of each thing" do client 'x', '{}' cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"' } data_bag 'x', { 'y' => '{}' } environment 'x', '{}' node 'x', '{}' role 'x', '{}' user 'x', '{}' when_the_repository 'has only top-level directories' do directory 'clients' directory 'cookbooks' directory 'data_bags' directory 'environments' directory 'nodes' directory 'roles' directory 'users' it 'knife upload does nothing' do knife('upload /').should_succeed '' knife('diff --name-status /').should_succeed < "WARN: The default environment (_default.json) cannot be deleted. Skipping.\n") Deleted extra entry /cookbooks/x (purge is on) Deleted extra entry /data_bags/x (purge is on) Deleted extra entry /environments/x.json (purge is on) Deleted extra entry /roles/x.json (purge is on) EOM knife('diff --name-status /').should_succeed < 'y' } file 'cookbooks/x/blah.rb', '' file 'cookbooks/y/metadata.rb', 'version "1.0.0"' file 'data_bags/x/z.json', < 'y' } file 'roles/y.json', < 'y' } it 'knife upload adds the new files' do knife('upload /').should_succeed < /USAGE/ end end end end # Test upload of an item when the other end doesn't even have the container when_the_chef_server 'is empty' do when_the_repository 'has two data bag items' do file 'data_bags/x/y.json', < {}, 'modified' => {}, 'unmodified' => {} } when_the_repository 'has a modified, unmodified, added and deleted data bag item' do file 'data_bags/x/added.json', < 'version "1.0.0"', 'z.rb' => '' } when_the_repository 'has a modified, extra and missing file for the cookbook' do file 'cookbooks/x/metadata.rb', 'version "1.0.0"' file 'cookbooks/x/y.rb', 'hi' it 'knife upload of any individual file fails' do knife('upload /cookbooks/x/metadata.rb').should_fail "ERROR: remote/cookbooks/x/metadata.rb cannot be updated.\n" knife('upload /cookbooks/x/y.rb').should_fail "ERROR: remote/cookbooks/x cannot have a child created under it.\n" knife('upload --purge /cookbooks/x/z.rb').should_fail "ERROR: remote/cookbooks/x/z.rb cannot be deleted.\n" end # TODO this is a bit of an inconsistency: if we didn't specify --purge, # technically we shouldn't have deleted missing files. But ... cookbooks # are a special case. it 'knife upload of the cookbook itself succeeds' do knife('upload /cookbooks/x').should_succeed <