summaryrefslogtreecommitdiff
path: root/spec/integration/knife/download_spec.rb
diff options
context:
space:
mode:
authordanielsdeleo <dan@getchef.com>2014-08-07 18:20:20 -0700
committerdanielsdeleo <dan@getchef.com>2014-08-10 09:40:36 -0700
commit674cc65dc68b9d5f0eaa36f2409c6c12becf2c11 (patch)
tree7c33437663b794c5cdbbd78eff5a77f0b83ead1f /spec/integration/knife/download_spec.rb
parente2a6b85f5b095f2350fa24f8e825fa22660fcbc7 (diff)
downloadchef-674cc65dc68b9d5f0eaa36f2409c6c12becf2c11.tar.gz
Convert Chef Zero helpers to instance methods
* Prefer instance methods to class methods for Chef Zero helpers. RSpec's design and feature set heavily favors using instance methods for test setup. This change will allow us to use let bindings and more naturally move common setup to shared contexts. * Temporarily copy ChefZero's RSpec features in-repo. master of Chef Zero is currently broken for unit testing. Copy the changes here for now so we can make progress. * Automatically generate a metadata file when using the "cookbook" helper function. This will be needed for a subsequent change that makes `name' required in metadata.
Diffstat (limited to 'spec/integration/knife/download_spec.rb')
-rw-r--r--spec/integration/knife/download_spec.rb355
1 files changed, 228 insertions, 127 deletions
diff --git a/spec/integration/knife/download_spec.rb b/spec/integration/knife/download_spec.rb
index f266b47b1b..4788a564b7 100644
--- a/spec/integration/knife/download_spec.rb
+++ b/spec/integration/knife/download_spec.rb
@@ -20,27 +20,32 @@ require 'chef/knife/download'
require 'chef/knife/diff'
describe 'knife download' do
- extend IntegrationSupport
+ include IntegrationSupport
include KnifeSupport
context 'without 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', {}
+
+ before do
+ client 'x', {}
+ cookbook 'x', '1.0.0'
+ data_bag 'x', { 'y' => {} }
+ environment 'x', {}
+ node 'x', {}
+ role 'x', {}
+ user 'x', {}
+ end
when_the_repository 'has only top-level directories' do
- directory 'clients'
- directory 'cookbooks'
- directory 'data_bags'
- directory 'environments'
- directory 'nodes'
- directory 'roles'
- directory 'users'
+ before do
+ directory 'clients'
+ directory 'cookbooks'
+ directory 'data_bags'
+ directory 'environments'
+ directory 'nodes'
+ directory 'roles'
+ directory 'users'
+ end
it 'knife download downloads everything' do
knife('download /').should_succeed <<EOM
@@ -63,17 +68,19 @@ EOM
end
when_the_repository 'has an identical copy of each thing' do
- file 'clients/chef-validator.json', { 'validator' => true, 'public_key' => ChefZero::PUBLIC_KEY }
- file 'clients/chef-webui.json', { 'admin' => true, 'public_key' => ChefZero::PUBLIC_KEY }
- file 'clients/x.json', { 'public_key' => ChefZero::PUBLIC_KEY }
- file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
- file 'data_bags/x/y.json', {}
- file 'environments/_default.json', { "description" => "The default Chef environment" }
- file 'environments/x.json', {}
- file 'nodes/x.json', {}
- file 'roles/x.json', {}
- file 'users/admin.json', { 'admin' => true, 'public_key' => ChefZero::PUBLIC_KEY }
- file 'users/x.json', { 'public_key' => ChefZero::PUBLIC_KEY }
+ before do
+ file 'clients/chef-validator.json', { 'validator' => true, 'public_key' => ChefZero::PUBLIC_KEY }
+ file 'clients/chef-webui.json', { 'admin' => true, 'public_key' => ChefZero::PUBLIC_KEY }
+ file 'clients/x.json', { 'public_key' => ChefZero::PUBLIC_KEY }
+ file 'cookbooks/x/metadata.rb', cb_metadata("x", "1.0.0")
+ file 'data_bags/x/y.json', {}
+ file 'environments/_default.json', { "description" => "The default Chef environment" }
+ file 'environments/x.json', {}
+ file 'nodes/x.json', {}
+ file 'roles/x.json', {}
+ file 'users/admin.json', { 'admin' => true, 'public_key' => ChefZero::PUBLIC_KEY }
+ file 'users/x.json', { 'public_key' => ChefZero::PUBLIC_KEY }
+ end
it 'knife download makes no changes' do
knife('download /').should_succeed ''
@@ -86,7 +93,8 @@ EOM
end
context 'except the role file' do
- file 'roles/x.json', <<EOM
+ before do
+ file 'roles/x.json', <<EOM
{
"chef_type": "role",
"default_attributes": {
@@ -103,6 +111,8 @@ EOM
]
}
EOM
+ end
+
it 'knife download changes the role' do
knife('download /').should_succeed "Updated /roles/x.json\n"
knife('diff --name-status /').should_succeed ''
@@ -115,7 +125,8 @@ EOM
end
context 'except the role file is textually different, but not ACTUALLY different' do
- file 'roles/x.json', <<EOM
+ before do
+ file 'roles/x.json', <<EOM
{
"chef_type": "role",
"default_attributes": {
@@ -132,6 +143,8 @@ EOM
]
}
EOM
+ end
+
it 'knife download / does not change anything' do
knife('download /').should_succeed ''
knife('diff --name-status /').should_succeed ''
@@ -139,15 +152,17 @@ EOM
end
context 'as well as one extra copy of each thing' do
- file 'clients/y.json', { 'public_key' => ChefZero::PUBLIC_KEY }
- file 'cookbooks/x/blah.rb', ''
- file 'cookbooks/y/metadata.rb', 'version "1.0.0"'
- file 'data_bags/x/z.json', {}
- file 'data_bags/y/zz.json', {}
- file 'environments/y.json', {}
- file 'nodes/y.json', {}
- file 'roles/y.json', {}
- file 'users/y.json', { 'public_key' => ChefZero::PUBLIC_KEY }
+ before do
+ file 'clients/y.json', { 'public_key' => ChefZero::PUBLIC_KEY }
+ file 'cookbooks/x/blah.rb', ''
+ file 'cookbooks/y/metadata.rb', cb_metadata("x", "1.0.0")
+ file 'data_bags/x/z.json', {}
+ file 'data_bags/y/zz.json', {}
+ file 'environments/y.json', {}
+ file 'nodes/y.json', {}
+ file 'roles/y.json', {}
+ file 'users/y.json', { 'public_key' => ChefZero::PUBLIC_KEY }
+ end
it 'knife download does nothing' do
knife('download /').should_succeed ''
@@ -235,7 +250,10 @@ EOM
end
context 'when current directory is top level' do
- cwd '.'
+ before do
+ cwd '.'
+ end
+
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
@@ -246,7 +264,9 @@ EOM
# 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' => {} }
+ before do
+ data_bag 'x', { 'y' => {}, 'z' => {} }
+ end
it 'knife download of one data bag item itself succeeds' do
knife('download /data_bags/x/y.json').should_succeed <<EOM
@@ -271,28 +291,32 @@ EOM
end
when_the_repository 'has three data bag items' do
- file 'data_bags/x/deleted.json', <<EOM
+ before do
+ file 'data_bags/x/deleted.json', <<EOM
{
"id": "deleted"
}
EOM
- file 'data_bags/x/modified.json', <<EOM
+ file 'data_bags/x/modified.json', <<EOM
{
"id": "modified"
}
EOM
- file 'data_bags/x/unmodified.json', <<EOM
+ file 'data_bags/x/unmodified.json', <<EOM
{
"id": "unmodified"
}
EOM
+ end
when_the_chef_server 'has a modified, unmodified, added and deleted data bag item' do
- data_bag 'x', {
- 'added' => {},
- 'modified' => { 'foo' => 'bar' },
- 'unmodified' => {}
- }
+ before do
+ data_bag 'x', {
+ 'added' => {},
+ 'modified' => { 'foo' => 'bar' },
+ 'unmodified' => {}
+ }
+ end
it 'knife download of the modified file succeeds' do
knife('download /data_bags/x/modified.json').should_succeed <<EOM
@@ -355,7 +379,9 @@ EOM
knife('diff --name-status /data_bags').should_succeed ''
end
context 'when cwd is the /data_bags directory' do
- cwd 'data_bags'
+ before do
+ cwd 'data_bags'
+ end
it 'knife download fails' 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
@@ -380,11 +406,15 @@ EOM
end
when_the_repository 'has a cookbook' do
- file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
- file 'cookbooks/x/z.rb', ''
+ before do
+ file 'cookbooks/x/metadata.rb', cb_metadata("x", "1.0.0")
+ file 'cookbooks/x/z.rb', ''
+ end
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' }
+ before do
+ cookbook 'x', '1.0.0', { 'metadata.rb' => cb_metadata("x", "1.0.0", "#extra content"), 'y.rb' => 'hi' }
+ end
it 'knife download of a modified file succeeds' do
knife('download /cookbooks/x/metadata.rb').should_succeed "Updated /cookbooks/x/metadata.rb\n"
@@ -436,12 +466,16 @@ EOM
end
when_the_repository 'has a cookbook' do
- file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
- file 'cookbooks/x/onlyin1.0.0.rb', 'old_text'
+ before do
+ file 'cookbooks/x/metadata.rb', cb_metadata("x", "1.0.0")
+ file 'cookbooks/x/onlyin1.0.0.rb', 'old_text'
+ end
when_the_chef_server 'has a later version for the cookbook' do
- cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"', 'onlyin1.0.0.rb' => '' }
- cookbook 'x', '1.0.1', { 'metadata.rb' => 'version "1.0.1"', 'onlyin1.0.1.rb' => 'hi' }
+ before do
+ cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => '' }
+ cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => 'hi' }
+ end
it 'knife download /cookbooks/x downloads the latest version' do
knife('download --purge /cookbooks/x').should_succeed <<EOM
@@ -454,8 +488,11 @@ EOM
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' }
+ before do
+ cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => ''}
+ cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => 'hi' }
+ end
+
it 'knife download /cookbooks/x downloads the updated file' do
knife('download --purge /cookbooks/x').should_succeed <<EOM
Updated /cookbooks/x/onlyin1.0.0.rb
@@ -465,7 +502,9 @@ EOM
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' }
+ before do
+ cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => 'hi' }
+ end
it 'knife download /cookbooks/x downloads the latest version' do
knife('download --purge /cookbooks/x').should_succeed <<EOM
@@ -478,7 +517,9 @@ EOM
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' }
+ before do
+ cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => 'hi' }
+ end
it 'knife download /cookbooks/x downloads the old version' do
knife('download --purge /cookbooks/x').should_succeed <<EOM
@@ -492,9 +533,13 @@ EOM
end
when_the_chef_server 'has an environment' do
- environment 'x', {}
+ before do
+ environment 'x', {}
+ end
when_the_repository 'has an environment with bad JSON' do
- file 'environments/x.json', '{'
+ before do
+ file 'environments/x.json', '{'
+ end
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 ''
@@ -502,7 +547,9 @@ EOM
end
when_the_repository 'has the same environment with the wrong name in the file' do
- file 'environments/x.json', { 'name' => 'y' }
+ before do
+ file 'environments/x.json', { 'name' => 'y' }
+ end
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 ''
@@ -510,7 +557,9 @@ EOM
end
when_the_repository 'has the same environment with no name in the file' do
- file 'environments/x.json', { 'description' => 'hi' }
+ before do
+ file 'environments/x.json', { 'description' => 'hi' }
+ end
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 ''
@@ -521,22 +570,26 @@ EOM
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', {}
+ before do
+ client 'x', {}
+ cookbook 'x', '1.0.0'
+ data_bag 'x', { 'y' => {} }
+ environment 'x', {}
+ node 'x', {}
+ role 'x', {}
+ user 'x', {}
+ end
when_the_repository 'has only top-level directories' do
- directory 'clients'
- directory 'cookbooks'
- directory 'data_bags'
- directory 'environments'
- directory 'nodes'
- directory 'roles'
- directory 'users'
+ before do
+ directory 'clients'
+ directory 'cookbooks'
+ directory 'data_bags'
+ directory 'environments'
+ directory 'nodes'
+ directory 'roles'
+ directory 'users'
+ end
it 'knife download downloads everything' do
knife('download /').should_succeed <<EOM
@@ -559,17 +612,19 @@ EOM
end
when_the_repository 'has an identical copy of each thing' do
- file 'clients/chef-validator.json', { 'validator' => true, 'public_key' => ChefZero::PUBLIC_KEY }
- file 'clients/chef-webui.json', { 'admin' => true, 'public_key' => ChefZero::PUBLIC_KEY }
- file 'clients/x.json', { 'public_key' => ChefZero::PUBLIC_KEY }
- file 'cookbooks/x-1.0.0/metadata.rb', 'version "1.0.0"'
- file 'data_bags/x/y.json', {}
- file 'environments/_default.json', { "description" => "The default Chef environment" }
- file 'environments/x.json', {}
- file 'nodes/x.json', {}
- file 'roles/x.json', {}
- file 'users/admin.json', { 'admin' => true, 'public_key' => ChefZero::PUBLIC_KEY }
- file 'users/x.json', { 'public_key' => ChefZero::PUBLIC_KEY }
+ before do
+ file 'clients/chef-validator.json', { 'validator' => true, 'public_key' => ChefZero::PUBLIC_KEY }
+ file 'clients/chef-webui.json', { 'admin' => true, 'public_key' => ChefZero::PUBLIC_KEY }
+ file 'clients/x.json', { 'public_key' => ChefZero::PUBLIC_KEY }
+ file 'cookbooks/x-1.0.0/metadata.rb', cb_metadata("x", "1.0.0")
+ file 'data_bags/x/y.json', {}
+ file 'environments/_default.json', { "description" => "The default Chef environment" }
+ file 'environments/x.json', {}
+ file 'nodes/x.json', {}
+ file 'roles/x.json', {}
+ file 'users/admin.json', { 'admin' => true, 'public_key' => ChefZero::PUBLIC_KEY }
+ file 'users/x.json', { 'public_key' => ChefZero::PUBLIC_KEY }
+ end
it 'knife download makes no changes' do
knife('download /').should_succeed ''
@@ -582,7 +637,9 @@ EOM
end
context 'except the role file' do
- file 'roles/x.json', { "description" => "blarghle" }
+ before do
+ file 'roles/x.json', { "description" => "blarghle" }
+ end
it 'knife download changes the role' do
knife('download /').should_succeed "Updated /roles/x.json\n"
@@ -591,7 +648,8 @@ EOM
end
context 'except the role file is textually different, but not ACTUALLY different' do
- file 'roles/x.json', <<EOM
+ before do
+ file 'roles/x.json', <<EOM
{
"chef_type": "role" ,
"default_attributes": {
@@ -608,6 +666,8 @@ EOM
]
}
EOM
+ end
+
it 'knife download / does not change anything' do
knife('download /').should_succeed ''
knife('diff --name-status /').should_succeed ''
@@ -615,16 +675,18 @@ EOM
end
context 'as well as one extra copy of each thing' do
- file 'clients/y.json', { 'public_key' => ChefZero::PUBLIC_KEY }
- 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', {}
- file 'data_bags/y/zz.json', {}
- file 'environments/y.json', {}
- file 'nodes/y.json', {}
- file 'roles/y.json', {}
- file 'users/y.json', { 'public_key' => ChefZero::PUBLIC_KEY }
+ before do
+ file 'clients/y.json', { 'public_key' => ChefZero::PUBLIC_KEY }
+ 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', {}
+ file 'data_bags/y/zz.json', {}
+ file 'environments/y.json', {}
+ file 'nodes/y.json', {}
+ file 'roles/y.json', {}
+ file 'users/y.json', { 'public_key' => ChefZero::PUBLIC_KEY }
+ end
it 'knife download does nothing' do
knife('download /').should_succeed ''
@@ -688,7 +750,9 @@ EOM
end
context 'when current directory is top level' do
- cwd '.'
+ before do
+ cwd '.'
+ end
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
@@ -699,7 +763,9 @@ EOM
# 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' => {} }
+ before do
+ data_bag 'x', { 'y' => {}, 'z' => {} }
+ end
it 'knife download of one data bag item itself succeeds' do
knife('download /data_bags/x/y.json').should_succeed <<EOM
@@ -715,28 +781,32 @@ EOM
end
when_the_repository 'has three data bag items' do
- file 'data_bags/x/deleted.json', <<EOM
+ before do
+ file 'data_bags/x/deleted.json', <<EOM
{
"id": "deleted"
}
EOM
- file 'data_bags/x/modified.json', <<EOM
+ file 'data_bags/x/modified.json', <<EOM
{
"id": "modified"
}
EOM
- file 'data_bags/x/unmodified.json', <<EOM
+ file 'data_bags/x/unmodified.json', <<EOM
{
"id": "unmodified"
}
EOM
+ end
when_the_chef_server 'has a modified, unmodified, added and deleted data bag item' do
- data_bag 'x', {
- 'added' => {},
- 'modified' => { 'foo' => 'bar' },
- 'unmodified' => {}
- }
+ before do
+ data_bag 'x', {
+ 'added' => {},
+ 'modified' => { 'foo' => 'bar' },
+ 'unmodified' => {}
+ }
+ end
it 'knife download of the modified file succeeds' do
knife('download /data_bags/x/modified.json').should_succeed <<EOM
@@ -799,7 +869,9 @@ EOM
knife('diff --name-status /data_bags').should_succeed ''
end
context 'when cwd is the /data_bags directory' do
- cwd 'data_bags'
+ before do
+ cwd 'data_bags'
+ end
it 'knife download fails' 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
@@ -824,11 +896,15 @@ EOM
end
when_the_repository 'has a cookbook' do
- file 'cookbooks/x-1.0.0/metadata.rb', 'version "1.0.0"'
- file 'cookbooks/x-1.0.0/z.rb', ''
+ before do
+ file 'cookbooks/x-1.0.0/metadata.rb', 'name "x"; version "1.0.0"'
+ file 'cookbooks/x-1.0.0/z.rb', ''
+ end
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' }
+ before do
+ cookbook 'x', '1.0.0', { 'y.rb' => 'hi' }
+ end
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"
@@ -880,12 +956,16 @@ EOM
end
when_the_repository 'has a cookbook' do
- file 'cookbooks/x-1.0.0/metadata.rb', 'version "1.0.0"'
- file 'cookbooks/x-1.0.0/onlyin1.0.0.rb', 'old_text'
+ before do
+ file 'cookbooks/x-1.0.0/metadata.rb', cb_metadata("x", "1.0.0")
+ file 'cookbooks/x-1.0.0/onlyin1.0.0.rb', 'old_text'
+ end
when_the_chef_server 'has a later version for the cookbook' do
- cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"', 'onlyin1.0.0.rb' => '' }
- cookbook 'x', '1.0.1', { 'metadata.rb' => 'version "1.0.1"', 'onlyin1.0.1.rb' => 'hi' }
+ before do
+ cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => '' }
+ cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => 'hi' }
+ end
it 'knife download /cookbooks/x downloads the latest version' do
knife('download --purge /cookbooks').should_succeed <<EOM
@@ -899,8 +979,11 @@ EOM
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' }
+ before do
+ cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => ''}
+ cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => 'hi' }
+ end
+
it 'knife download /cookbooks downloads the updated file' do
knife('download --purge /cookbooks').should_succeed <<EOM
Created /cookbooks/x-0.9.9
@@ -913,7 +996,9 @@ EOM
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' }
+ before do
+ cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => 'hi' }
+ end
it 'knife download /cookbooks/x downloads the latest version' do
knife('download --purge /cookbooks').should_succeed <<EOM
@@ -927,7 +1012,9 @@ EOM
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' }
+ before do
+ cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => 'hi' }
+ end
it 'knife download --purge /cookbooks downloads the old version and deletes the new version' do
knife('download --purge /cookbooks').should_succeed <<EOM
@@ -942,9 +1029,15 @@ EOM
end
when_the_chef_server 'has an environment' do
- environment 'x', {}
+ before do
+ environment 'x', {}
+ end
+
when_the_repository 'has an environment with bad JSON' do
- file 'environments/x.json', '{'
+ before do
+ file 'environments/x.json', '{'
+ end
+
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 ''
@@ -952,7 +1045,10 @@ EOM
end
when_the_repository 'has the same environment with the wrong name in the file' do
- file 'environments/x.json', { 'name' => 'y' }
+ before do
+ file 'environments/x.json', { 'name' => 'y' }
+ end
+
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 ''
@@ -960,7 +1056,10 @@ EOM
end
when_the_repository 'has the same environment with no name in the file' do
- file 'environments/x.json', { 'description' => 'hi' }
+ before do
+ file 'environments/x.json', { 'description' => 'hi' }
+ end
+
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 ''
@@ -970,7 +1069,9 @@ EOM
end # with versioned cookbooks
when_the_chef_server 'has a cookbook' do
- cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"' }
+ before do
+ cookbook 'x', '1.0.0'
+ end
when_the_repository 'is empty' do
it 'knife download /cookbooks/x signs all requests', :ruby_gte_19_only do