From 01120b3a61cb3d110ec28c022693730d78c330ca Mon Sep 17 00:00:00 2001 From: Ho-Sheng Hsiao Date: Mon, 4 Mar 2013 19:15:44 -0800 Subject: [SPEC] Refactored diff, upload, and download spec to have explicit inputs --- spec/integration/knife/download_spec.rb | 961 ++++++++++++++++++++++++-------- 1 file changed, 723 insertions(+), 238 deletions(-) (limited to 'spec/integration/knife/download_spec.rb') diff --git a/spec/integration/knife/download_spec.rb b/spec/integration/knife/download_spec.rb index 306fd6677d..ee120fb474 100644 --- a/spec/integration/knife/download_spec.rb +++ b/spec/integration/knife/download_spec.rb @@ -6,20 +6,27 @@ describe 'knife download' do extend IntegrationSupport include KnifeSupport - when_the_chef_server "has one of each thing" do - one_of_each_resource_in_chef_server - - 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 download downloads everything' do - knife('download /').should_succeed < '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 download downloads everything' do + knife('download /').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 download does nothing' do + knife('download /').should_succeed '' + knife('diff --name-status /').should_succeed < /USAGE/ + context 'when current directory is top level' do + cwd '.' + it 'knife download with no parameters reports an error' do + knife('download').should_fail "FATAL: Must specify at least one argument. If you want to download everything in this directory, type \"knife download .\"\n", :stdout => /USAGE/ + end end end - end # when the repository is empty - end # when the chef server has one of each resource + end - # Test download of an item when the other end doesn't even have the container - when_the_repository 'is empty' do - when_the_chef_server 'has two data bag items' do - data_bag 'x', { 'y' => {}, 'z' => {} } + # Test download of an item when the other end doesn't even have the container + when_the_repository 'is empty' do + when_the_chef_server 'has two data bag items' do + data_bag 'x', { 'y' => {}, 'z' => {} } - it 'knife download of one data bag item itself succeeds' do - knife('download /data_bags/x/y.json').should_succeed < {}, - 'modified' => { 'foo' => 'bar' }, - 'unmodified' => {} - } + when_the_chef_server 'has a modified, unmodified, added and deleted data bag item' do + data_bag 'x', { + 'added' => {}, + 'modified' => { 'foo' => 'bar' }, + 'unmodified' => {} + } - it 'knife download of the modified file succeeds' do - knife('download /data_bags/x/modified.json').should_succeed < /USAGE/ + knife('diff --name-status /data_bags').should_succeed '' end - it 'knife download --purge . downloads everything' do - knife('download --purge .').should_succeed < /USAGE/ + end + it 'knife download --purge . downloads everything' do + knife('download --purge .').should_succeed < 'version "1.0.0"', 'y.rb' => 'hi' } when_the_repository 'has a cookbook' do - without_versioned_cookbooks do - file 'cookbooks/x/metadata.rb', 'version "1.0.0"' - file 'cookbooks/x/z.rb', '' + file 'cookbooks/x/metadata.rb', 'version "1.0.0"' + file 'cookbooks/x/z.rb', '' + + when_the_chef_server 'has a modified, added and deleted file for the cookbook' do + cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"', 'y.rb' => 'hi' } it 'knife download of a modified file succeeds' do knife('download /cookbooks/x/metadata.rb').should_succeed "Updated /cookbooks/x/metadata.rb\n" @@ -355,7 +428,7 @@ EOM Updated /cookbooks/x/metadata.rb Created /cookbooks/x/y.rb EOM - knife('diff --name-status /cookbooks').should_succeed < "WARN: Parse error reading #{path_to('environments/x.json')} as JSON: A JSON text must at least contain two octets!\n" + knife('diff --name-status /environments/x.json').should_succeed '' + end + end + + when_the_repository 'has the same environment with the wrong name in the file' do + file 'environments/x.json', { 'name' => 'y' } + it 'knife download succeeds' do + knife('download /environments/x.json').should_succeed "Updated /environments/x.json\n" + knife('diff --name-status /environments/x.json').should_succeed '' + end + end + + when_the_repository 'has the same environment with no name in the file' do + file 'environments/x.json', { 'description' => 'hi' } + it 'knife download succeeds' do + knife('download /environments/x.json').should_succeed "Updated /environments/x.json\n" + knife('diff --name-status /environments/x.json').should_succeed '' + end + end + end end # without versioned cookbooks with_versioned_cookbooks do + 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 download downloads everything' do + knife('download /').should_succeed < 'y' } + file 'cookbooks/x-1.0.0/blah.rb', '' + file 'cookbooks/x-2.0.0/metadata.rb', 'version "2.0.0"' + file 'cookbooks/y-1.0.0/metadata.rb', 'version "1.0.0"' + file 'data_bags/x/z.json', < 'y' } + file 'roles/y.json', < 'y' } + + it 'knife download does nothing' do + knife('download /').should_succeed '' + knife('diff --name-status /').should_succeed < /USAGE/ + end + end + end + end + + # Test download of an item when the other end doesn't even have the container + when_the_repository 'is empty' do + when_the_chef_server 'has two data bag items' do + data_bag 'x', { 'y' => {}, 'z' => {} } + + it 'knife download of one data bag item itself succeeds' do + knife('download /data_bags/x/y.json').should_succeed < {}, + 'modified' => { 'foo' => 'bar' }, + 'unmodified' => {} + } + + it 'knife download of the modified file succeeds' do + knife('download /data_bags/x/modified.json').should_succeed < /USAGE/ + end + it 'knife download --purge . downloads everything' do + knife('download --purge .').should_succeed < 'version "1.0.0"', 'y.rb' => 'hi' } + + it 'knife download of a modified file succeeds' do + knife('download /cookbooks/x-1.0.0/metadata.rb').should_succeed "Updated /cookbooks/x-1.0.0/metadata.rb\n" + knife('diff --name-status /cookbooks').should_succeed < '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 download /cookbooks/x downloads the updated file' do + it 'knife download /cookbooks downloads the updated file' do knife('download --purge /cookbooks').should_succeed < 'version "0.9.9"', 'onlyin0.9.9.rb' => 'hi' } - it 'knife download /cookbooks/x downloads the old version' do + it 'knife download --purge /cookbooks downloads the old version and deletes the new version' do knife('download --purge /cookbooks').should_succeed < "WARN: Parse error reading #{path_to('environments/x.json')} as JSON: A JSON text must at least contain two octets!\n" - knife('diff --name-status /environments/x.json').should_succeed '' + when_the_chef_server 'has an environment' do + environment 'x', {} + when_the_repository 'has an environment with bad JSON' do + file 'environments/x.json', '{' + it 'knife download succeeds' do + knife('download /environments/x.json').should_succeed "Updated /environments/x.json\n", :stderr => "WARN: Parse error reading #{path_to('environments/x.json')} as JSON: A JSON text must at least contain two octets!\n" + knife('diff --name-status /environments/x.json').should_succeed '' + end end - end - when_the_repository 'has the same environment with the wrong name in the file' do - file 'environments/x.json', { 'name' => 'y' } - it 'knife download succeeds' do - knife('download /environments/x.json').should_succeed "Updated /environments/x.json\n" - knife('diff --name-status /environments/x.json').should_succeed '' + when_the_repository 'has the same environment with the wrong name in the file' do + file 'environments/x.json', { 'name' => 'y' } + it 'knife download succeeds' do + knife('download /environments/x.json').should_succeed "Updated /environments/x.json\n" + knife('diff --name-status /environments/x.json').should_succeed '' + end end - end - when_the_repository 'has the same environment with no name in the file' do - file 'environments/x.json', { 'description' => 'hi' } - it 'knife download succeeds' do - knife('download /environments/x.json').should_succeed "Updated /environments/x.json\n" - knife('diff --name-status /environments/x.json').should_succeed '' + when_the_repository 'has the same environment with no name in the file' do + file 'environments/x.json', { 'description' => 'hi' } + it 'knife download succeeds' do + knife('download /environments/x.json').should_succeed "Updated /environments/x.json\n" + knife('diff --name-status /environments/x.json').should_succeed '' + end end end - end + end # with versioned cookbooks end -- cgit v1.2.1