summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--spec/integration/client/client_spec.rb10
-rw-r--r--spec/integration/client/ipv6_spec.rb30
-rw-r--r--spec/integration/knife/chef_fs_data_store_spec.rb98
-rw-r--r--spec/integration/knife/chef_repo_path_spec.rb183
-rw-r--r--spec/integration/knife/chef_repository_file_system_spec.rb184
-rw-r--r--spec/integration/knife/chefignore_spec.rb122
-rw-r--r--spec/integration/knife/common_options_spec.rb37
-rw-r--r--spec/integration/knife/cookbook_api_ipv6_spec.rb4
-rw-r--r--spec/integration/knife/delete_spec.rb112
-rw-r--r--spec/integration/knife/deps_spec.rb239
-rw-r--r--spec/integration/knife/diff_spec.rb278
-rw-r--r--spec/integration/knife/download_spec.rb355
-rw-r--r--spec/integration/knife/list_spec.rb116
-rw-r--r--spec/integration/knife/raw_spec.rb33
-rw-r--r--spec/integration/knife/redirection_spec.rb4
-rw-r--r--spec/integration/knife/serve_spec.rb4
-rw-r--r--spec/integration/knife/show_spec.rb58
-rw-r--r--spec/integration/knife/upload_spec.rb447
-rw-r--r--spec/integration/recipes/lwrp_inline_resources_spec.rb18
-rw-r--r--spec/integration/solo/solo_spec.rb29
-rw-r--r--spec/support/shared/integration/chef_zero_support.rb130
-rw-r--r--spec/support/shared/integration/integration_helper.rb196
22 files changed, 1663 insertions, 1024 deletions
diff --git a/spec/integration/client/client_spec.rb b/spec/integration/client/client_spec.rb
index 8d6f0f03e1..f0d978c516 100644
--- a/spec/integration/client/client_spec.rb
+++ b/spec/integration/client/client_spec.rb
@@ -2,7 +2,7 @@ require 'support/shared/integration/integration_helper'
require 'chef/mixin/shell_out'
describe "chef-client" do
- extend IntegrationSupport
+ include IntegrationSupport
include Chef::Mixin::ShellOut
let(:chef_dir) { File.join(File.dirname(__FILE__), "..", "..", "..", "bin") }
@@ -19,7 +19,7 @@ describe "chef-client" do
let(:chef_client) { "ruby #{chef_dir}/chef-client" }
when_the_repository "has a cookbook with a no-op recipe" do
- file 'cookbooks/x/recipes/default.rb', ''
+ before { file 'cookbooks/x/recipes/default.rb', '' }
it "should complete with success" do
file 'config/client.rb', <<EOM
@@ -49,7 +49,7 @@ EOM
end
context 'and a config file under .chef/knife.rb' do
- file '.chef/knife.rb', 'xxx.xxx'
+ before { file '.chef/knife.rb', 'xxx.xxx' }
it 'should load .chef/knife.rb when -z is specified' do
result = shell_out("#{chef_client} -z -o 'x::default' --config-file-jail \"#{path_to('')}\"", :cwd => path_to(''))
@@ -74,7 +74,8 @@ EOM
end
context 'and a private key' do
- file 'mykey.pem', <<EOM
+ before do
+ file 'mykey.pem', <<EOM
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEApubutqtYYQ5UiA9QhWP7UvSmsfHsAoPKEVVPdVW/e8Svwpyf
0Xef6OFWVmBE+W442ZjLOe2y6p2nSnaq4y7dg99NFz6X+16mcKiCbj0RCiGqCvCk
@@ -103,6 +104,7 @@ syHLXYFNy0OxMtH/bBAXBGNHd9gf5uOnqh0pYcbe/uRAxumC7Rl0cL509eURiA2T
+vFmf54y9YdnLXaqv+FhJT6B6V7WX7IpU9BMqJY1cJYXHuHG2KA=
-----END RSA PRIVATE KEY-----
EOM
+ end
it "should complete with success even with a client key" do
file 'config/client.rb', <<EOM
diff --git a/spec/integration/client/ipv6_spec.rb b/spec/integration/client/ipv6_spec.rb
index bb4889b0fa..5e3f7cfb0b 100644
--- a/spec/integration/client/ipv6_spec.rb
+++ b/spec/integration/client/ipv6_spec.rb
@@ -19,7 +19,7 @@ require 'support/shared/integration/integration_helper'
require 'chef/mixin/shell_out'
describe "chef-client" do
- extend IntegrationSupport
+ include IntegrationSupport
include Chef::Mixin::ShellOut
let(:chef_zero_opts) { {:host => "::1"} }
@@ -87,8 +87,8 @@ END_CLIENT_RB
when_the_chef_server "is running on IPv6", :not_supported_on_solaris do
when_the_repository "has a cookbook with a no-op recipe" do
- cookbook 'noop', '1.0.0', { 'metadata.rb' => 'version "1.0.0"' }, "recipes" => {"default.rb" => "#raise 'foo'"}
before do
+ cookbook 'noop', '1.0.0', { }, "recipes" => {"default.rb" => "#raise 'foo'"}
file 'config/client.rb', client_rb_content
file 'config/validator.pem', validation_pem
end
@@ -102,21 +102,23 @@ END_CLIENT_RB
when_the_repository "has a cookbook that hits server APIs" do
- recipe=<<-END_RECIPE
- actual_item = data_bag_item("expect_bag", "expect_item")
- if actual_item.key?("expect_key") and actual_item["expect_key"] == "expect_value"
- Chef::Log.info "lookin good"
- else
- Chef::Log.error("!" * 80)
- raise "unexpected data bag item content \#{actual_item.inspect}"
- Chef::Log.error("!" * 80)
- end
+ before do
+ recipe=<<-END_RECIPE
+ actual_item = data_bag_item("expect_bag", "expect_item")
+ if actual_item.key?("expect_key") and actual_item["expect_key"] == "expect_value"
+ Chef::Log.info "lookin good"
+ else
+ Chef::Log.error("!" * 80)
+ raise "unexpected data bag item content \#{actual_item.inspect}"
+ Chef::Log.error("!" * 80)
+ end
- END_RECIPE
+ END_RECIPE
- data_bag('expect_bag', { 'expect_item' => {"expect_key" => "expect_value"} })
+ data_bag('expect_bag', { 'expect_item' => {"expect_key" => "expect_value"} })
- cookbook 'api-smoke-test', '1.0.0', { 'metadata.rb' => 'version "1.0.0"' }, "recipes" => {"default.rb" => recipe}
+ cookbook 'api-smoke-test', '1.0.0', { }, "recipes" => {"default.rb" => recipe}
+ end
before do
file 'config/client.rb', client_rb_content
diff --git a/spec/integration/knife/chef_fs_data_store_spec.rb b/spec/integration/knife/chef_fs_data_store_spec.rb
index 7e55aa7319..da1c72bd0c 100644
--- a/spec/integration/knife/chef_fs_data_store_spec.rb
+++ b/spec/integration/knife/chef_fs_data_store_spec.rb
@@ -23,17 +23,19 @@ require 'chef/knife/raw'
require 'chef/knife/cookbook_upload'
describe 'ChefFSDataStore tests' do
- extend IntegrationSupport
+ include IntegrationSupport
include KnifeSupport
when_the_repository "has one of each thing" do
- file 'clients/x.json', {}
- file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
- file 'data_bags/x/y.json', {}
- file 'environments/x.json', {}
- file 'nodes/x.json', {}
- file 'roles/x.json', {}
- file 'users/x.json', {}
+ before do
+ file 'clients/x.json', {}
+ file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
+ file 'data_bags/x/y.json', {}
+ file 'environments/x.json', {}
+ file 'nodes/x.json', {}
+ file 'roles/x.json', {}
+ file 'users/x.json', {}
+ end
context 'GET /TYPE' do
it 'knife list -z -R returns everything' do
@@ -102,7 +104,7 @@ EOM
context 'GET /TYPE/NAME' do
it 'knife show -z /clients/x.json works' do
- knife('show -z /clients/x.json').should_succeed /"x"/
+ knife('show -z /clients/x.json').should_succeed( /"x"/ )
end
it 'knife show -z /cookbooks/x/metadata.rb works' do
@@ -110,33 +112,35 @@ EOM
end
it 'knife show -z /data_bags/x/y.json works' do
- knife('show -z /data_bags/x/y.json').should_succeed /"y"/
+ knife('show -z /data_bags/x/y.json').should_succeed( /"y"/ )
end
it 'knife show -z /environments/x.json works' do
- knife('show -z /environments/x.json').should_succeed /"x"/
+ knife('show -z /environments/x.json').should_succeed( /"x"/ )
end
it 'knife show -z /nodes/x.json works' do
- knife('show -z /nodes/x.json').should_succeed /"x"/
+ knife('show -z /nodes/x.json').should_succeed( /"x"/ )
end
it 'knife show -z /roles/x.json works' do
- knife('show -z /roles/x.json').should_succeed /"x"/
+ knife('show -z /roles/x.json').should_succeed( /"x"/ )
end
it 'knife show -z /users/x.json works' do
- knife('show -z /users/x.json').should_succeed /"x"/
+ knife('show -z /users/x.json').should_succeed( /"x"/ )
end
end
context 'PUT /TYPE/NAME' do
- file 'empty.json', {}
- file 'rolestuff.json', '{"description":"hi there","name":"x"}'
- file 'cookbooks_to_upload/x/metadata.rb', "version '1.0.0'\n\n"
+ before do
+ file 'empty.json', {}
+ file 'rolestuff.json', '{"description":"hi there","name":"x"}'
+ file 'cookbooks_to_upload/x/metadata.rb', "version '1.0.0'\n\n"
+ end
it 'knife raw -z -i empty.json -m PUT /clients/x' do
- knife("raw -z -i #{path_to('empty.json')} -m PUT /clients/x").should_succeed /"x"/
+ knife("raw -z -i #{path_to('empty.json')} -m PUT /clients/x").should_succeed( /"x"/ )
knife('list --local /clients').should_succeed "/clients/x.json\n"
end
@@ -149,32 +153,32 @@ EOM
end
it 'knife raw -z -i empty.json -m PUT /data/x/y' do
- knife("raw -z -i #{path_to('empty.json')} -m PUT /data/x/y").should_succeed /"y"/
+ knife("raw -z -i #{path_to('empty.json')} -m PUT /data/x/y").should_succeed( /"y"/ )
knife('list --local -Rfp /data_bags').should_succeed "/data_bags/x/\n/data_bags/x/y.json\n"
end
it 'knife raw -z -i empty.json -m PUT /environments/x' do
- knife("raw -z -i #{path_to('empty.json')} -m PUT /environments/x").should_succeed /"x"/
+ knife("raw -z -i #{path_to('empty.json')} -m PUT /environments/x").should_succeed( /"x"/ )
knife('list --local /environments').should_succeed "/environments/x.json\n"
end
it 'knife raw -z -i empty.json -m PUT /nodes/x' do
- knife("raw -z -i #{path_to('empty.json')} -m PUT /nodes/x").should_succeed /"x"/
+ knife("raw -z -i #{path_to('empty.json')} -m PUT /nodes/x").should_succeed( /"x"/ )
knife('list --local /nodes').should_succeed "/nodes/x.json\n"
end
it 'knife raw -z -i empty.json -m PUT /roles/x' do
- knife("raw -z -i #{path_to('empty.json')} -m PUT /roles/x").should_succeed /"x"/
+ knife("raw -z -i #{path_to('empty.json')} -m PUT /roles/x").should_succeed( /"x"/ )
knife('list --local /roles').should_succeed "/roles/x.json\n"
end
it 'knife raw -z -i empty.json -m PUT /users/x' do
- knife("raw -z -i #{path_to('empty.json')} -m PUT /users/x").should_succeed /"x"/
+ knife("raw -z -i #{path_to('empty.json')} -m PUT /users/x").should_succeed( /"x"/ )
knife('list --local /users').should_succeed "/users/x.json\n"
end
it 'After knife raw -z -i rolestuff.json -m PUT /roles/x, the output is pretty', :pending => (RUBY_VERSION < "1.9") do
- knife("raw -z -i #{path_to('rolestuff.json')} -m PUT /roles/x").should_succeed /"x"/
+ knife("raw -z -i #{path_to('rolestuff.json')} -m PUT /roles/x").should_succeed( /"x"/ )
IO.read(path_to('roles/x.json')).should == <<EOM.strip
{
"name": "x",
@@ -187,14 +191,16 @@ EOM
when_the_repository 'is empty' do
context 'POST /TYPE/NAME' do
- file 'empty.json', { 'name' => 'z' }
- file 'empty_x.json', { 'name' => 'x' }
- file 'empty_id.json', { 'id' => 'z' }
- file 'rolestuff.json', '{"description":"hi there","name":"x"}'
- file 'cookbooks_to_upload/z/metadata.rb', "version '1.0.0'"
+ before do
+ file 'empty.json', { 'name' => 'z' }
+ file 'empty_x.json', { 'name' => 'x' }
+ file 'empty_id.json', { 'id' => 'z' }
+ file 'rolestuff.json', '{"description":"hi there","name":"x"}'
+ file 'cookbooks_to_upload/z/metadata.rb', "version '1.0.0'"
+ end
it 'knife raw -z -i empty.json -m POST /clients' do
- knife("raw -z -i #{path_to('empty.json')} -m POST /clients").should_succeed /uri/
+ knife("raw -z -i #{path_to('empty.json')} -m POST /clients").should_succeed( /uri/ )
knife('list --local /clients').should_succeed "/clients/z.json\n"
end
@@ -207,38 +213,38 @@ EOM
end
it 'knife raw -z -i empty.json -m POST /data' do
- knife("raw -z -i #{path_to('empty.json')} -m POST /data").should_succeed /uri/
+ knife("raw -z -i #{path_to('empty.json')} -m POST /data").should_succeed( /uri/ )
knife('list --local -Rfp /data_bags').should_succeed "/data_bags/z/\n"
end
it 'knife raw -z -i empty.json -m POST /data/x' do
- knife("raw -z -i #{path_to('empty_x.json')} -m POST /data").should_succeed /uri/
- knife("raw -z -i #{path_to('empty_id.json')} -m POST /data/x").should_succeed /"z"/
+ knife("raw -z -i #{path_to('empty_x.json')} -m POST /data").should_succeed( /uri/ )
+ knife("raw -z -i #{path_to('empty_id.json')} -m POST /data/x").should_succeed( /"z"/ )
knife('list --local -Rfp /data_bags').should_succeed "/data_bags/x/\n/data_bags/x/z.json\n"
end
it 'knife raw -z -i empty.json -m POST /environments' do
- knife("raw -z -i #{path_to('empty.json')} -m POST /environments").should_succeed /uri/
+ knife("raw -z -i #{path_to('empty.json')} -m POST /environments").should_succeed( /uri/ )
knife('list --local /environments').should_succeed "/environments/z.json\n"
end
it 'knife raw -z -i empty.json -m POST /nodes' do
- knife("raw -z -i #{path_to('empty.json')} -m POST /nodes").should_succeed /uri/
+ knife("raw -z -i #{path_to('empty.json')} -m POST /nodes").should_succeed( /uri/ )
knife('list --local /nodes').should_succeed "/nodes/z.json\n"
end
it 'knife raw -z -i empty.json -m POST /roles' do
- knife("raw -z -i #{path_to('empty.json')} -m POST /roles").should_succeed /uri/
+ knife("raw -z -i #{path_to('empty.json')} -m POST /roles").should_succeed( /uri/ )
knife('list --local /roles').should_succeed "/roles/z.json\n"
end
it 'knife raw -z -i empty.json -m POST /users' do
- knife("raw -z -i #{path_to('empty.json')} -m POST /users").should_succeed /uri/
+ knife("raw -z -i #{path_to('empty.json')} -m POST /users").should_succeed( /uri/ )
knife('list --local /users').should_succeed "/users/z.json\n"
end
it 'After knife raw -z -i rolestuff.json -m POST /roles, the output is pretty', :pending => (RUBY_VERSION < "1.9") do
- knife("raw -z -i #{path_to('rolestuff.json')} -m POST /roles").should_succeed /uri/
+ knife("raw -z -i #{path_to('rolestuff.json')} -m POST /roles").should_succeed( /uri/ )
IO.read(path_to('roles/x.json')).should == <<EOM.strip
{
"name": "x",
@@ -325,30 +331,32 @@ EOM
end
context 'PUT /TYPE/NAME' do
- file 'empty.json', {}
+ before do
+ file 'empty.json', {}
+ end
it 'knife raw -z -i empty.json -m PUT /clients/x fails with 404' do
- knife("raw -z -i #{path_to('empty.json')} -m PUT /clients/x").should_fail /404/
+ knife("raw -z -i #{path_to('empty.json')} -m PUT /clients/x").should_fail( /404/ )
end
it 'knife raw -z -i empty.json -m PUT /data/x/y fails with 404' do
- knife("raw -z -i #{path_to('empty.json')} -m PUT /data/x/y").should_fail /404/
+ knife("raw -z -i #{path_to('empty.json')} -m PUT /data/x/y").should_fail( /404/ )
end
it 'knife raw -z -i empty.json -m PUT /environments/x fails with 404' do
- knife("raw -z -i #{path_to('empty.json')} -m PUT /environments/x").should_fail /404/
+ knife("raw -z -i #{path_to('empty.json')} -m PUT /environments/x").should_fail( /404/ )
end
it 'knife raw -z -i empty.json -m PUT /nodes/x fails with 404' do
- knife("raw -z -i #{path_to('empty.json')} -m PUT /nodes/x").should_fail /404/
+ knife("raw -z -i #{path_to('empty.json')} -m PUT /nodes/x").should_fail( /404/ )
end
it 'knife raw -z -i empty.json -m PUT /roles/x fails with 404' do
- knife("raw -z -i #{path_to('empty.json')} -m PUT /roles/x").should_fail /404/
+ knife("raw -z -i #{path_to('empty.json')} -m PUT /roles/x").should_fail( /404/ )
end
it 'knife raw -z -i empty.json -m PUT /users/x fails with 404' do
- knife("raw -z -i #{path_to('empty.json')} -m PUT /users/x").should_fail /404/
+ knife("raw -z -i #{path_to('empty.json')} -m PUT /users/x").should_fail( /404/ )
end
end
end
diff --git a/spec/integration/knife/chef_repo_path_spec.rb b/spec/integration/knife/chef_repo_path_spec.rb
index 72d2ffbf75..90455ed374 100644
--- a/spec/integration/knife/chef_repo_path_spec.rb
+++ b/spec/integration/knife/chef_repo_path_spec.rb
@@ -21,36 +21,38 @@ require 'chef/knife/list'
require 'chef/knife/show'
describe 'chef_repo_path tests' do
- extend IntegrationSupport
+ include IntegrationSupport
include KnifeSupport
# TODO alternate repo_path / *_path
context 'alternate *_path' do
when_the_repository 'has clients and clients2, cookbooks and cookbooks2, etc.' do
- file 'clients/client1.json', {}
- file 'cookbooks/cookbook1/metadata.rb', ''
- file 'data_bags/bag/item.json', {}
- file 'environments/env1.json', {}
- file 'nodes/node1.json', {}
- file 'roles/role1.json', {}
- file 'users/user1.json', {}
-
- file 'clients2/client2.json', {}
- file 'cookbooks2/cookbook2/metadata.rb', ''
- file 'data_bags2/bag2/item2.json', {}
- file 'environments2/env2.json', {}
- file 'nodes2/node2.json', {}
- file 'roles2/role2.json', {}
- file 'users2/user2.json', {}
-
- directory 'chef_repo2' do
- file 'clients/client3.json', {}
- file 'cookbooks/cookbook3/metadata.rb', ''
- file 'data_bags/bag3/item3.json', {}
- file 'environments/env3.json', {}
- file 'nodes/node3.json', {}
- file 'roles/role3.json', {}
- file 'users/user3.json', {}
+ before do
+ file 'clients/client1.json', {}
+ file 'cookbooks/cookbook1/metadata.rb', ''
+ file 'data_bags/bag/item.json', {}
+ file 'environments/env1.json', {}
+ file 'nodes/node1.json', {}
+ file 'roles/role1.json', {}
+ file 'users/user1.json', {}
+
+ file 'clients2/client2.json', {}
+ file 'cookbooks2/cookbook2/metadata.rb', ''
+ file 'data_bags2/bag2/item2.json', {}
+ file 'environments2/env2.json', {}
+ file 'nodes2/node2.json', {}
+ file 'roles2/role2.json', {}
+ file 'users2/user2.json', {}
+
+ directory 'chef_repo2' do
+ file 'clients/client3.json', {}
+ file 'cookbooks/cookbook3/metadata.rb', ''
+ file 'data_bags/bag3/item3.json', {}
+ file 'environments/env3.json', {}
+ file 'nodes/node3.json', {}
+ file 'roles/role3.json', {}
+ file 'users/user3.json', {}
+ end
end
it 'knife list --local -Rfp --chef-repo-path chef_repo2 / grabs chef_repo2 stuff' do
@@ -105,21 +107,21 @@ EOM
end
context 'when cwd is at the top level' do
- cwd '.'
+ before { cwd '.' }
it 'knife list --local -Rfp fails' do
knife('list --local -Rfp').should_fail("ERROR: Attempt to use relative path '' when current directory is outside the repository path\n")
end
end
context 'when cwd is inside the data_bags directory' do
- cwd 'data_bags'
+ before { cwd 'data_bags' }
it 'knife list --local -Rfp fails' do
knife('list --local -Rfp').should_fail("ERROR: Attempt to use relative path '' when current directory is outside the repository path\n")
end
end
context 'when cwd is inside chef_repo2' do
- cwd 'chef_repo2'
+ before { cwd 'chef_repo2' }
it 'knife list --local -Rfp lists everything' do
knife('list --local -Rfp').should_succeed <<EOM
clients/
@@ -143,7 +145,7 @@ EOM
end
context 'when cwd is inside data_bags2' do
- cwd 'data_bags2'
+ before { cwd 'data_bags2' }
it 'knife list --local -Rfp lists data bags' do
knife('list --local -Rfp').should_succeed <<EOM
bag2/
@@ -164,7 +166,7 @@ EOM
end
context 'when cwd is at the top level' do
- cwd '.'
+ before { cwd '.' }
it 'knife list --local -Rfp lists everything' do
knife('list --local -Rfp').should_succeed <<EOM
clients/
@@ -188,21 +190,21 @@ EOM
end
context 'when cwd is inside the data_bags directory' do
- cwd 'data_bags'
+ before { cwd 'data_bags' }
it 'knife list --local -Rfp fails' do
knife('list --local -Rfp').should_fail("ERROR: Attempt to use relative path '' when current directory is outside the repository path\n")
end
end
context 'when cwd is inside chef_repo2' do
- cwd 'chef_repo2'
+ before { cwd 'chef_repo2' }
it 'knife list -Rfp fails' do
knife('list --local -Rfp').should_fail("ERROR: Attempt to use relative path '' when current directory is outside the repository path\n")
end
end
context 'when cwd is inside data_bags2' do
- cwd 'data_bags2'
+ before { cwd 'data_bags2' }
it 'knife list --local -Rfp lists data bags' do
knife('list --local -Rfp').should_succeed <<EOM
bag2/
@@ -221,21 +223,21 @@ EOM
end
context 'when cwd is at the top level' do
- cwd '.'
+ before { cwd '.' }
it 'knife list --local -Rfp fails' do
knife('list --local -Rfp').should_fail("ERROR: Attempt to use relative path '' when current directory is outside the repository path\n")
end
end
context 'when cwd is inside the data_bags directory' do
- cwd 'data_bags'
+ before { cwd 'data_bags' }
it 'knife list --local -Rfp fails' do
knife('list --local -Rfp').should_fail("ERROR: Attempt to use relative path '' when current directory is outside the repository path\n")
end
end
context 'when cwd is inside chef_repo2' do
- cwd 'chef_repo2'
+ before { cwd 'chef_repo2' }
it 'knife list --local -Rfp lists everything' do
knife('list --local -Rfp').should_succeed <<EOM
clients/
@@ -259,7 +261,7 @@ EOM
end
context 'when cwd is inside chef_repo2/data_bags' do
- cwd 'chef_repo2/data_bags'
+ before { cwd 'chef_repo2/data_bags' }
it 'knife list --local -Rfp lists data bags' do
knife('list --local -Rfp').should_succeed <<EOM
bag3/
@@ -281,20 +283,25 @@ EOM
end
context 'when there is a directory in clients1 and file in clients2 with the same name' do
- directory 'clients/blah.json'
- file 'clients2/blah.json', {}
+ before do
+ directory 'clients/blah.json'
+ file 'clients2/blah.json', {}
+ end
it 'knife show /clients/blah.json succeeds' do
knife('show --local /clients/blah.json').should_succeed <<EOM
/clients/blah.json:
{
+
}
EOM
end
end
context 'when there is a file in cookbooks1 and directory in cookbooks2 with the same name' do
- file 'cookbooks/blah', ''
- file 'cookbooks2/blah/metadata.rb', ''
+ before do
+ file 'cookbooks/blah', ''
+ file 'cookbooks2/blah/metadata.rb', ''
+ end
it 'knife list -Rfp cookbooks shows files in blah' do
knife('list --local -Rfp /cookbooks').should_succeed <<EOM
/cookbooks/blah/
@@ -308,8 +315,10 @@ EOM
end
context 'when there is an empty directory in cookbooks1 and a real cookbook in cookbooks2 with the same name' do
- directory 'cookbooks/blah'
- file 'cookbooks2/blah/metadata.rb', ''
+ before do
+ directory 'cookbooks/blah'
+ file 'cookbooks2/blah/metadata.rb', ''
+ end
it 'knife list -Rfp cookbooks shows files in blah' do
knife('list --local -Rfp /cookbooks').should_succeed(<<EOM, :stderr => "WARN: Cookbook 'blah' is empty or entirely chefignored at #{Chef::Config.cookbook_path[0]}/blah\n")
/cookbooks/blah/
@@ -323,8 +332,10 @@ EOM
end
context 'when there is a cookbook in cookbooks1 and a cookbook in cookbooks2 with the same name' do
- file 'cookbooks/blah/metadata.json', {}
- file 'cookbooks2/blah/metadata.rb', ''
+ before do
+ file 'cookbooks/blah/metadata.json', {}
+ file 'cookbooks2/blah/metadata.rb', ''
+ end
it 'knife list -Rfp cookbooks shows files in the first cookbook and not the second' do
knife('list --local -Rfp /cookbooks').should_succeed(<<EOM, :stderr => "WARN: Child with name 'blah' found in multiple directories: #{Chef::Config.cookbook_path[0]}/blah and #{Chef::Config.cookbook_path[1]}/blah\n")
/cookbooks/blah/
@@ -338,8 +349,10 @@ EOM
end
context 'when there is a file in data_bags1 and a directory in data_bags2 with the same name' do
- file 'data_bags/blah', ''
- file 'data_bags2/blah/item.json', ''
+ before do
+ file 'data_bags/blah', ''
+ file 'data_bags2/blah/item.json', ''
+ end
it 'knife list -Rfp data_bags shows files in blah' do
knife('list --local -Rfp /data_bags').should_succeed <<EOM
/data_bags/bag/
@@ -353,8 +366,10 @@ EOM
end
context 'when there is a data bag in data_bags1 and a data bag in data_bags2 with the same name' do
- file 'data_bags/blah/item1.json', ''
- file 'data_bags2/blah/item2.json', ''
+ before do
+ file 'data_bags/blah/item1.json', ''
+ file 'data_bags2/blah/item2.json', ''
+ end
it 'knife list -Rfp data_bags shows only items in data_bags1' do
knife('list --local -Rfp /data_bags').should_succeed(<<EOM, :stderr => "WARN: Child with name 'blah' found in multiple directories: #{Chef::Config.data_bag_path[0]}/blah and #{Chef::Config.data_bag_path[1]}/blah\n")
/data_bags/bag/
@@ -368,62 +383,74 @@ EOM
end
context 'when there is a directory in environments1 and file in environments2 with the same name' do
- directory 'environments/blah.json'
- file 'environments2/blah.json', {}
+ before do
+ directory 'environments/blah.json'
+ file 'environments2/blah.json', {}
+ end
it 'knife show /environments/blah.json succeeds' do
knife('show --local /environments/blah.json').should_succeed <<EOM
/environments/blah.json:
{
+
}
EOM
end
end
context 'when there is a directory in nodes1 and file in nodes2 with the same name' do
- directory 'nodes/blah.json'
- file 'nodes2/blah.json', {}
+ before do
+ directory 'nodes/blah.json'
+ file 'nodes2/blah.json', {}
+ end
it 'knife show /nodes/blah.json succeeds' do
knife('show --local /nodes/blah.json').should_succeed <<EOM
/nodes/blah.json:
{
+
}
EOM
end
end
context 'when there is a directory in roles1 and file in roles2 with the same name' do
- directory 'roles/blah.json'
- file 'roles2/blah.json', {}
+ before do
+ directory 'roles/blah.json'
+ file 'roles2/blah.json', {}
+ end
it 'knife show /roles/blah.json succeeds' do
knife('show --local /roles/blah.json').should_succeed <<EOM
/roles/blah.json:
{
+
}
EOM
end
end
context 'when there is a directory in users1 and file in users2 with the same name' do
- directory 'users/blah.json'
- file 'users2/blah.json', {}
+ before do
+ directory 'users/blah.json'
+ file 'users2/blah.json', {}
+ end
it 'knife show /users/blah.json succeeds' do
knife('show --local /users/blah.json').should_succeed <<EOM
/users/blah.json:
{
+
}
EOM
end
end
context 'when cwd is at the top level' do
- cwd '.'
+ before { cwd '.' }
it 'knife list --local -Rfp fails' do
knife('list --local -Rfp').should_fail("ERROR: Attempt to use relative path '' when current directory is outside the repository path\n")
end
end
context 'when cwd is inside the data_bags directory' do
- cwd 'data_bags'
+ before { cwd 'data_bags' }
it 'knife list --local -Rfp lists data bags' do
knife('list --local -Rfp').should_succeed <<EOM
bag/
@@ -435,7 +462,7 @@ EOM
end
context 'when cwd is inside chef_repo2' do
- cwd 'chef_repo2'
+ before { cwd 'chef_repo2' }
it 'knife list --local -Rfp lists everything' do
knife('list --local -Rfp').should_succeed <<EOM
clients/
@@ -468,7 +495,7 @@ EOM
end
context 'when cwd is inside data_bags2' do
- cwd 'data_bags2'
+ before { cwd 'data_bags2' }
it 'knife list --local -Rfp lists data bags' do
knife('list --local -Rfp').should_succeed <<EOM
bag/
@@ -492,7 +519,7 @@ EOM
end
context 'when cwd is at the top level' do
- cwd '.'
+ before { cwd '.' }
it 'knife list --local -Rfp lists everything' do
knife('list --local -Rfp').should_succeed <<EOM
clients/
@@ -525,7 +552,7 @@ EOM
end
context 'when cwd is inside the data_bags directory' do
- cwd 'data_bags'
+ before { cwd 'data_bags' }
it 'knife list --local -Rfp lists data bags' do
knife('list --local -Rfp').should_succeed <<EOM
bag/
@@ -537,7 +564,7 @@ EOM
end
context 'when cwd is inside chef_repo2' do
- cwd 'chef_repo2'
+ before { cwd 'chef_repo2' }
it 'knife list --local -Rfp lists everything' do
knife('list --local -Rfp').should_succeed <<EOM
clients/
@@ -570,7 +597,7 @@ EOM
end
context 'when cwd is inside chef_repo2/data_bags' do
- cwd 'chef_repo2/data_bags'
+ before { cwd 'chef_repo2/data_bags' }
it 'knife list --local -Rfp lists data bags' do
knife('list --local -Rfp').should_succeed <<EOM
bag/
@@ -592,21 +619,21 @@ EOM
end
context 'when cwd is at the top level' do
- cwd '.'
+ before { cwd '.' }
it 'knife list --local -Rfp fails' do
knife('list --local -Rfp').should_fail("ERROR: Attempt to use relative path '' when current directory is outside the repository path\n")
end
end
context 'when cwd is inside the data_bags directory' do
- cwd 'data_bags'
+ before { cwd 'data_bags' }
it 'knife list --local -Rfp fails' do
knife('list --local -Rfp').should_fail("ERROR: Attempt to use relative path '' when current directory is outside the repository path\n")
end
end
context 'when cwd is inside chef_repo2' do
- cwd 'chef_repo2'
+ before { cwd 'chef_repo2' }
it 'knife list --local -Rfp lists everything' do
knife('list --local -Rfp').should_succeed <<EOM
clients/
@@ -630,7 +657,7 @@ EOM
end
context 'when cwd is inside chef_repo2/data_bags' do
- cwd 'chef_repo2/data_bags'
+ before { cwd 'chef_repo2/data_bags' }
it 'knife list --local -Rfp lists data bags' do
knife('list --local -Rfp').should_succeed <<EOM
bag3/
@@ -653,7 +680,7 @@ EOM
end
context 'when cwd is at the top level' do
- cwd '.'
+ before { cwd '.' }
it 'knife list --local -Rfp lists everything' do
knife('list --local -Rfp').should_succeed <<EOM
clients/
@@ -686,7 +713,7 @@ EOM
end
context 'when cwd is inside the data_bags directory' do
- cwd 'data_bags'
+ before { cwd 'data_bags' }
it 'knife list --local -Rfp lists data bags' do
knife('list --local -Rfp').should_succeed <<EOM
bag/
@@ -698,7 +725,7 @@ EOM
end
context 'when cwd is inside chef_repo2' do
- cwd 'chef_repo2'
+ before { cwd 'chef_repo2' }
it 'knife list --local -Rfp lists everything' do
knife('list --local -Rfp').should_succeed <<EOM
clients/
@@ -731,7 +758,7 @@ EOM
end
context 'when cwd is inside chef_repo2/data_bags' do
- cwd 'chef_repo2/data_bags'
+ before { cwd 'chef_repo2/data_bags' }
it 'knife list --local -Rfp lists data bags' do
knife('list --local -Rfp').should_succeed <<EOM
bag/
@@ -753,14 +780,14 @@ EOM
end
context 'when cwd is at the top level' do
- cwd '.'
+ before { cwd '.' }
it 'knife list --local -Rfp fails' do
knife('list --local -Rfp').should_fail("ERROR: Attempt to use relative path '' when current directory is outside the repository path\n")
end
end
context 'when cwd is inside the data_bags directory' do
- cwd 'data_bags'
+ before { cwd 'data_bags' }
it 'knife list --local -Rfp lists data bags' do
knife('list --local -Rfp').should_succeed <<EOM
bag/
@@ -770,7 +797,7 @@ EOM
end
context 'when cwd is inside chef_repo2' do
- cwd 'chef_repo2'
+ before { cwd 'chef_repo2' }
it 'knife list --local -Rfp lists everything' do
knife('list --local -Rfp').should_succeed <<EOM
clients/
@@ -794,7 +821,7 @@ EOM
end
context 'when cwd is inside chef_repo2/data_bags' do
- cwd 'chef_repo2/data_bags'
+ before { cwd 'chef_repo2/data_bags' }
it 'knife list --local -Rfp fails' do
knife('list --local -Rfp').should_fail("ERROR: Attempt to use relative path '' when current directory is outside the repository path\n")
end
@@ -828,7 +855,7 @@ EOM
end
context 'when cwd is inside the data_bags directory' do
- cwd 'data_bags'
+ before { cwd 'data_bags' }
it 'knife list --local -Rfp lists data bags' do
knife('list --local -Rfp').should_succeed <<EOM
bag/
diff --git a/spec/integration/knife/chef_repository_file_system_spec.rb b/spec/integration/knife/chef_repository_file_system_spec.rb
index 68ca5f89f4..ff86924e22 100644
--- a/spec/integration/knife/chef_repository_file_system_spec.rb
+++ b/spec/integration/knife/chef_repository_file_system_spec.rb
@@ -20,14 +20,16 @@ require 'chef/knife/list'
require 'chef/knife/show'
describe 'General chef_repo file system checks' do
- extend IntegrationSupport
+ include IntegrationSupport
include KnifeSupport
context 'directories and files that should/should not be ignored' do
when_the_repository "has empty roles, environments and data bag item directories" do
- directory "roles"
- directory "environments"
- directory "data_bags/bag1"
+ before do
+ directory "roles"
+ directory "environments"
+ directory "data_bags/bag1"
+ end
it "knife list --local -Rfp / returns them" do
knife('list --local -Rfp /').should_succeed <<EOM
@@ -40,7 +42,7 @@ EOM
end
when_the_repository "has an empty data_bags directory" do
- directory "data_bags"
+ before { directory "data_bags" }
it "knife list --local / returns it" do
knife('list --local /').should_succeed "/data_bags\n"
@@ -48,7 +50,7 @@ EOM
end
when_the_repository "has an empty cookbook directory" do
- directory 'cookbooks/cookbook1'
+ before { directory 'cookbooks/cookbook1' }
it "knife list --local -Rfp / does not return it" do
knife('list --local -Rfp /').should_succeed(<<EOM, :stderr => "WARN: Cookbook 'cookbook1' is empty or entirely chefignored at #{Chef::Config.chef_repo_path}/cookbooks/cookbook1\n")
@@ -58,7 +60,7 @@ EOM
end
when_the_repository "has only empty cookbook subdirectories" do
- directory 'cookbooks/cookbook1/recipes'
+ before { directory 'cookbooks/cookbook1/recipes' }
it "knife list --local -Rfp / does not return it" do
knife('list --local -Rfp /').should_succeed(<<EOM, :stderr => "WARN: Cookbook 'cookbook1' is empty or entirely chefignored at #{Chef::Config.chef_repo_path}/cookbooks/cookbook1\n")
@@ -68,8 +70,10 @@ EOM
end
when_the_repository "has empty and non-empty cookbook subdirectories" do
- directory 'cookbooks/cookbook1/recipes'
- file 'cookbooks/cookbook1/templates/default/x.txt', ''
+ before do
+ directory 'cookbooks/cookbook1/recipes'
+ file 'cookbooks/cookbook1/templates/default/x.txt', ''
+ end
it "knife list --local -Rfp / does not return the empty ones" do
knife('list --local -Rfp /').should_succeed <<EOM
@@ -83,7 +87,7 @@ EOM
end
when_the_repository "has only empty cookbook sub-sub-directories" do
- directory 'cookbooks/cookbook1/templates/default'
+ before { directory 'cookbooks/cookbook1/templates/default' }
it "knife list --local -Rfp / does not return it" do
knife('list --local -Rfp /').should_succeed(<<EOM, :stderr => "WARN: Cookbook 'cookbook1' is empty or entirely chefignored at #{Chef::Config.chef_repo_path}/cookbooks/cookbook1\n")
@@ -93,9 +97,11 @@ EOM
end
when_the_repository "has empty cookbook sub-sub-directories alongside non-empty ones" do
- file 'cookbooks/cookbook1/templates/default/x.txt', ''
- directory 'cookbooks/cookbook1/templates/rhel'
- directory 'cookbooks/cookbook1/files/default'
+ before do
+ file 'cookbooks/cookbook1/templates/default/x.txt', ''
+ directory 'cookbooks/cookbook1/templates/rhel'
+ directory 'cookbooks/cookbook1/files/default'
+ end
it "knife list --local -Rfp / does not return the empty ones" do
knife('list --local -Rfp /').should_succeed <<EOM
@@ -109,8 +115,10 @@ EOM
end
when_the_repository "has an extra schmenvironments directory" do
- directory "schmenvironments" do
- file "_default.json", {}
+ before do
+ directory "schmenvironments" do
+ file "_default.json", {}
+ end
end
it "knife list --local -Rfp / should NOT return it" do
@@ -119,20 +127,22 @@ EOM
end
when_the_repository "has extra subdirectories and files under data bag items, roles, and environments" do
- directory "data_bags/bag1" do
- file "item1.json", {}
- file "item2.xml", ""
- file "another_subdir/item.json", {}
- end
- directory "roles" do
- file "role1.json", {}
- file "role2.xml", ""
- file "subdir/role.json", {}
- end
- directory "environments" do
- file "environment1.json", {}
- file "environment2.xml", ""
- file "subdir/environment.json", {}
+ before do
+ directory "data_bags/bag1" do
+ file "item1.json", {}
+ file "item2.xml", ""
+ file "another_subdir/item.json", {}
+ end
+ directory "roles" do
+ file "role1.json", {}
+ file "role2.xml", ""
+ file "subdir/role.json", {}
+ end
+ directory "environments" do
+ file "environment1.json", {}
+ file "environment2.xml", ""
+ file "subdir/environment.json", {}
+ end
end
it "knife list --local -Rfp / should NOT return them" do
@@ -149,56 +159,58 @@ EOM
end
when_the_repository "has extraneous subdirectories and files under a cookbook" do
- directory 'cookbooks/cookbook1' do
- file 'a.rb', ''
- file 'blarghle/blah.rb', ''
- directory 'attributes' do
- file 'a.rb', ''
- file 'b.json', {}
- file 'c/d.rb', ''
- file 'c/e.json', {}
- end
- directory 'definitions' do
- file 'a.rb', ''
- file 'b.json', {}
- file 'c/d.rb', ''
- file 'c/e.json', {}
- end
- directory 'recipes' do
+ before do
+ directory 'cookbooks/cookbook1' do
file 'a.rb', ''
- file 'b.json', {}
- file 'c/d.rb', ''
- file 'c/e.json', {}
- end
- directory 'libraries' do
- file 'a.rb', ''
- file 'b.json', {}
- file 'c/d.rb', ''
- file 'c/e.json', {}
- end
- directory 'templates' do
- file 'a.rb', ''
- file 'b.json', {}
- file 'c/d.rb', ''
- file 'c/e.json', {}
- end
- directory 'files' do
- file 'a.rb', ''
- file 'b.json', {}
- file 'c/d.rb', ''
- file 'c/e.json', {}
- end
- directory 'resources' do
- file 'a.rb', ''
- file 'b.json', {}
- file 'c/d.rb', ''
- file 'c/e.json', {}
- end
- directory 'providers' do
- file 'a.rb', ''
- file 'b.json', {}
- file 'c/d.rb', ''
- file 'c/e.json', {}
+ file 'blarghle/blah.rb', ''
+ directory 'attributes' do
+ file 'a.rb', ''
+ file 'b.json', {}
+ file 'c/d.rb', ''
+ file 'c/e.json', {}
+ end
+ directory 'definitions' do
+ file 'a.rb', ''
+ file 'b.json', {}
+ file 'c/d.rb', ''
+ file 'c/e.json', {}
+ end
+ directory 'recipes' do
+ file 'a.rb', ''
+ file 'b.json', {}
+ file 'c/d.rb', ''
+ file 'c/e.json', {}
+ end
+ directory 'libraries' do
+ file 'a.rb', ''
+ file 'b.json', {}
+ file 'c/d.rb', ''
+ file 'c/e.json', {}
+ end
+ directory 'templates' do
+ file 'a.rb', ''
+ file 'b.json', {}
+ file 'c/d.rb', ''
+ file 'c/e.json', {}
+ end
+ directory 'files' do
+ file 'a.rb', ''
+ file 'b.json', {}
+ file 'c/d.rb', ''
+ file 'c/e.json', {}
+ end
+ directory 'resources' do
+ file 'a.rb', ''
+ file 'b.json', {}
+ file 'c/d.rb', ''
+ file 'c/e.json', {}
+ end
+ directory 'providers' do
+ file 'a.rb', ''
+ file 'b.json', {}
+ file 'c/d.rb', ''
+ file 'c/e.json', {}
+ end
end
end
@@ -240,7 +252,7 @@ EOM
end
when_the_repository "has a file in cookbooks/" do
- file 'cookbooks/file', ''
+ before { file 'cookbooks/file', '' }
it 'does not show up in list -Rfp' do
knife('list --local -Rfp /').should_succeed <<EOM
/cookbooks/
@@ -249,7 +261,7 @@ EOM
end
when_the_repository "has a file in data_bags/" do
- file 'data_bags/file', ''
+ before { file 'data_bags/file', '' }
it 'does not show up in list -Rfp' do
knife('list --local -Rfp /').should_succeed <<EOM
/data_bags/
@@ -259,16 +271,20 @@ EOM
end
when_the_repository 'has a cookbook starting with .' do
- file 'cookbooks/.svn/metadata.rb', ''
- file 'cookbooks/a.b/metadata.rb', ''
+ before do
+ file 'cookbooks/.svn/metadata.rb', ''
+ file 'cookbooks/a.b/metadata.rb', ''
+ end
it 'knife list does not show it' do
knife('list --local -fp /cookbooks').should_succeed "/cookbooks/a.b/\n"
end
end
when_the_repository 'has a data bag starting with .' do
- file 'data_bags/.svn/x.json', {}
- file 'data_bags/a.b/x.json', {}
+ before do
+ file 'data_bags/.svn/x.json', {}
+ file 'data_bags/a.b/x.json', {}
+ end
it 'knife list does not show it' do
knife('list --local -fp /data_bags').should_succeed "/data_bags/a.b/\n"
end
diff --git a/spec/integration/knife/chefignore_spec.rb b/spec/integration/knife/chefignore_spec.rb
index 4c3d2fa3aa..b09959b581 100644
--- a/spec/integration/knife/chefignore_spec.rb
+++ b/spec/integration/knife/chefignore_spec.rb
@@ -20,23 +20,27 @@ require 'chef/knife/list'
require 'chef/knife/show'
describe 'chefignore tests' do
- extend IntegrationSupport
+ include IntegrationSupport
include KnifeSupport
when_the_repository "has lots of stuff in it" do
- file 'roles/x.json', {}
- file 'environments/x.json', {}
- file 'data_bags/bag1/x.json', {}
- file 'cookbooks/cookbook1/x.json', {}
+ before do
+ file 'roles/x.json', {}
+ file 'environments/x.json', {}
+ file 'data_bags/bag1/x.json', {}
+ file 'cookbooks/cookbook1/x.json', {}
+ end
context "and has a chefignore everywhere except cookbooks" do
- chefignore = "x.json\nroles/x.json\nenvironments/x.json\ndata_bags/bag1/x.json\nbag1/x.json\ncookbooks/cookbook1/x.json\ncookbook1/x.json\n"
- file 'chefignore', chefignore
- file 'roles/chefignore', chefignore
- file 'environments/chefignore', chefignore
- file 'data_bags/chefignore', chefignore
- file 'data_bags/bag1/chefignore', chefignore
- file 'cookbooks/cookbook1/chefignore', chefignore
+ before do
+ chefignore = "x.json\nroles/x.json\nenvironments/x.json\ndata_bags/bag1/x.json\nbag1/x.json\ncookbooks/cookbook1/x.json\ncookbook1/x.json\n"
+ file 'chefignore', chefignore
+ file 'roles/chefignore', chefignore
+ file 'environments/chefignore', chefignore
+ file 'data_bags/chefignore', chefignore
+ file 'data_bags/bag1/chefignore', chefignore
+ file 'cookbooks/cookbook1/chefignore', chefignore
+ end
it 'matching files and directories get ignored' do
# NOTE: many of the "chefignore" files should probably not show up
@@ -58,9 +62,11 @@ EOM
end
when_the_repository 'has a cookbook with only chefignored files' do
- file 'cookbooks/cookbook1/templates/default/x.rb', ''
- file 'cookbooks/cookbook1/libraries/x.rb', ''
- file 'cookbooks/chefignore', "libraries/x.rb\ntemplates/default/x.rb\n"
+ before do
+ file 'cookbooks/cookbook1/templates/default/x.rb', ''
+ file 'cookbooks/cookbook1/libraries/x.rb', ''
+ file 'cookbooks/chefignore', "libraries/x.rb\ntemplates/default/x.rb\n"
+ end
it 'the cookbook is not listed' do
knife('list --local -Rfp /').should_succeed(<<EOM, :stderr => "WARN: Cookbook 'cookbook1' is empty or entirely chefignored at #{Chef::Config.chef_repo_path}/cookbooks/cookbook1\n")
@@ -70,13 +76,15 @@ EOM
end
when_the_repository "has multiple cookbooks" do
- file 'cookbooks/cookbook1/x.json', {}
- file 'cookbooks/cookbook1/y.json', {}
- file 'cookbooks/cookbook2/x.json', {}
- file 'cookbooks/cookbook2/y.json', {}
+ before do
+ file 'cookbooks/cookbook1/x.json', {}
+ file 'cookbooks/cookbook1/y.json', {}
+ file 'cookbooks/cookbook2/x.json', {}
+ file 'cookbooks/cookbook2/y.json', {}
+ end
context 'and has a chefignore with filenames' do
- file 'cookbooks/chefignore', "x.json\n"
+ before { file 'cookbooks/chefignore', "x.json\n" }
it 'matching files and directories get ignored in all cookbooks' do
knife('list --local -Rfp /').should_succeed <<EOM
@@ -90,8 +98,10 @@ EOM
end
context "and has a chefignore with wildcards" do
- file 'cookbooks/chefignore', "x.*\n"
- file 'cookbooks/cookbook1/x.rb', ''
+ before do
+ file 'cookbooks/chefignore', "x.*\n"
+ file 'cookbooks/cookbook1/x.rb', ''
+ end
it 'matching files and directories get ignored in all cookbooks' do
knife('list --local -Rfp /').should_succeed <<EOM
@@ -105,9 +115,11 @@ EOM
end
context "and has a chefignore with relative paths" do
- file 'cookbooks/cookbook1/recipes/x.rb', ''
- file 'cookbooks/cookbook2/recipes/y.rb', ''
- file 'cookbooks/chefignore', "recipes/x.rb\n"
+ before do
+ file 'cookbooks/cookbook1/recipes/x.rb', ''
+ file 'cookbooks/cookbook2/recipes/y.rb', ''
+ file 'cookbooks/chefignore', "recipes/x.rb\n"
+ end
it 'matching directories get ignored' do
knife('list --local -Rfp /').should_succeed <<EOM
@@ -125,8 +137,10 @@ EOM
end
context "and has a chefignore with subdirectories" do
- file 'cookbooks/cookbook1/recipes/y.rb', ''
- file 'cookbooks/chefignore', "recipes\nrecipes/\n"
+ before do
+ file 'cookbooks/cookbook1/recipes/y.rb', ''
+ file 'cookbooks/chefignore', "recipes\nrecipes/\n"
+ end
it 'matching directories do NOT get ignored' do
knife('list --local -Rfp /').should_succeed <<EOM
@@ -144,9 +158,11 @@ EOM
end
context "and has a chefignore that ignores all files in a subdirectory" do
- file 'cookbooks/cookbook1/templates/default/x.rb', ''
- file 'cookbooks/cookbook1/libraries/x.rb', ''
- file 'cookbooks/chefignore', "libraries/x.rb\ntemplates/default/x.rb\n"
+ before do
+ file 'cookbooks/cookbook1/templates/default/x.rb', ''
+ file 'cookbooks/cookbook1/libraries/x.rb', ''
+ file 'cookbooks/chefignore', "libraries/x.rb\ntemplates/default/x.rb\n"
+ end
it 'ignores the subdirectory entirely' do
knife('list --local -Rfp /').should_succeed <<EOM
@@ -162,7 +178,9 @@ EOM
end
context "and has an empty chefignore" do
- file 'cookbooks/chefignore', "\n"
+ before do
+ file 'cookbooks/chefignore', "\n"
+ end
it 'nothing is ignored' do
knife('list --local -Rfp /').should_succeed <<EOM
@@ -178,7 +196,9 @@ EOM
end
context "and has a chefignore with comments and empty lines" do
- file 'cookbooks/chefignore', "\n\n # blah\n#\nx.json\n\n"
+ before do
+ file 'cookbooks/chefignore', "\n\n # blah\n#\nx.json\n\n"
+ end
it 'matching files and directories get ignored in all cookbooks' do
knife('list --local -Rfp /').should_succeed <<EOM
@@ -200,14 +220,18 @@ EOM
]
end
- file 'cookbooks1/mycookbook/metadata.rb', ''
- file 'cookbooks1/mycookbook/x.json', {}
- file 'cookbooks2/yourcookbook/metadata.rb', ''
- file 'cookbooks2/yourcookbook/x.json', ''
+ before do
+ file 'cookbooks1/mycookbook/metadata.rb', ''
+ file 'cookbooks1/mycookbook/x.json', {}
+ file 'cookbooks2/yourcookbook/metadata.rb', ''
+ file 'cookbooks2/yourcookbook/x.json', ''
+ end
context "and multiple chefignores" do
- file 'cookbooks1/chefignore', "metadata.rb\n"
- file 'cookbooks2/chefignore', "x.json\n"
+ before do
+ file 'cookbooks1/chefignore', "metadata.rb\n"
+ file 'cookbooks2/chefignore', "x.json\n"
+ end
it "chefignores apply only to the directories they are in" do
knife('list --local -Rfp /').should_succeed <<EOM
/cookbooks/
@@ -219,10 +243,12 @@ EOM
end
context "and conflicting cookbooks" do
- file 'cookbooks1/yourcookbook/metadata.rb', ''
- file 'cookbooks1/yourcookbook/x.json', ''
- file 'cookbooks1/yourcookbook/onlyincookbooks1.rb', ''
- file 'cookbooks2/yourcookbook/onlyincookbooks2.rb', ''
+ before do
+ file 'cookbooks1/yourcookbook/metadata.rb', ''
+ file 'cookbooks1/yourcookbook/x.json', ''
+ file 'cookbooks1/yourcookbook/onlyincookbooks1.rb', ''
+ file 'cookbooks2/yourcookbook/onlyincookbooks2.rb', ''
+ end
it "chefignores apply only to the winning cookbook" do
knife('list --local -Rfp /').should_succeed(<<EOM, :stderr => "WARN: Child with name 'yourcookbook' found in multiple directories: #{Chef::Config.chef_repo_path}/cookbooks1/yourcookbook and #{Chef::Config.chef_repo_path}/cookbooks2/yourcookbook\n")
@@ -239,7 +265,9 @@ EOM
end
when_the_repository 'has a cookbook named chefignore' do
- file 'cookbooks/chefignore/metadata.rb', {}
+ before do
+ file 'cookbooks/chefignore/metadata.rb', {}
+ end
it 'knife list -Rfp /cookbooks shows it' do
knife('list --local -Rfp /cookbooks').should_succeed <<EOM
/cookbooks/chefignore/
@@ -249,9 +277,11 @@ EOM
end
when_the_repository 'has multiple cookbook paths, one with a chefignore file and the other with a cookbook named chefignore' do
- file 'cookbooks1/chefignore', ''
- file 'cookbooks1/blah/metadata.rb', ''
- file 'cookbooks2/chefignore/metadata.rb', ''
+ before do
+ file 'cookbooks1/chefignore', ''
+ file 'cookbooks1/blah/metadata.rb', ''
+ file 'cookbooks2/chefignore/metadata.rb', ''
+ end
before :each do
Chef::Config.cookbook_path = [
File.join(Chef::Config.chef_repo_path, 'cookbooks1'),
diff --git a/spec/integration/knife/common_options_spec.rb b/spec/integration/knife/common_options_spec.rb
index 9127edc6b5..7a48f14ad3 100644
--- a/spec/integration/knife/common_options_spec.rb
+++ b/spec/integration/knife/common_options_spec.rb
@@ -19,18 +19,11 @@ require 'support/shared/integration/integration_helper'
require 'chef/knife/raw'
describe 'knife common options' do
- extend IntegrationSupport
+ include IntegrationSupport
include KnifeSupport
when_the_repository "has a node" do
- file 'nodes/x.json', {}
-
- before(:each) do
- if ChefZero::RSpec.server
- ChefZero::RSpec.server.stop
- ChefZero::RSpec.server = nil
- end
- end
+ before { file 'nodes/x.json', {} }
context 'When chef_zero.enabled is true' do
before(:each) do
@@ -38,14 +31,14 @@ describe 'knife common options' do
end
it 'knife raw /nodes/x should retrieve the node' do
- knife('raw /nodes/x').should_succeed /"name": "x"/
+ knife('raw /nodes/x').should_succeed( /"name": "x"/ )
end
context 'And chef_zero.port is 9999' do
before(:each) { Chef::Config.chef_zero.port = 9999 }
it 'knife raw /nodes/x should retrieve the node' do
- knife('raw /nodes/x').should_succeed /"name": "x"/
+ knife('raw /nodes/x').should_succeed( /"name": "x"/ )
Chef::Config.chef_server_url.should == 'http://localhost:9999'
end
end
@@ -55,12 +48,13 @@ describe 'knife common options' do
before(:each) { Chef::Config.chef_zero.host = '0.0.0.0' }
it 'knife raw /nodes/x should retrieve the role' do
- knife('raw /nodes/x').should_succeed /"name": "x"/
+ knife('raw /nodes/x').should_succeed( /"name": "x"/ )
end
end
context 'and there is a private key' do
- file 'mykey.pem', <<EOM
+ before do
+ file 'mykey.pem', <<EOM
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEApubutqtYYQ5UiA9QhWP7UvSmsfHsAoPKEVVPdVW/e8Svwpyf
0Xef6OFWVmBE+W442ZjLOe2y6p2nSnaq4y7dg99NFz6X+16mcKiCbj0RCiGqCvCk
@@ -89,23 +83,24 @@ syHLXYFNy0OxMtH/bBAXBGNHd9gf5uOnqh0pYcbe/uRAxumC7Rl0cL509eURiA2T
+vFmf54y9YdnLXaqv+FhJT6B6V7WX7IpU9BMqJY1cJYXHuHG2KA=
-----END RSA PRIVATE KEY-----
EOM
+ end
it 'knife raw /nodes/x should retrieve the node' do
- knife('raw /nodes/x').should_succeed /"name": "x"/
+ knife('raw /nodes/x').should_succeed( /"name": "x"/ )
end
end
end
it 'knife raw -z /nodes/x retrieves the node' do
- knife('raw -z /nodes/x').should_succeed /"name": "x"/
+ knife('raw -z /nodes/x').should_succeed( /"name": "x"/ )
end
it 'knife raw --local-mode /nodes/x retrieves the node' do
- knife('raw --local-mode /nodes/x').should_succeed /"name": "x"/
+ knife('raw --local-mode /nodes/x').should_succeed( /"name": "x"/ )
end
it 'knife raw -z --chef-zero-port=9999 /nodes/x retrieves the node' do
- knife('raw -z --chef-zero-port=9999 /nodes/x').should_succeed /"name": "x"/
+ knife('raw -z --chef-zero-port=9999 /nodes/x').should_succeed( /"name": "x"/ )
Chef::Config.chef_server_url.should == 'http://localhost:9999'
end
@@ -123,7 +118,7 @@ EOM
end
it 'knife raw -z /nodes/x retrieves the node' do
- knife('raw -z /nodes/x').should_succeed /"name": "x"/
+ knife('raw -z /nodes/x').should_succeed( /"name": "x"/ )
expect(URI(Chef::Config.chef_server_url).port).to be > 8889
end
end
@@ -142,18 +137,18 @@ EOM
end
it 'knife raw -z --chef-zero-port=9999-20000 /nodes/x' do
- knife('raw -z --chef-zero-port=9999-20000 /nodes/x').should_succeed /"name": "x"/
+ knife('raw -z --chef-zero-port=9999-20000 /nodes/x').should_succeed( /"name": "x"/ )
expect(URI(Chef::Config.chef_server_url).port).to be > 9999
end
it 'knife raw -z --chef-zero-port=9999-9999,19423' do
- knife('raw -z --chef-zero-port=9999-9999,19423 /nodes/x').should_succeed /"name": "x"/
+ knife('raw -z --chef-zero-port=9999-9999,19423 /nodes/x').should_succeed( /"name": "x"/ )
expect(URI(Chef::Config.chef_server_url).port).to be == 19423
end
end
it 'knife raw -z --chef-zero-port=9999 /nodes/x retrieves the node' do
- knife('raw -z --chef-zero-port=9999 /nodes/x').should_succeed /"name": "x"/
+ knife('raw -z --chef-zero-port=9999 /nodes/x').should_succeed( /"name": "x"/ )
Chef::Config.chef_server_url.should == 'http://localhost:9999'
end
end
diff --git a/spec/integration/knife/cookbook_api_ipv6_spec.rb b/spec/integration/knife/cookbook_api_ipv6_spec.rb
index ad7d5e857f..ac2538dc38 100644
--- a/spec/integration/knife/cookbook_api_ipv6_spec.rb
+++ b/spec/integration/knife/cookbook_api_ipv6_spec.rb
@@ -19,7 +19,7 @@ require 'support/shared/integration/integration_helper'
require 'chef/mixin/shell_out'
describe "Knife cookbook API integration with IPv6" do
- extend IntegrationSupport
+ include IntegrationSupport
include Chef::Mixin::ShellOut
when_the_chef_server "is bound to IPv6" do
@@ -100,7 +100,7 @@ END_CLIENT_RB
end
it "downloads the cookbook" do
- s = shell_out!("knife cookbook download apache2 #{knife_config_flag} -d #{cache_path}", :cwd => chef_dir)
+ shell_out!("knife cookbook download apache2 #{knife_config_flag} -d #{cache_path}", :cwd => chef_dir)
Dir["#{cache_path}/*"].map {|entry| File.basename(entry)}.should include("apache2-0.0.0")
end
end
diff --git a/spec/integration/knife/delete_spec.rb b/spec/integration/knife/delete_spec.rb
index 8d9b972ca4..efbfa1004b 100644
--- a/spec/integration/knife/delete_spec.rb
+++ b/spec/integration/knife/delete_spec.rb
@@ -21,7 +21,7 @@ require 'chef/knife/list'
require 'chef/knife/raw'
describe 'knife delete' do
- extend IntegrationSupport
+ include IntegrationSupport
include KnifeSupport
let :everything do
@@ -99,23 +99,27 @@ EOM
end
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 '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', {}
+ 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 <<EOM
@@ -216,8 +220,11 @@ EOM
# TODO delete empty data bag (particularly different on local side)
context 'with an empty data bag on both' do
- data_bag 'empty', {}
- directory 'data_bags/empty'
+ before do
+ data_bag 'empty', {}
+ directory 'data_bags/empty'
+ end
+
it 'knife delete --both /data_bags/empty fails but deletes local version' do
knife('delete --both /data_bags/empty').should_fail <<EOM
ERROR: /data_bags/empty (remote) must be deleted recursively! Pass -r to knife delete.
@@ -468,13 +475,15 @@ EOM
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 delete --both /cookbooks/x fails' do
knife('delete --both /cookbooks/x').should_fail "ERROR: /cookbooks/x (remote) must be deleted recursively! Pass -r to knife delete.\n"
@@ -632,7 +641,7 @@ EOM
end
context 'and cwd is at the top level' do
- cwd '.'
+ before { cwd '.' }
it 'knife delete fails' do
knife('delete').should_fail "FATAL: Must specify at least one argument. If you want to delete everything in this directory, type \"knife delete --recurse .\"\n", :stdout => /USAGE/
knife('list -Rf /').should_succeed <<EOM
@@ -673,14 +682,16 @@ EOM
when_the_chef_server 'is empty' do
when_the_repository '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', {}
+ 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: /cookbooks/x (local) must be deleted recursively! Pass -r to knife delete.\n"
@@ -843,7 +854,7 @@ EOM
end
context 'and cwd is at the top level' do
- cwd '.'
+ before { cwd '.' }
it 'knife delete fails' do
knife('delete').should_fail "FATAL: Must specify at least one argument. If you want to delete everything in this directory, type \"knife delete --recurse .\"\n", :stdout => /USAGE/
knife('list -Rf /').should_succeed <<EOM
@@ -884,12 +895,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', 'version "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
# TODO this seems wrong
it 'knife delete --both -r /cookbooks/x deletes the latest version on the server and the local version' do
@@ -900,8 +915,10 @@ 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 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"
@@ -911,7 +928,7 @@ 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 { 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"
@@ -921,7 +938,7 @@ 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 { 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"
@@ -933,11 +950,14 @@ EOM
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"' }
+ 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/
+ knife('raw /cookbooks/x').should_succeed( /2.0.11/ )
end
end
end
diff --git a/spec/integration/knife/deps_spec.rb b/spec/integration/knife/deps_spec.rb
index 7f434f844d..7ee6138739 100644
--- a/spec/integration/knife/deps_spec.rb
+++ b/spec/integration/knife/deps_spec.rb
@@ -20,24 +20,26 @@ require 'support/shared/context/config'
require 'chef/knife/deps'
describe 'knife deps' do
- extend IntegrationSupport
+ include IntegrationSupport
include KnifeSupport
context 'local' do
when_the_repository 'has a role with no run_list' do
- file 'roles/starring.json', {}
+ before { file 'roles/starring.json', {} }
it 'knife deps reports no dependencies' do
knife('deps /roles/starring.json').should_succeed "/roles/starring.json\n"
end
end
when_the_repository 'has a role with a default run_list' do
- file 'roles/starring.json', { 'run_list' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) }
- file 'roles/minor.json', {}
- file 'cookbooks/quiche/metadata.rb', 'name "quiche"'
- file 'cookbooks/quiche/recipes/default.rb', ''
- file 'cookbooks/soup/metadata.rb', 'name "soup"'
- file 'cookbooks/soup/recipes/chicken.rb', ''
+ before do
+ file 'roles/starring.json', { 'run_list' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) }
+ file 'roles/minor.json', {}
+ file 'cookbooks/quiche/metadata.rb', 'name "quiche"'
+ file 'cookbooks/quiche/recipes/default.rb', ''
+ file 'cookbooks/soup/metadata.rb', 'name "soup"'
+ file 'cookbooks/soup/recipes/chicken.rb', ''
+ end
it 'knife deps reports all dependencies' do
knife('deps /roles/starring.json').should_succeed <<EOM
/roles/minor.json
@@ -49,12 +51,14 @@ EOM
end
when_the_repository 'has a role with an env_run_list' do
- file 'roles/starring.json', { 'env_run_lists' => { 'desert' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) } }
- file 'roles/minor.json', {}
- file 'cookbooks/quiche/metadata.rb', 'name "quiche"'
- file 'cookbooks/quiche/recipes/default.rb', ''
- file 'cookbooks/soup/metadata.rb', 'name "soup"'
- file 'cookbooks/soup/recipes/chicken.rb', ''
+ before do
+ file 'roles/starring.json', { 'env_run_lists' => { 'desert' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) } }
+ file 'roles/minor.json', {}
+ file 'cookbooks/quiche/metadata.rb', 'name "quiche"'
+ file 'cookbooks/quiche/recipes/default.rb', ''
+ file 'cookbooks/soup/metadata.rb', 'name "soup"'
+ file 'cookbooks/soup/recipes/chicken.rb', ''
+ end
it 'knife deps reports all dependencies' do
knife('deps /roles/starring.json').should_succeed <<EOM
/roles/minor.json
@@ -66,25 +70,29 @@ EOM
end
when_the_repository 'has a node with no environment or run_list' do
- file 'nodes/mort.json', {}
+ before { file 'nodes/mort.json', {} }
it 'knife deps reports just the node' do
knife('deps /nodes/mort.json').should_succeed "/nodes/mort.json\n"
end
end
when_the_repository 'has a node with an environment' do
- file 'environments/desert.json', {}
- file 'nodes/mort.json', { 'chef_environment' => 'desert' }
+ before do
+ file 'environments/desert.json', {}
+ file 'nodes/mort.json', { 'chef_environment' => 'desert' }
+ end
it 'knife deps reports just the node' do
knife('deps /nodes/mort.json').should_succeed "/environments/desert.json\n/nodes/mort.json\n"
end
end
when_the_repository 'has a node with roles and recipes in its run_list' do
- file 'roles/minor.json', {}
- file 'cookbooks/quiche/metadata.rb', 'name "quiche"'
- file 'cookbooks/quiche/recipes/default.rb', ''
- file 'cookbooks/soup/metadata.rb', 'name "soup"'
- file 'cookbooks/soup/recipes/chicken.rb', ''
- file 'nodes/mort.json', { 'run_list' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) }
+ before do
+ file 'roles/minor.json', {}
+ file 'cookbooks/quiche/metadata.rb', 'name "quiche"'
+ file 'cookbooks/quiche/recipes/default.rb', ''
+ file 'cookbooks/soup/metadata.rb', 'name "soup"'
+ file 'cookbooks/soup/recipes/chicken.rb', ''
+ file 'nodes/mort.json', { 'run_list' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) }
+ end
it 'knife deps reports just the node' do
knife('deps /nodes/mort.json').should_succeed <<EOM
/roles/minor.json
@@ -95,42 +103,48 @@ EOM
end
end
when_the_repository 'has a cookbook with no dependencies' do
- file 'cookbooks/quiche/metadata.rb', 'name "quiche"'
- file 'cookbooks/quiche/recipes/default.rb', ''
+ before do
+ file 'cookbooks/quiche/metadata.rb', 'name "quiche"'
+ file 'cookbooks/quiche/recipes/default.rb', ''
+ end
it 'knife deps reports just the cookbook' do
knife('deps /cookbooks/quiche').should_succeed "/cookbooks/quiche\n"
end
end
when_the_repository 'has a cookbook with dependencies' do
- file 'cookbooks/kettle/metadata.rb', 'name "kettle"'
- file 'cookbooks/quiche/metadata.rb', "name 'quiche'\ndepends 'kettle'\n"
- file 'cookbooks/quiche/recipes/default.rb', ''
+ before do
+ file 'cookbooks/kettle/metadata.rb', 'name "kettle"'
+ file 'cookbooks/quiche/metadata.rb', "name 'quiche'\ndepends 'kettle'\n"
+ file 'cookbooks/quiche/recipes/default.rb', ''
+ end
it 'knife deps reports just the cookbook' do
knife('deps /cookbooks/quiche').should_succeed "/cookbooks/kettle\n/cookbooks/quiche\n"
end
end
when_the_repository 'has a data bag' do
- file 'data_bags/bag/item.json', {}
+ before { file 'data_bags/bag/item.json', {} }
it 'knife deps reports just the data bag' do
knife('deps /data_bags/bag/item.json').should_succeed "/data_bags/bag/item.json\n"
end
end
when_the_repository 'has an environment' do
- file 'environments/desert.json', {}
+ before { file 'environments/desert.json', {} }
it 'knife deps reports just the environment' do
knife('deps /environments/desert.json').should_succeed "/environments/desert.json\n"
end
end
when_the_repository 'has a deep dependency tree' do
- file 'roles/starring.json', { 'run_list' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) }
- file 'roles/minor.json', {}
- file 'cookbooks/quiche/metadata.rb', 'name "quiche"'
- file 'cookbooks/quiche/recipes/default.rb', ''
- file 'cookbooks/soup/metadata.rb', 'name "soup"'
- file 'cookbooks/soup/recipes/chicken.rb', ''
- file 'environments/desert.json', {}
- file 'nodes/mort.json', { 'chef_environment' => 'desert', 'run_list' => [ 'role[starring]' ] }
- file 'nodes/bart.json', { 'run_list' => [ 'role[minor]' ] }
+ before do
+ file 'roles/starring.json', { 'run_list' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) }
+ file 'roles/minor.json', {}
+ file 'cookbooks/quiche/metadata.rb', 'name "quiche"'
+ file 'cookbooks/quiche/recipes/default.rb', ''
+ file 'cookbooks/soup/metadata.rb', 'name "soup"'
+ file 'cookbooks/soup/recipes/chicken.rb', ''
+ file 'environments/desert.json', {}
+ file 'nodes/mort.json', { 'chef_environment' => 'desert', 'run_list' => [ 'role[starring]' ] }
+ file 'nodes/bart.json', { 'run_list' => [ 'role[minor]' ] }
+ end
it 'knife deps reports all dependencies' do
knife('deps /nodes/mort.json').should_succeed <<EOM
@@ -189,10 +203,13 @@ EOM
context 'circular dependencies' do
when_the_repository 'has cookbooks with circular dependencies' do
- file 'cookbooks/foo/metadata.rb', "name 'foo'\ndepends 'bar'\n"
- file 'cookbooks/bar/metadata.rb', "name 'bar'\ndepends 'baz'\n"
- file 'cookbooks/baz/metadata.rb', "name 'baz'\ndepends 'foo'\n"
- file 'cookbooks/self/metadata.rb', "name 'self'\ndepends 'self'\n"
+ before do
+ file 'cookbooks/foo/metadata.rb', "name 'foo'\ndepends 'bar'\n"
+ file 'cookbooks/bar/metadata.rb', "name 'bar'\ndepends 'baz'\n"
+ file 'cookbooks/baz/metadata.rb', "name 'baz'\ndepends 'foo'\n"
+ file 'cookbooks/self/metadata.rb', "name 'self'\ndepends 'self'\n"
+ end
+
it 'knife deps prints each once' do
knife('deps /cookbooks/foo /cookbooks/self').should_succeed <<EOM
/cookbooks/baz
@@ -213,10 +230,12 @@ EOM
end
end
when_the_repository 'has roles with circular dependencies' do
- file 'roles/foo.json', { 'run_list' => [ 'role[bar]' ] }
- file 'roles/bar.json', { 'run_list' => [ 'role[baz]' ] }
- file 'roles/baz.json', { 'run_list' => [ 'role[foo]' ] }
- file 'roles/self.json', { 'run_list' => [ 'role[self]' ] }
+ before do
+ file 'roles/foo.json', { 'run_list' => [ 'role[bar]' ] }
+ file 'roles/bar.json', { 'run_list' => [ 'role[baz]' ] }
+ file 'roles/baz.json', { 'run_list' => [ 'role[foo]' ] }
+ file 'roles/self.json', { 'run_list' => [ 'role[self]' ] }
+ end
it 'knife deps prints each once' do
knife('deps /roles/foo.json /roles/self.json').should_succeed <<EOM
/roles/baz.json
@@ -280,7 +299,9 @@ EOM
end
end
when_the_repository 'is missing a dependent cookbook' do
- file 'roles/starring.json', { 'run_list' => [ 'recipe[quiche]'] }
+ before do
+ file 'roles/starring.json', { 'run_list' => [ 'recipe[quiche]'] }
+ end
it 'knife deps reports the cookbook, along with an error' do
knife('deps /roles/starring.json').should_fail(
:exit_code => 2,
@@ -290,7 +311,9 @@ EOM
end
end
when_the_repository 'is missing a dependent environment' do
- file 'nodes/mort.json', { 'chef_environment' => 'desert' }
+ before do
+ file 'nodes/mort.json', { 'chef_environment' => 'desert' }
+ end
it 'knife deps reports the environment, along with an error' do
knife('deps /nodes/mort.json').should_fail(
:exit_code => 2,
@@ -300,7 +323,9 @@ EOM
end
end
when_the_repository 'is missing a dependent role' do
- file 'roles/starring.json', { 'run_list' => [ 'role[minor]'] }
+ before do
+ file 'roles/starring.json', { 'run_list' => [ 'role[minor]'] }
+ end
it 'knife deps reports the role, along with an error' do
knife('deps /roles/starring.json').should_fail(
:exit_code => 2,
@@ -324,13 +349,13 @@ EOM
end
end
when_the_repository 'has a data bag' do
- file 'data_bags/bag/item.json', ''
+ before { file 'data_bags/bag/item.json', '' }
it 'knife deps /data_bags/bag shows no dependencies' do
knife('deps /data_bags/bag').should_succeed("/data_bags/bag\n")
end
end
when_the_repository 'has a cookbook' do
- file 'cookbooks/blah/metadata.rb', 'name "blah"'
+ before { file 'cookbooks/blah/metadata.rb', 'name "blah"' }
it 'knife deps on a cookbook file shows no dependencies' do
knife('deps /cookbooks/blah/metadata.rb').should_succeed(
"/cookbooks/blah/metadata.rb\n"
@@ -342,19 +367,21 @@ EOM
context 'remote' do
include_context "default config options"
-
+
when_the_chef_server 'has a role with no run_list' do
- role 'starring', {}
+ before { role 'starring', {} }
it 'knife deps reports no dependencies' do
knife('deps --remote /roles/starring.json').should_succeed "/roles/starring.json\n"
end
end
when_the_chef_server 'has a role with a default run_list' do
- role 'starring', { 'run_list' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) }
- role 'minor', {}
- cookbook 'quiche', '1.0.0', { 'metadata.rb' => "name 'quiche'\nversion '1.0.0'\n", 'recipes' => { 'default.rb' => '' } }
- cookbook 'soup', '1.0.0', { 'metadata.rb' => "name 'soup'\nversion '1.0.0'\n", 'recipes' => { 'chicken.rb' => '' } }
+ before do
+ role 'starring', { 'run_list' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) }
+ role 'minor', {}
+ cookbook 'quiche', '1.0.0', { 'metadata.rb' => "name 'quiche'\nversion '1.0.0'\n", 'recipes' => { 'default.rb' => '' } }
+ cookbook 'soup', '1.0.0', { 'metadata.rb' => "name 'soup'\nversion '1.0.0'\n", 'recipes' => { 'chicken.rb' => '' } }
+ end
it 'knife deps reports all dependencies' do
knife('deps --remote /roles/starring.json').should_succeed <<EOM
/roles/minor.json
@@ -366,10 +393,12 @@ EOM
end
when_the_chef_server 'has a role with an env_run_list' do
- role 'starring', { 'env_run_lists' => { 'desert' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) } }
- role 'minor', {}
- cookbook 'quiche', '1.0.0', { 'metadata.rb' => "name 'quiche'\nversion '1.0.0'\n", 'recipes' => { 'default.rb' => '' } }
- cookbook 'soup', '1.0.0', { 'metadata.rb' => "name 'soup'\nversion '1.0.0'\n", 'recipes' => { 'chicken.rb' => '' } }
+ before do
+ role 'starring', { 'env_run_lists' => { 'desert' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) } }
+ role 'minor', {}
+ cookbook 'quiche', '1.0.0', { 'metadata.rb' => "name 'quiche'\nversion '1.0.0'\n", 'recipes' => { 'default.rb' => '' } }
+ cookbook 'soup', '1.0.0', { 'metadata.rb' => "name 'soup'\nversion '1.0.0'\n", 'recipes' => { 'chicken.rb' => '' } }
+ end
it 'knife deps reports all dependencies' do
knife('deps --remote /roles/starring.json').should_succeed <<EOM
/roles/minor.json
@@ -381,23 +410,27 @@ EOM
end
when_the_chef_server 'has a node with no environment or run_list' do
- node 'mort', {}
+ before { node 'mort', {} }
it 'knife deps reports just the node' do
knife('deps --remote /nodes/mort.json').should_succeed "/nodes/mort.json\n"
end
end
when_the_chef_server 'has a node with an environment' do
- environment 'desert', {}
- node 'mort', { 'chef_environment' => 'desert' }
+ before do
+ environment 'desert', {}
+ node 'mort', { 'chef_environment' => 'desert' }
+ end
it 'knife deps reports just the node' do
knife('deps --remote /nodes/mort.json').should_succeed "/environments/desert.json\n/nodes/mort.json\n"
end
end
when_the_chef_server 'has a node with roles and recipes in its run_list' do
- role 'minor', {}
- cookbook 'quiche', '1.0.0', { 'metadata.rb' => "name 'quiche'\nversion '1.0.0'\n", 'recipes' => { 'default.rb' => '' } }
- cookbook 'soup', '1.0.0', { 'metadata.rb' => "name 'soup'\nversion '1.0.0'\n", 'recipes' => { 'chicken.rb' => '' } }
- node 'mort', { 'run_list' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) }
+ before do
+ role 'minor', {}
+ cookbook 'quiche', '1.0.0', { 'metadata.rb' => "name 'quiche'\nversion '1.0.0'\n", 'recipes' => { 'default.rb' => '' } }
+ cookbook 'soup', '1.0.0', { 'metadata.rb' => "name 'soup'\nversion '1.0.0'\n", 'recipes' => { 'chicken.rb' => '' } }
+ node 'mort', { 'run_list' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) }
+ end
it 'knife deps reports just the node' do
knife('deps --remote /nodes/mort.json').should_succeed <<EOM
/roles/minor.json
@@ -408,38 +441,44 @@ EOM
end
end
when_the_chef_server 'has a cookbook with no dependencies' do
- cookbook 'quiche', '1.0.0', { 'metadata.rb' => "name 'quiche'\nversion '1.0.0'\n", 'recipes' => { 'default.rb' => '' } }
+ before do
+ cookbook 'quiche', '1.0.0', { 'metadata.rb' => "name 'quiche'\nversion '1.0.0'\n", 'recipes' => { 'default.rb' => '' } }
+ end
it 'knife deps reports just the cookbook' do
knife('deps --remote /cookbooks/quiche').should_succeed "/cookbooks/quiche\n"
end
end
when_the_chef_server 'has a cookbook with dependencies' do
- cookbook 'kettle', '1.0.0', { 'metadata.rb' => "name 'kettle'\nversion '1.0.0'\n" }
- cookbook 'quiche', '1.0.0', { 'metadata.rb' => "name 'quiche'\ndepends 'kettle'\n", 'recipes' => { 'default.rb' => '' } }
+ before do
+ cookbook 'kettle', '1.0.0', { 'metadata.rb' => "name 'kettle'\nversion '1.0.0'\n" }
+ cookbook 'quiche', '1.0.0', { 'metadata.rb' => "name 'quiche'\ndepends 'kettle'\n", 'recipes' => { 'default.rb' => '' } }
+ end
it 'knife deps reports the cookbook and its dependencies' do
knife('deps --remote /cookbooks/quiche').should_succeed "/cookbooks/kettle\n/cookbooks/quiche\n"
end
end
when_the_chef_server 'has a data bag' do
- data_bag 'bag', { 'item' => {} }
+ before { data_bag 'bag', { 'item' => {} } }
it 'knife deps reports just the data bag' do
knife('deps --remote /data_bags/bag/item.json').should_succeed "/data_bags/bag/item.json\n"
end
end
when_the_chef_server 'has an environment' do
- environment 'desert', {}
+ before { environment 'desert', {} }
it 'knife deps reports just the environment' do
knife('deps --remote /environments/desert.json').should_succeed "/environments/desert.json\n"
end
end
when_the_chef_server 'has a deep dependency tree' do
- role 'starring', { 'run_list' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) }
- role 'minor', {}
- cookbook 'quiche', '1.0.0', { 'metadata.rb' => "name 'quiche'\nversion '1.0.0'\n", 'recipes' => { 'default.rb' => '' } }
- cookbook 'soup', '1.0.0', { 'metadata.rb' => "name 'soup'\nversion '1.0.0'\n", 'recipes' => { 'chicken.rb' => '' } }
- environment 'desert', {}
- node 'mort', { 'chef_environment' => 'desert', 'run_list' => [ 'role[starring]' ] }
- node 'bart', { 'run_list' => [ 'role[minor]' ] }
+ before do
+ role 'starring', { 'run_list' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) }
+ role 'minor', {}
+ cookbook 'quiche', '1.0.0', { 'metadata.rb' => "name 'quiche'\nversion '1.0.0'\n", 'recipes' => { 'default.rb' => '' } }
+ cookbook 'soup', '1.0.0', { 'metadata.rb' => "name 'soup'\nversion '1.0.0'\n", 'recipes' => { 'chicken.rb' => '' } }
+ environment 'desert', {}
+ node 'mort', { 'chef_environment' => 'desert', 'run_list' => [ 'role[starring]' ] }
+ node 'bart', { 'run_list' => [ 'role[minor]' ] }
+ end
it 'knife deps reports all dependencies' do
knife('deps --remote /nodes/mort.json').should_succeed <<EOM
@@ -498,10 +537,12 @@ EOM
context 'circular dependencies' do
when_the_chef_server 'has cookbooks with circular dependencies' do
- cookbook 'foo', '1.0.0', { 'metadata.rb' => "name 'foo'\ndepends 'bar'\n" }
- cookbook 'bar', '1.0.0', { 'metadata.rb' => "name 'bar'\ndepends 'baz'\n" }
- cookbook 'baz', '1.0.0', { 'metadata.rb' => "name 'baz'\ndepends 'foo'\n" }
- cookbook 'self', '1.0.0', { 'metadata.rb' => "name 'self'\ndepends 'self'\n" }
+ before do
+ cookbook 'foo', '1.0.0', { 'metadata.rb' => "name 'foo'\ndepends 'bar'\n" }
+ cookbook 'bar', '1.0.0', { 'metadata.rb' => "name 'bar'\ndepends 'baz'\n" }
+ cookbook 'baz', '1.0.0', { 'metadata.rb' => "name 'baz'\ndepends 'foo'\n" }
+ cookbook 'self', '1.0.0', { 'metadata.rb' => "name 'self'\ndepends 'self'\n" }
+ end
it 'knife deps prints each once' do
knife('deps --remote /cookbooks/foo /cookbooks/self').should_succeed <<EOM
/cookbooks/baz
@@ -522,10 +563,12 @@ EOM
end
end
when_the_chef_server 'has roles with circular dependencies' do
- role 'foo', { 'run_list' => [ 'role[bar]' ] }
- role 'bar', { 'run_list' => [ 'role[baz]' ] }
- role 'baz', { 'run_list' => [ 'role[foo]' ] }
- role 'self', { 'run_list' => [ 'role[self]' ] }
+ before do
+ role 'foo', { 'run_list' => [ 'role[bar]' ] }
+ role 'bar', { 'run_list' => [ 'role[baz]' ] }
+ role 'baz', { 'run_list' => [ 'role[foo]' ] }
+ role 'self', { 'run_list' => [ 'role[self]' ] }
+ end
it 'knife deps prints each once' do
knife('deps --remote /roles/foo.json /roles/self.json').should_succeed <<EOM
/roles/baz.json
@@ -589,7 +632,9 @@ EOM
end
end
when_the_chef_server 'is missing a dependent cookbook' do
- role 'starring', { 'run_list' => [ 'recipe[quiche]'] }
+ before do
+ role 'starring', { 'run_list' => [ 'recipe[quiche]'] }
+ end
it 'knife deps reports the cookbook, along with an error' do
knife('deps --remote /roles/starring.json').should_fail(
:exit_code => 2,
@@ -599,7 +644,9 @@ EOM
end
end
when_the_chef_server 'is missing a dependent environment' do
- node 'mort', { 'chef_environment' => 'desert' }
+ before do
+ node 'mort', { 'chef_environment' => 'desert' }
+ end
it 'knife deps reports the environment, along with an error' do
knife('deps --remote /nodes/mort.json').should_fail(
:exit_code => 2,
@@ -609,7 +656,9 @@ EOM
end
end
when_the_chef_server 'is missing a dependent role' do
- role 'starring', { 'run_list' => [ 'role[minor]'] }
+ before do
+ role 'starring', { 'run_list' => [ 'role[minor]'] }
+ end
it 'knife deps reports the role, along with an error' do
knife('deps --remote /roles/starring.json').should_fail(
:exit_code => 2,
@@ -629,13 +678,15 @@ EOM
end
end
when_the_chef_server 'has a data bag' do
- data_bag 'bag', { 'item' => {} }
+ before { data_bag 'bag', { 'item' => {} } }
it 'knife deps /data_bags/bag shows no dependencies' do
knife('deps --remote /data_bags/bag').should_succeed("/data_bags/bag\n")
end
end
when_the_chef_server 'has a cookbook' do
- cookbook 'blah', '1.0.0', { 'metadata.rb' => 'name "blah"' }
+ before do
+ cookbook 'blah', '1.0.0', { 'metadata.rb' => 'name "blah"' }
+ end
it 'knife deps on a cookbook file shows no dependencies' do
knife('deps --remote /cookbooks/blah/metadata.rb').should_succeed(
"/cookbooks/blah/metadata.rb\n"
diff --git a/spec/integration/knife/diff_spec.rb b/spec/integration/knife/diff_spec.rb
index 2e36f39c82..8d13d86a99 100644
--- a/spec/integration/knife/diff_spec.rb
+++ b/spec/integration/knife/diff_spec.rb
@@ -19,27 +19,31 @@ require 'support/shared/integration/integration_helper'
require 'chef/knife/diff'
describe 'knife diff' 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 diff reports everything as deleted' do
knife('diff --name-status /').should_succeed <<EOM
@@ -60,17 +64,19 @@ EOM
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 diff reports no differences' do
knife('diff /').should_succeed ''
@@ -85,11 +91,14 @@ EOM
end
context 'except the role file' do
- file 'roles/x.json', <<EOM
+ before do
+ file 'roles/x.json', <<EOM
{
"foo": "bar"
}
EOM
+ end
+
it 'knife diff reports the role as different' do
knife('diff --name-status /').should_succeed <<EOM
M\t/roles/x.json
@@ -98,15 +107,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("y", "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 diff reports the new files as added' do
knife('diff --name-status /').should_succeed <<EOM
@@ -123,7 +134,7 @@ EOM
end
context 'when cwd is the data_bags directory' do
- cwd 'data_bags'
+ before { cwd 'data_bags' }
it 'knife diff reports different data bags' do
knife('diff --name-status').should_succeed <<EOM
A\tx/z.json
@@ -156,12 +167,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', ''
+ before do
+ file 'cookbooks/x/metadata.rb', cb_metadata("x", "1.0.0")
+ file 'cookbooks/x/onlyin1.0.0.rb', ''
+ 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' => '' }
+ before do
+ cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => ''}
+ cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => '' }
+ end
it 'knife diff /cookbooks/x shows differences' do
knife('diff --name-status /cookbooks/x').should_succeed <<EOM
@@ -180,15 +195,19 @@ 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' => '' }
+ before do
+ cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => '' }
+ cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => '' }
+ end
it 'knife diff /cookbooks/x shows no differences' do
knife('diff --name-status /cookbooks/x').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' => '' }
+ before do
+ cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => '' }
+ end
it 'knife diff /cookbooks/x shows the differences' do
knife('diff --name-status /cookbooks/x').should_succeed <<EOM
@@ -200,7 +219,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' => '' }
+ before do
+ cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => '' }
+ end
it 'knife diff /cookbooks/x shows the differences' do
knife('diff --name-status /cookbooks/x').should_succeed <<EOM
@@ -214,15 +235,18 @@ EOM
context 'json diff tests' do
when_the_repository 'has an empty environment file' do
- file 'environments/x.json', {}
+ before do
+ file 'environments/x.json', {}
+ end
+
when_the_chef_server 'has an empty environment' do
- environment 'x', {}
+ before { environment 'x', {} }
it 'knife diff returns no differences' do
knife('diff /environments/x.json').should_succeed ''
end
end
when_the_chef_server 'has an environment with a different value' do
- environment 'x', { 'description' => 'hi' }
+ before { environment 'x', { 'description' => 'hi' } }
it 'knife diff reports the difference', :pending => (RUBY_VERSION < "1.9") do
knife('diff /environments/x.json').should_succeed(/
{
@@ -236,15 +260,23 @@ EOM
end
when_the_repository 'has an environment file with a value in it' do
- file 'environments/x.json', { 'description' => 'hi' }
+ before do
+ file 'environments/x.json', { 'description' => 'hi' }
+ end
+
when_the_chef_server 'has an environment with the same value' do
- environment 'x', { 'description' => 'hi' }
+ before do
+ environment 'x', { 'description' => 'hi' }
+ end
it 'knife diff returns no differences' do
knife('diff /environments/x.json').should_succeed ''
end
end
when_the_chef_server 'has an environment with no value' do
- environment 'x', {}
+ before do
+ environment 'x', {}
+ end
+
it 'knife diff reports the difference', :pending => (RUBY_VERSION < "1.9") do
knife('diff /environments/x.json').should_succeed(/
{
@@ -256,7 +288,9 @@ EOM
end
end
when_the_chef_server 'has an environment with a different value' do
- environment 'x', { 'description' => 'lo' }
+ before do
+ environment 'x', { 'description' => 'lo' }
+ end
it 'knife diff reports the difference', :pending => (RUBY_VERSION < "1.9") do
knife('diff /environments/x.json').should_succeed(/
{
@@ -271,9 +305,9 @@ EOM
end
when_the_chef_server 'has an environment' do
- environment 'x', {}
+ before { environment 'x', {} }
when_the_repository 'has an environment with bad JSON' do
- file 'environments/x.json', '{'
+ before { file 'environments/x.json', '{' }
it 'knife diff reports an error and does a textual diff' do
knife('diff /environments/x.json').should_succeed(/- "name": "x"/, :stderr => "WARN: Parse error reading #{path_to('environments/x.json')} as JSON: A JSON text must at least contain two octets!\n")
end
@@ -283,22 +317,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 diff reports everything as deleted' do
knife('diff --name-status /').should_succeed <<EOM
@@ -318,17 +356,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 diff reports no differences' do
knife('diff /').should_succeed ''
@@ -343,11 +383,14 @@ EOM
end
context 'except the role file' do
- file 'roles/x.json', <<EOM
+ before do
+ file 'roles/x.json', <<EOM
{
"foo": "bar"
}
EOM
+ end
+
it 'knife diff reports the role as different' do
knife('diff --name-status /').should_succeed <<EOM
M\t/roles/x.json
@@ -356,16 +399,18 @@ EOM
end
context 'as well as one extra copy of each thing' do
- file 'clients/y.json', {}
- 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', {}
+ before do
+ file 'clients/y.json', {}
+ file 'cookbooks/x-1.0.0/blah.rb', ''
+ file 'cookbooks/x-2.0.0/metadata.rb', cb_metadata("x", "2.0.0")
+ file 'cookbooks/y-1.0.0/metadata.rb', cb_metadata("y", "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', {}
+ end
it 'knife diff reports the new files as added' do
knife('diff --name-status /').should_succeed <<EOM
@@ -383,7 +428,7 @@ EOM
end
context 'when cwd is the data_bags directory' do
- cwd 'data_bags'
+ before { cwd 'data_bags' }
it 'knife diff reports different data bags' do
knife('diff --name-status').should_succeed <<EOM
A\tx/z.json
@@ -416,12 +461,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', ''
+ 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', ''
+ 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' => '' }
+ before do
+ cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => ''}
+ cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => '' }
+ end
it 'knife diff /cookbooks shows differences' do
knife('diff --name-status /cookbooks').should_succeed <<EOM
@@ -435,15 +484,19 @@ 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' => '' }
+ before do
+ cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => '' }
+ cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => '' }
+ end
it 'knife diff /cookbooks shows the differences' do
knife('diff --name-status /cookbooks').should_succeed "D\t/cookbooks/x-0.9.9\n"
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' => '' }
+ before do
+ cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => '' }
+ end
it 'knife diff /cookbooks shows the differences' do
knife('diff --name-status /cookbooks').should_succeed <<EOM
@@ -454,7 +507,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' => '' }
+ before do
+ cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => '' }
+ end
it 'knife diff /cookbooks shows the differences' do
knife('diff --name-status /cookbooks').should_succeed <<EOM
@@ -467,15 +522,15 @@ EOM
context 'json diff tests' do
when_the_repository 'has an empty environment file' do
- file 'environments/x.json', {}
+ before { file 'environments/x.json', {} }
when_the_chef_server 'has an empty environment' do
- environment 'x', {}
+ before { environment 'x', {} }
it 'knife diff returns no differences' do
knife('diff /environments/x.json').should_succeed ''
end
end
when_the_chef_server 'has an environment with a different value' do
- environment 'x', { 'description' => 'hi' }
+ before { environment 'x', { 'description' => 'hi' } }
it 'knife diff reports the difference', :pending => (RUBY_VERSION < "1.9") do
knife('diff /environments/x.json').should_succeed(/
{
@@ -489,15 +544,20 @@ EOM
end
when_the_repository 'has an environment file with a value in it' do
- file 'environments/x.json', { 'description' => 'hi' }
+ before do
+ file 'environments/x.json', { 'description' => 'hi' }
+ end
+
when_the_chef_server 'has an environment with the same value' do
- environment 'x', { 'description' => 'hi' }
+ before do
+ environment 'x', { 'description' => 'hi' }
+ end
it 'knife diff returns no differences' do
knife('diff /environments/x.json').should_succeed ''
end
end
when_the_chef_server 'has an environment with no value' do
- environment 'x', {}
+ before { environment 'x', {} }
it 'knife diff reports the difference', :pending => (RUBY_VERSION < "1.9") do
knife('diff /environments/x.json').should_succeed(/
{
@@ -509,7 +569,9 @@ EOM
end
end
when_the_chef_server 'has an environment with a different value' do
- environment 'x', { 'description' => 'lo' }
+ before do
+ environment 'x', { 'description' => 'lo' }
+ end
it 'knife diff reports the difference', :pending => (RUBY_VERSION < "1.9") do
knife('diff /environments/x.json').should_succeed(/
{
@@ -524,9 +586,9 @@ EOM
end
when_the_chef_server 'has an environment' do
- environment 'x', {}
+ before { environment 'x', {} }
when_the_repository 'has an environment with bad JSON' do
- file 'environments/x.json', '{'
+ before { file 'environments/x.json', '{' }
it 'knife diff reports an error and does a textual diff' do
knife('diff /environments/x.json').should_succeed(/- "name": "x"/, :stderr => "WARN: Parse error reading #{path_to('environments/x.json')} as JSON: A JSON text must at least contain two octets!\n")
end
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
diff --git a/spec/integration/knife/list_spec.rb b/spec/integration/knife/list_spec.rb
index b9e72c5573..31dba2407d 100644
--- a/spec/integration/knife/list_spec.rb
+++ b/spec/integration/knife/list_spec.rb
@@ -20,7 +20,7 @@ require 'support/shared/context/config'
require 'chef/knife/list'
describe 'knife list' do
- extend IntegrationSupport
+ include IntegrationSupport
include KnifeSupport
include_context "default config options"
@@ -71,20 +71,22 @@ EOM
end
when_the_chef_server "has plenty of stuff in it" do
- client 'client1', {}
- client 'client2', {}
- cookbook 'cookbook1', '1.0.0', { 'metadata.rb' => '' }
- cookbook 'cookbook2', '1.0.1', { 'metadata.rb' => '', 'recipes' => { 'default.rb' => '' } }
- data_bag 'bag1', { 'item1' => {}, 'item2' => {} }
- data_bag 'bag2', { 'item1' => {}, 'item2' => {} }
- environment 'environment1', {}
- environment 'environment2', {}
- node 'node1', {}
- node 'node2', {}
- role 'role1', {}
- role 'role2', {}
- user 'user1', {}
- user 'user2', {}
+ before do
+ client 'client1', {}
+ client 'client2', {}
+ cookbook 'cookbook1', '1.0.0'
+ cookbook 'cookbook2', '1.0.1', { 'recipes' => { 'default.rb' => '' } }
+ data_bag 'bag1', { 'item1' => {}, 'item2' => {} }
+ data_bag 'bag2', { 'item1' => {}, 'item2' => {} }
+ environment 'environment1', {}
+ environment 'environment2', {}
+ node 'node1', {}
+ node 'node2', {}
+ role 'role1', {}
+ role 'role2', {}
+ user 'user1', {}
+ user 'user2', {}
+ end
it "knife list / returns all top level directories" do
knife('list /').should_succeed <<EOM
@@ -317,7 +319,7 @@ EOM
context 'symlink tests' do
when_the_repository 'is empty' do
context 'when cwd is at the top of the repository' do
- cwd '.'
+ before { cwd '.' }
it "knife list -Rfp returns everything" do
knife('list -Rfp').should_succeed <<EOM
@@ -360,9 +362,9 @@ EOM
end
when_the_repository 'has a cookbooks directory' do
- directory 'cookbooks'
+ before { directory 'cookbooks' }
context 'when cwd is in cookbooks/' do
- cwd 'cookbooks'
+ before { cwd 'cookbooks' }
it "knife list -Rfp / returns everything" do
knife('list -Rfp /').should_succeed <<EOM
@@ -454,10 +456,10 @@ EOM
end
when_the_repository 'has a cookbooks/cookbook2 directory' do
- directory 'cookbooks/cookbook2'
+ before { directory 'cookbooks/cookbook2' }
context 'when cwd is in cookbooks/cookbook2' do
- cwd 'cookbooks/cookbook2'
+ before { cwd 'cookbooks/cookbook2' }
it "knife list -Rfp returns cookbooks" do
knife('list -Rfp').should_succeed <<EOM
@@ -470,11 +472,13 @@ EOM
end
when_the_repository 'has a cookbooks directory and a symlinked cookbooks directory', :pending => (Chef::Platform.windows?) do
- directory 'cookbooks'
- symlink 'symlinked', 'cookbooks'
+ before do
+ directory 'cookbooks'
+ symlink 'symlinked', 'cookbooks'
+ end
context 'when cwd is in cookbooks/' do
- cwd 'cookbooks'
+ before { cwd 'cookbooks' }
it "knife list -Rfp returns cookbooks" do
knife('list -Rfp').should_succeed <<EOM
@@ -489,7 +493,7 @@ EOM
end
context 'when cwd is in symlinked/' do
- cwd 'symlinked'
+ before { cwd 'symlinked' }
it "knife list -Rfp returns cookbooks" do
knife('list -Rfp').should_succeed <<EOM
@@ -505,11 +509,13 @@ EOM
end
when_the_repository 'has a real_cookbooks directory and a cookbooks symlink to it', :pending => (Chef::Platform.windows?) do
- directory 'real_cookbooks'
- symlink 'cookbooks', 'real_cookbooks'
+ before do
+ directory 'real_cookbooks'
+ symlink 'cookbooks', 'real_cookbooks'
+ end
context 'when cwd is in real_cookbooks/' do
- cwd 'real_cookbooks'
+ before { cwd 'real_cookbooks' }
it "knife list -Rfp returns cookbooks" do
knife('list -Rfp').should_succeed <<EOM
@@ -524,7 +530,7 @@ EOM
end
context 'when cwd is in cookbooks/' do
- cwd 'cookbooks'
+ before { cwd 'cookbooks' }
it "knife list -Rfp returns cookbooks" do
knife('list -Rfp').should_succeed <<EOM
@@ -553,36 +559,38 @@ EOM
end
when_the_repository "has a bunch of stuff" do
- file 'clients/client1.json', {}
- file 'clients/client2.json', {}
-
- directory 'cookbooks/cookbook1' do
- file 'metadata.rb', ''
- end
- directory 'cookbooks/cookbook2' do
- file 'metadata.rb', ''
- file 'recipes/default.rb', ''
- end
+ before do
+ file 'clients/client1.json', {}
+ file 'clients/client2.json', {}
- directory 'data_bags' do
- directory 'bag1' do
- file 'item1.json', {}
- file 'item2.json', {}
+ directory 'cookbooks/cookbook1' do
+ file 'metadata.rb', cb_metadata("cookbook1", "1.0.0")
end
- directory 'bag2' do
- file 'item1.json', {}
- file 'item2.json', {}
+ directory 'cookbooks/cookbook2' do
+ file 'metadata.rb', cb_metadata("cookbook2", "2.0.0")
+ file 'recipes/default.rb', ''
+ end
+
+ directory 'data_bags' do
+ directory 'bag1' do
+ file 'item1.json', {}
+ file 'item2.json', {}
+ end
+ directory 'bag2' do
+ file 'item1.json', {}
+ file 'item2.json', {}
+ end
end
- end
- file 'environments/environment1.json', {}
- file 'environments/environment2.json', {}
- file 'nodes/node1.json', {}
- file 'nodes/node2.json', {}
- file 'roles/role1.json', {}
- file 'roles/role2.json', {}
- file 'users/user1.json', {}
- file 'users/user2.json', {}
+ file 'environments/environment1.json', {}
+ file 'environments/environment2.json', {}
+ file 'nodes/node1.json', {}
+ file 'nodes/node2.json', {}
+ file 'roles/role1.json', {}
+ file 'roles/role2.json', {}
+ file 'users/user1.json', {}
+ file 'users/user2.json', {}
+ end
it "knife list -Rfp / returns everything" do
knife('list -Rp --local --flat /').should_succeed <<EOM
diff --git a/spec/integration/knife/raw_spec.rb b/spec/integration/knife/raw_spec.rb
index 2a9b5d8904..080ea0f21b 100644
--- a/spec/integration/knife/raw_spec.rb
+++ b/spec/integration/knife/raw_spec.rb
@@ -21,20 +21,22 @@ require 'chef/knife/raw'
require 'chef/knife/show'
describe 'knife raw' do
- extend IntegrationSupport
+ include IntegrationSupport
include KnifeSupport
include AppServerSupport
include_context "default config options"
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
it 'knife raw /nodes/x returns the node', :pending => (RUBY_VERSION < "1.9") do
knife('raw /nodes/x').should_succeed <<EOM
@@ -44,12 +46,16 @@ describe 'knife raw' do
"chef_type": "node",
"chef_environment": "_default",
"override": {
+
},
"normal": {
+
},
"default": {
+
},
"automatic": {
+
},
"run_list": [
@@ -70,13 +76,16 @@ EOM
"json_class": "Chef::Role",
"chef_type": "role",
"default_attributes": {
+
},
"override_attributes": {
+
},
"run_list": [
],
"env_run_lists": {
+
}
}
EOM
@@ -92,13 +101,16 @@ EOM
"json_class": "Chef::Role",
"chef_type": "role",
"default_attributes": {
+
},
"override_attributes": {
+
},
"run_list": [
],
"env_run_lists": {
+
}
}
EOM
@@ -111,13 +123,16 @@ EOM
"json_class": "Chef::Role",
"chef_type": "role",
"default_attributes": {
+
},
"override_attributes": {
+
},
"run_list": [
],
"env_run_lists": {
+
}
}
EOM
@@ -154,7 +169,7 @@ EOM
knife("raw -m POST -i #{file.path} /roles").should_succeed <<EOM
{
- "uri": "#{ChefZero::RSpec.server.url}/roles/y"
+ "uri": "#{ChefZeroSupport::Server.server.url}/roles/y"
}
EOM
knife('show /roles/y.json').should_succeed <<EOM
diff --git a/spec/integration/knife/redirection_spec.rb b/spec/integration/knife/redirection_spec.rb
index ebfd40966e..549a6f6df0 100644
--- a/spec/integration/knife/redirection_spec.rb
+++ b/spec/integration/knife/redirection_spec.rb
@@ -20,14 +20,14 @@ require 'support/shared/context/config'
require 'chef/knife/list'
describe 'redirection' do
- extend IntegrationSupport
+ include IntegrationSupport
include KnifeSupport
include AppServerSupport
include_context "default config options"
when_the_chef_server 'has a role' do
- role 'x', {}
+ before { role 'x', {} }
context 'and another server redirects to it with 302' do
before :each do
diff --git a/spec/integration/knife/serve_spec.rb b/spec/integration/knife/serve_spec.rb
index 20e4e43586..32e633543d 100644
--- a/spec/integration/knife/serve_spec.rb
+++ b/spec/integration/knife/serve_spec.rb
@@ -20,12 +20,12 @@ require 'chef/knife/serve'
require 'chef/server_api'
describe 'knife serve' do
- extend IntegrationSupport
+ include IntegrationSupport
include KnifeSupport
include AppServerSupport
when_the_repository 'also has one of each thing' do
- file 'nodes/x.json', { 'foo' => 'bar' }
+ before { file 'nodes/x.json', { 'foo' => 'bar' } }
it 'knife serve serves up /nodes/x' do
exception = nil
diff --git a/spec/integration/knife/show_spec.rb b/spec/integration/knife/show_spec.rb
index 5b15110e41..3a20f96a11 100644
--- a/spec/integration/knife/show_spec.rb
+++ b/spec/integration/knife/show_spec.rb
@@ -20,40 +20,44 @@ require 'support/shared/context/config'
require 'chef/knife/show'
describe 'knife show' do
- extend IntegrationSupport
+ include IntegrationSupport
include KnifeSupport
include_context "default config options"
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 'also has one of each thing' do
- file 'clients/x.json', { 'foo' => 'bar' }
- file 'cookbooks/x/metadata.rb', 'version "1.0.1"'
- file 'data_bags/x/y.json', { 'foo' => 'bar' }
- file 'environments/_default.json', { 'foo' => 'bar' }
- file 'environments/x.json', { 'foo' => 'bar' }
- file 'nodes/x.json', { 'foo' => 'bar' }
- file 'roles/x.json', { 'foo' => 'bar' }
- file 'users/x.json', { 'foo' => 'bar' }
+ before do
+ file 'clients/x.json', { 'foo' => 'bar' }
+ file 'cookbooks/x/metadata.rb', cb_metadata('x', '1.0.0')
+ file 'data_bags/x/y.json', { 'foo' => 'bar' }
+ file 'environments/_default.json', { 'foo' => 'bar' }
+ file 'environments/x.json', { 'foo' => 'bar' }
+ file 'nodes/x.json', { 'foo' => 'bar' }
+ file 'roles/x.json', { 'foo' => 'bar' }
+ file 'users/x.json', { 'foo' => 'bar' }
+ end
it 'knife show /cookbooks/x/metadata.rb shows the remote version' do
knife('show /cookbooks/x/metadata.rb').should_succeed <<EOM
/cookbooks/x/metadata.rb:
-version "1.0.0"
+name 'x'; version '1.0.0'
EOM
end
it 'knife show --local /cookbooks/x/metadata.rb shows the local version' do
knife('show --local /cookbooks/x/metadata.rb').should_succeed <<EOM
/cookbooks/x/metadata.rb:
-version "1.0.1"
+name 'x'; version '1.0.0'
EOM
end
it 'knife show /data_bags/x/y.json shows the remote version' do
@@ -122,13 +126,15 @@ EOM
end
when_the_chef_server 'has a hash with multiple keys' do
- environment 'x', {
- 'default_attributes' => { 'foo' => 'bar' },
- 'cookbook_versions' => { 'blah' => '= 1.0.0'},
- 'override_attributes' => { 'x' => 'y' },
- 'description' => 'woo',
- 'name' => 'x'
- }
+ before do
+ environment 'x', {
+ 'default_attributes' => { 'foo' => 'bar' },
+ 'cookbook_versions' => { 'blah' => '= 1.0.0'},
+ 'override_attributes' => { 'x' => 'y' },
+ 'description' => 'woo',
+ 'name' => 'x'
+ }
+ end
it 'knife show shows the attributes in a predetermined order', :pending => (RUBY_VERSION < "1.9") do
knife('show /environments/x.json').should_succeed <<EOM
/environments/x.json:
@@ -150,7 +156,7 @@ EOM
end
when_the_repository 'has an environment with bad JSON' do
- file 'environments/x.json', '{'
+ before { file 'environments/x.json', '{' }
it 'knife show succeeds' do
knife('show --local /environments/x.json').should_succeed <<EOM
/environments/x.json:
diff --git a/spec/integration/knife/upload_spec.rb b/spec/integration/knife/upload_spec.rb
index 46b804205f..90666f4fc9 100644
--- a/spec/integration/knife/upload_spec.rb
+++ b/spec/integration/knife/upload_spec.rb
@@ -21,27 +21,33 @@ require 'chef/knife/diff'
require 'chef/knife/raw'
describe 'knife upload' 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 upload does nothing' do
knife('upload /').should_succeed ''
@@ -80,17 +86,20 @@ 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 upload makes no changes' do
knife('upload /cookbooks/x').should_succeed ''
@@ -103,7 +112,10 @@ 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 upload changes the role' do
knife('upload /').should_succeed "Updated /roles/x.json\n"
knife('diff --name-status /').should_succeed ''
@@ -115,7 +127,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 +145,8 @@ EOM
]
}
EOM
+ end
+
it 'knife upload / does not change anything' do
knife('upload /').should_succeed ''
knife('diff --name-status /').should_succeed ''
@@ -139,15 +154,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("y", "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 upload adds the new files' do
knife('upload /').should_succeed <<EOM
@@ -219,7 +236,10 @@ EOM
end
context 'when current directory is top level' do
- cwd '.'
+ before do
+ cwd '.'
+ end
+
it 'knife upload with no parameters reports an error' do
knife('upload').should_fail "FATAL: Must specify at least one argument. If you want to upload everything in this directory, type \"knife upload .\"\n", :stdout => /USAGE/
end
@@ -229,7 +249,11 @@ EOM
when_the_chef_server 'is empty' do
when_the_repository 'has a data bag item' do
- file 'data_bags/x/y.json', { 'foo' => 'bar' }
+
+ before do
+ file 'data_bags/x/y.json', { 'foo' => 'bar' }
+ end
+
it 'knife upload of the data bag uploads only the values in the data bag item and no other' do
knife('upload /data_bags/x/y.json').should_succeed <<EOM
Created /data_bags/x
@@ -249,7 +273,11 @@ EOM
end
when_the_repository 'has a data bag item with keys chef_type and data_bag' do
- file 'data_bags/x/y.json', { 'chef_type' => 'aaa', 'data_bag' => 'bbb' }
+
+ before do
+ file 'data_bags/x/y.json', { 'chef_type' => 'aaa', 'data_bag' => 'bbb' }
+ end
+
it 'upload preserves chef_type and data_bag' do
knife('upload /data_bags/x/y.json').should_succeed <<EOM
Created /data_bags/x
@@ -265,8 +293,10 @@ EOM
# Test upload of an item when the other end doesn't even have the container
when_the_repository 'has two data bag items' do
- file 'data_bags/x/y.json', {}
- file 'data_bags/x/z.json', {}
+ before do
+ file 'data_bags/x/y.json', {}
+ file 'data_bags/x/z.json', {}
+ end
it 'knife upload of one data bag item itself succeeds' do
knife('upload /data_bags/x/y.json').should_succeed <<EOM
Created /data_bags/x
@@ -280,12 +310,17 @@ EOM
end
when_the_chef_server 'has three data bag items' do
- data_bag 'x', { 'deleted' => {}, 'modified' => {}, 'unmodified' => {} }
+
+ before do
+ data_bag 'x', { 'deleted' => {}, 'modified' => {}, 'unmodified' => {} }
+ end
when_the_repository 'has a modified, unmodified, added and deleted data bag item' do
- file 'data_bags/x/added.json', {}
- file 'data_bags/x/modified.json', { 'foo' => 'bar' }
- file 'data_bags/x/unmodified.json', {}
+ before do
+ file 'data_bags/x/added.json', {}
+ file 'data_bags/x/modified.json', { 'foo' => 'bar' }
+ file 'data_bags/x/unmodified.json', {}
+ end
it 'knife upload of the modified file succeeds' do
knife('upload /data_bags/x/modified.json').should_succeed <<EOM
@@ -348,10 +383,15 @@ 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 upload fails' do
knife('upload').should_fail "FATAL: Must specify at least one argument. If you want to upload everything in this directory, type \"knife upload .\"\n", :stdout => /USAGE/
end
+
it 'knife upload --purge . uploads everything' do
knife('upload --purge .').should_succeed <<EOM
Created x/added.json
@@ -376,10 +416,17 @@ EOM
# upload of a file is designed not to work at present. Make sure that is the
# case.
when_the_chef_server 'has a cookbook' do
- cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"', 'z.rb' => '' }
+
+ before do
+ cookbook 'x', '1.0.0', { 'z.rb' => '' }
+ end
+
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'
+ before do
+ file 'cookbooks/x/metadata.rb', cb_metadata("x", "1.0.0", "#modified")
+ file 'cookbooks/x/y.rb', 'hi'
+ end
+
it 'knife upload of any individual file fails' do
knife('upload /cookbooks/x/metadata.rb').should_fail "ERROR: /cookbooks/x/metadata.rb cannot be updated.\n"
knife('upload /cookbooks/x/y.rb').should_fail "ERROR: /cookbooks/x cannot have a child created under it.\n"
@@ -402,7 +449,11 @@ EOM
end
end
when_the_repository 'has a missing file for the cookbook' do
- file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
+
+ before do
+ file 'cookbooks/x/metadata.rb', cb_metadata('x', '1.0.0')
+ end
+
it 'knife upload of the cookbook succeeds' do
knife('upload /cookbooks/x').should_succeed <<EOM
Updated /cookbooks/x
@@ -411,9 +462,13 @@ EOM
end
end
when_the_repository 'has an extra file for the cookbook' do
- file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
- file 'cookbooks/x/z.rb', ''
- file 'cookbooks/x/blah.rb', ''
+
+ before do
+ file 'cookbooks/x/metadata.rb', cb_metadata('x', '1.0.0')
+ file 'cookbooks/x/z.rb', ''
+ file 'cookbooks/x/blah.rb', ''
+ end
+
it 'knife upload of the cookbook succeeds' do
knife('upload /cookbooks/x').should_succeed <<EOM
Updated /cookbooks/x
@@ -423,26 +478,31 @@ EOM
end
when_the_repository 'has a different file in the cookbook' do
- file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
+ before do
+ file 'cookbooks/x/metadata.rb', cb_metadata('x', '1.0.0')
+ end
it 'knife upload --freeze freezes the cookbook' do
knife('upload --freeze /cookbooks/x').should_succeed <<EOM
Updated /cookbooks/x
EOM
# Modify a file and attempt to upload
- file 'cookbooks/x/metadata.rb', 'version "1.0.0" # This is different'
+ file 'cookbooks/x/metadata.rb', "name 'x'; version '1.0.0'#different"
knife('upload /cookbooks/x').should_fail "ERROR: /cookbooks failed to write: Cookbook x is frozen\n"
end
end
end
when_the_chef_server 'has a frozen cookbook' do
- cookbook 'frozencook', '1.0.0', {
- 'metadata.rb' => 'version "1.0.0"'
- }, :frozen => true
+ before do
+ cookbook 'frozencook', '1.0.0', {}, :frozen => true
+ end
when_the_repository 'has an update to said cookbook' do
- file 'cookbooks/frozencook/metadata.rb', 'version "1.0.0" # This is different'
+
+ before do
+ file 'cookbooks/frozencook/metadata.rb', cb_metadata("frozencook", "1.0.0", "# This is different")
+ end
it 'knife upload fails to upload the frozen cookbook' do
knife('upload /cookbooks/frozencook').should_fail "ERROR: /cookbooks failed to write: Cookbook frozencook is frozen\n"
@@ -456,12 +516,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 upload /cookbooks/x uploads the local version' do
knife('diff --name-status /cookbooks').should_succeed <<EOM
@@ -481,8 +545,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 upload /cookbooks/x uploads the local version' do
knife('upload --purge /cookbooks/x').should_succeed <<EOM
Updated /cookbooks/x
@@ -492,7 +559,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 upload /cookbooks/x uploads the local version' do
knife('diff --name-status /cookbooks').should_succeed <<EOM
@@ -512,7 +581,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 upload /cookbooks/x uploads the new version' do
knife('upload --purge /cookbooks/x').should_succeed <<EOM
@@ -524,9 +595,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 upload tries and fails' do
knife('upload /environments/x.json').should_fail "WARN: Parse error reading #{path_to('environments/x.json')} as JSON: A JSON text must at least contain two octets!\nERROR: /environments/x.json failed to write: Parse error reading JSON: A JSON text must at least contain two octets!\n"
knife('diff --name-status /environments/x.json').should_succeed "M\t/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"
@@ -534,7 +611,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 upload fails' do
knife('upload /environments/x.json').should_fail "ERROR: /environments/x.json failed to write: Name must be 'x' (is 'y')\n"
knife('diff --name-status /environments/x.json').should_succeed "M\t/environments/x.json\n"
@@ -542,7 +621,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 upload succeeds' do
knife('upload /environments/x.json').should_succeed "Updated /environments/x.json\n"
knife('diff --name-status /environments/x.json').should_succeed ''
@@ -552,7 +633,9 @@ EOM
when_the_chef_server 'is empty' do
when_the_repository 'has an environment with bad JSON' do
- file 'environments/x.json', '{'
+ before do
+ file 'environments/x.json', '{'
+ end
it 'knife upload tries and fails' do
knife('upload /environments/x.json').should_fail "ERROR: /environments failed to create_child: Parse error reading JSON creating child 'x.json': A JSON text must at least contain two octets!\n"
knife('diff --name-status /environments/x.json').should_succeed "A\t/environments/x.json\n"
@@ -560,7 +643,9 @@ EOM
end
when_the_repository 'has an 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 upload fails' do
knife('upload /environments/x.json').should_fail "ERROR: /environments failed to create_child: Error creating 'x.json': Name must be 'x' (is 'y')\n"
knife('diff --name-status /environments/x.json').should_succeed "A\t/environments/x.json\n"
@@ -568,7 +653,10 @@ EOM
end
when_the_repository 'has an 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 upload succeeds' do
knife('upload /environments/x.json').should_succeed "Created /environments/x.json\n"
knife('diff --name-status /environments/x.json').should_succeed ''
@@ -576,7 +664,9 @@ EOM
end
when_the_repository 'has a data bag with no id in the file' do
- file 'data_bags/bag/x.json', { 'foo' => 'bar' }
+ before do
+ file 'data_bags/bag/x.json', { 'foo' => 'bar' }
+ end
it 'knife upload succeeds' do
knife('upload /data_bags/bag/x.json').should_succeed "Created /data_bags/bag\nCreated /data_bags/bag/x.json\n"
knife('diff --name-status /data_bags/bag/x.json').should_succeed ''
@@ -587,22 +677,27 @@ 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 upload does nothing' do
knife('upload /').should_succeed ''
@@ -641,17 +736,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 upload makes no changes' do
knife('upload /cookbooks/x-1.0.0').should_succeed ''
@@ -664,7 +761,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 upload changes the role' do
knife('upload /').should_succeed "Updated /roles/x.json\n"
@@ -673,7 +772,9 @@ 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": {
@@ -690,6 +791,8 @@ EOM
]
}
EOM
+ end
+
it 'knife upload / does not change anything' do
knife('upload /').should_succeed ''
knife('diff --name-status /').should_succeed ''
@@ -697,16 +800,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', cb_metadata('x', '2.0.0')
+ file 'cookbooks/y-1.0.0/metadata.rb', cb_metadata('y', '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 upload adds the new files' do
knife('upload /').should_succeed <<EOM
@@ -763,7 +868,9 @@ EOM
end
context 'when current directory is top level' do
- cwd '.'
+ before do
+ cwd '.'
+ end
it 'knife upload with no parameters reports an error' do
knife('upload').should_fail "FATAL: Must specify at least one argument. If you want to upload everything in this directory, type \"knife upload .\"\n", :stdout => /USAGE/
end
@@ -774,8 +881,10 @@ EOM
# 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', {}
- file 'data_bags/x/z.json', {}
+ before do
+ file 'data_bags/x/y.json', {}
+ file 'data_bags/x/z.json', {}
+ end
it 'knife upload of one data bag item itself succeeds' do
knife('upload /data_bags/x/y.json').should_succeed <<EOM
@@ -790,11 +899,15 @@ EOM
end
when_the_chef_server 'has three data bag items' do
- data_bag 'x', { 'deleted' => {}, 'modified' => {}, 'unmodified' => {} }
+ before do
+ data_bag 'x', { 'deleted' => {}, 'modified' => {}, 'unmodified' => {} }
+ end
when_the_repository 'has a modified, unmodified, added and deleted data bag item' do
- file 'data_bags/x/added.json', {}
- file 'data_bags/x/modified.json', { 'foo' => 'bar' }
- file 'data_bags/x/unmodified.json', {}
+ before do
+ file 'data_bags/x/added.json', {}
+ file 'data_bags/x/modified.json', { 'foo' => 'bar' }
+ file 'data_bags/x/unmodified.json', {}
+ end
it 'knife upload of the modified file succeeds' do
knife('upload /data_bags/x/modified.json').should_succeed <<EOM
@@ -857,7 +970,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 upload fails' do
knife('upload').should_fail "FATAL: Must specify at least one argument. If you want to upload everything in this directory, type \"knife upload .\"\n", :stdout => /USAGE/
end
@@ -885,11 +1000,15 @@ EOM
# upload of a file is designed not to work at present. Make sure that is the
# case.
when_the_chef_server 'has a cookbook' do
- cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"', 'z.rb' => '' }
+ before do
+ cookbook 'x', '1.0.0', { 'z.rb' => '' }
+ end
when_the_repository 'has a modified, extra and missing file for the cookbook' do
- file 'cookbooks/x-1.0.0/metadata.rb', 'version "1.0.0"'
- file 'cookbooks/x-1.0.0/y.rb', 'hi'
+ before do
+ file 'cookbooks/x-1.0.0/metadata.rb', cb_metadata('x', '1.0.0', '#modified')
+ file 'cookbooks/x-1.0.0/y.rb', 'hi'
+ end
it 'knife upload of any individual file fails' do
knife('upload /cookbooks/x-1.0.0/metadata.rb').should_fail "ERROR: /cookbooks/x-1.0.0/metadata.rb cannot be updated.\n"
@@ -916,7 +1035,9 @@ EOM
end
when_the_repository 'has a missing file for the cookbook' do
- file 'cookbooks/x-1.0.0/metadata.rb', 'version "1.0.0"'
+ before do
+ file 'cookbooks/x-1.0.0/metadata.rb', cb_metadata('x', "1.0.0")
+ end
it 'knife upload of the cookbook succeeds' do
knife('upload /cookbooks/x-1.0.0').should_succeed <<EOM
@@ -927,9 +1048,11 @@ EOM
end
when_the_repository 'has an extra file for the cookbook' do
- file 'cookbooks/x-1.0.0/metadata.rb', 'version "1.0.0"'
- file 'cookbooks/x-1.0.0/z.rb', ''
- file 'cookbooks/x-1.0.0/blah.rb', ''
+ before do
+ file 'cookbooks/x-1.0.0/metadata.rb', cb_metadata('x', '1.0.0')
+ file 'cookbooks/x-1.0.0/z.rb', ''
+ file 'cookbooks/x-1.0.0/blah.rb', ''
+ end
it 'knife upload of the cookbook succeeds' do
knife('upload /cookbooks/x-1.0.0').should_succeed <<EOM
@@ -941,12 +1064,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 upload /cookbooks uploads the local version' do
knife('diff --name-status /cookbooks').should_succeed <<EOM
@@ -962,8 +1089,10 @@ 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 upload /cookbooks uploads the local version' do
knife('upload --purge /cookbooks').should_succeed <<EOM
Updated /cookbooks/x-1.0.0
@@ -974,7 +1103,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 upload /cookbooks/x uploads the local version' do
knife('diff --name-status /cookbooks').should_succeed <<EOM
@@ -990,7 +1121,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 upload /cookbooks/x uploads the new version' do
knife('upload --purge /cookbooks').should_succeed <<EOM
@@ -1003,9 +1136,14 @@ 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 upload tries and fails' do
knife('upload /environments/x.json').should_fail "WARN: Parse error reading #{path_to('environments/x.json')} as JSON: A JSON text must at least contain two octets!\nERROR: /environments/x.json failed to write: Parse error reading JSON: A JSON text must at least contain two octets!\n"
knife('diff --name-status /environments/x.json').should_succeed "M\t/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"
@@ -1013,7 +1151,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 upload fails' do
knife('upload /environments/x.json').should_fail "ERROR: /environments/x.json failed to write: Name must be 'x' (is 'y')\n"
knife('diff --name-status /environments/x.json').should_succeed "M\t/environments/x.json\n"
@@ -1021,7 +1161,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 upload succeeds' do
knife('upload /environments/x.json').should_succeed "Updated /environments/x.json\n"
knife('diff --name-status /environments/x.json').should_succeed ''
@@ -1031,7 +1173,9 @@ EOM
when_the_chef_server 'is empty' do
when_the_repository 'has an environment with bad JSON' do
- file 'environments/x.json', '{'
+ before do
+ file 'environments/x.json', '{'
+ end
it 'knife upload tries and fails' do
knife('upload /environments/x.json').should_fail "ERROR: /environments failed to create_child: Parse error reading JSON creating child 'x.json': A JSON text must at least contain two octets!\n"
knife('diff --name-status /environments/x.json').should_succeed "A\t/environments/x.json\n"
@@ -1039,7 +1183,9 @@ EOM
end
when_the_repository 'has an 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 upload fails' do
knife('upload /environments/x.json').should_fail "ERROR: /environments failed to create_child: Error creating 'x.json': Name must be 'x' (is 'y')\n"
knife('diff --name-status /environments/x.json').should_succeed "A\t/environments/x.json\n"
@@ -1047,7 +1193,9 @@ EOM
end
when_the_repository 'has an 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 upload succeeds' do
knife('upload /environments/x.json').should_succeed "Created /environments/x.json\n"
knife('diff --name-status /environments/x.json').should_succeed ''
@@ -1055,7 +1203,9 @@ EOM
end
when_the_repository 'has a data bag with no id in the file' do
- file 'data_bags/bag/x.json', { 'foo' => 'bar' }
+ before do
+ file 'data_bags/bag/x.json', { 'foo' => 'bar' }
+ end
it 'knife upload succeeds' do
knife('upload /data_bags/bag/x.json').should_succeed "Created /data_bags/bag\nCreated /data_bags/bag/x.json\n"
knife('diff --name-status /data_bags/bag/x.json').should_succeed ''
@@ -1065,9 +1215,14 @@ EOM
end # with versioned cookbooks
when_the_chef_server 'has a user' do
- user 'x', {}
+ before do
+ user 'x', {}
+ end
+
when_the_repository 'has the same user with json_class in it' do
- file 'users/x.json', { 'admin' => true, 'json_class' => 'Chef::WebUIUser' }
+ before do
+ file 'users/x.json', { 'admin' => true, 'json_class' => 'Chef::WebUIUser' }
+ end
it 'knife upload /users/x.json succeeds' do
knife('upload /users/x.json').should_succeed "Updated /users/x.json\n"
end
diff --git a/spec/integration/recipes/lwrp_inline_resources_spec.rb b/spec/integration/recipes/lwrp_inline_resources_spec.rb
index df666eaaa9..9e2cf3fc8d 100644
--- a/spec/integration/recipes/lwrp_inline_resources_spec.rb
+++ b/spec/integration/recipes/lwrp_inline_resources_spec.rb
@@ -2,7 +2,7 @@ require 'support/shared/integration/integration_helper'
require 'chef/mixin/shell_out'
describe "LWRPs with inline resources" do
- extend IntegrationSupport
+ include IntegrationSupport
include Chef::Mixin::ShellOut
let(:chef_dir) { File.join(File.dirname(__FILE__), "..", "..", "..", "bin") }
@@ -19,22 +19,23 @@ describe "LWRPs with inline resources" do
let(:chef_client) { "ruby #{chef_dir}/chef-client" }
when_the_repository "has a cookbook with a nested LWRP" do
- directory 'cookbooks/x' do
+ before do
+ directory 'cookbooks/x' do
- file 'resources/do_nothing.rb', <<EOM
+ file 'resources/do_nothing.rb', <<EOM
actions :create, :nothing
default_action :create
EOM
- file 'providers/do_nothing.rb', <<EOM
+ file 'providers/do_nothing.rb', <<EOM
action :create do
end
EOM
- file 'resources/my_machine.rb', <<EOM
+ file 'resources/my_machine.rb', <<EOM
actions :create, :nothing
default_action :create
EOM
- file 'providers/my_machine.rb', <<EOM
+ file 'providers/my_machine.rb', <<EOM
use_inline_resources
action :create do
x_do_nothing 'a'
@@ -42,12 +43,13 @@ action :create do
end
EOM
- file 'recipes/default.rb', <<EOM
+ file 'recipes/default.rb', <<EOM
x_my_machine "me"
x_my_machine "you"
EOM
- end # directory 'cookbooks/x'
+ end # directory 'cookbooks/x'
+ end
it "should complete with success" do
file 'config/client.rb', <<EOM
diff --git a/spec/integration/solo/solo_spec.rb b/spec/integration/solo/solo_spec.rb
index 23ec8d0bad..b10ff379e2 100644
--- a/spec/integration/solo/solo_spec.rb
+++ b/spec/integration/solo/solo_spec.rb
@@ -6,14 +6,16 @@ require 'timeout'
require 'fileutils'
describe "chef-solo" do
- extend IntegrationSupport
+ include IntegrationSupport
include Chef::Mixin::ShellOut
let(:chef_dir) { File.join(File.dirname(__FILE__), "..", "..", "..") }
when_the_repository "has a cookbook with a basic recipe" do
- file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
- file 'cookbooks/x/recipes/default.rb', 'puts "ITWORKS"'
+ before do
+ file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
+ file 'cookbooks/x/recipes/default.rb', 'puts "ITWORKS"'
+ end
it "should complete with success" do
file 'config/solo.rb', <<EOM
@@ -43,11 +45,13 @@ E
end
when_the_repository "has a cookbook with an undeclared dependency" do
- file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
- file 'cookbooks/x/recipes/default.rb', 'include_recipe "ancient::aliens"'
+ before do
+ file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
+ file 'cookbooks/x/recipes/default.rb', 'include_recipe "ancient::aliens"'
- file 'cookbooks/ancient/metadata.rb', 'version "1.0.0"'
- file 'cookbooks/ancient/recipes/aliens.rb', 'print "it was aliens"'
+ file 'cookbooks/ancient/metadata.rb', 'version "1.0.0"'
+ file 'cookbooks/ancient/recipes/aliens.rb', 'print "it was aliens"'
+ end
it "should exit with an error" do
file 'config/solo.rb', <<EOM
@@ -62,16 +66,19 @@ EOM
when_the_repository "has a cookbook with a recipe with sleep" do
- directory 'logs'
- file 'logs/runs.log', ''
- file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
- file 'cookbooks/x/recipes/default.rb', <<EOM
+ before do
+ directory 'logs'
+ file 'logs/runs.log', ''
+ file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
+ file 'cookbooks/x/recipes/default.rb', <<EOM
ruby_block "sleeping" do
block do
sleep 5
end
end
EOM
+ end
+
# Ruby 1.8.7 doesn't have Process.spawn :(
it "while running solo concurrently", :ruby_gte_19_only => true do
file 'config/solo.rb', <<EOM
diff --git a/spec/support/shared/integration/chef_zero_support.rb b/spec/support/shared/integration/chef_zero_support.rb
new file mode 100644
index 0000000000..6505f0d066
--- /dev/null
+++ b/spec/support/shared/integration/chef_zero_support.rb
@@ -0,0 +1,130 @@
+require 'tempfile'
+require 'chef_zero/server'
+require 'chef_zero/rest_request'
+
+# This is a copy of chef_zero/rspec, modified to implement contextual
+# helpers as instance_methods rather than class methods. This makes it
+# possible to use them with let bindings and other RSpec code reuse
+# mechanisms.
+#
+# Unfortunately, at the time of this writing, chef-zero master doesn't
+# work for our rspec tests, so in the interests of making forward
+# progress, we're using a modified version of the chef_zero/rspec code
+# here.
+#
+# This file should be entirely replaced by chef_zero/rspec once these
+# issues are fixed.
+module ChefZeroSupport
+ module Server
+
+ def self.server
+ @server
+ end
+ def self.server=(value)
+ @server = value
+ end
+ def self.client_key
+ @client_key
+ end
+ def self.client_key=(value)
+ @client_key = value
+ end
+ def self.request_log
+ @request_log ||= []
+ end
+ def self.clear_request_log
+ @request_log = []
+ end
+
+ end
+
+ def client(name, client)
+ ChefZeroSupport::Server.server.load_data({ 'clients' => { name => client }})
+ end
+
+ def cookbook(name, version, cookbook = {}, options = {})
+
+ auto_metadata = "name '#{name}'; version '#{version}'"
+
+ cookbook["metadata.rb"] ||= auto_metadata
+
+ ChefZeroSupport::Server.server.load_data({ 'cookbooks' => { "#{name}-#{version}" => cookbook.merge(options) }})
+ end
+
+ def data_bag(name, data_bag)
+ ChefZeroSupport::Server.server.load_data({ 'data' => { name => data_bag }})
+ end
+
+ def environment(name, environment)
+ ChefZeroSupport::Server.server.load_data({ 'environments' => { name => environment }})
+ end
+
+ def node(name, node)
+ ChefZeroSupport::Server.server.load_data({ 'nodes' => { name => node }})
+ end
+
+ def role(name, role)
+ ChefZeroSupport::Server.server.load_data({ 'roles' => { name => role }})
+ end
+
+ def user(name, user)
+ ChefZeroSupport::Server.server.load_data({ 'users' => { name => user }})
+ end
+
+ RSpec.shared_context "With chef-zero running" do
+ before :each do
+
+ default_opts = {:port => 8900, :signals => false, :log_requests => true}
+ server_opts = if self.respond_to?(:chef_zero_opts)
+ default_opts.merge(chef_zero_opts)
+ else
+ default_opts
+ end
+
+ if ChefZeroSupport::Server.server && server_opts.any? { |opt, value| ChefZeroSupport::Server.server.options[opt] != value }
+ ChefZeroSupport::Server.server.stop
+ ChefZeroSupport::Server.server = nil
+ end
+
+ unless ChefZeroSupport::Server.server
+ # TODO: can this be logged easily?
+ # pp :zero_opts => server_opts
+
+ # Set up configuration so that clients will point to the server
+ ChefZeroSupport::Server.server = ChefZero::Server.new(server_opts)
+ ChefZeroSupport::Server.client_key = Tempfile.new(['chef_zero_client_key', '.pem'])
+ ChefZeroSupport::Server.client_key.write(ChefZero::PRIVATE_KEY)
+ ChefZeroSupport::Server.client_key.close
+ # Start the server
+ ChefZeroSupport::Server.server.start_background
+ ChefZeroSupport::Server.server.on_response do |request, response|
+ ChefZeroSupport::Server.request_log << [ request, response ]
+ end
+ else
+ ChefZeroSupport::Server.server.clear_data
+ end
+ ChefZeroSupport::Server.clear_request_log
+
+ if defined?(Chef::Config)
+ @old_chef_server_url = Chef::Config.chef_server_url
+ @old_node_name = Chef::Config.node_name
+ @old_client_key = Chef::Config.client_key
+ Chef::Config.chef_server_url = ChefZeroSupport::Server.server.url
+ Chef::Config.node_name = 'admin'
+ Chef::Config.client_key = ChefZeroSupport::Server.client_key.path
+ Chef::Config.http_retry_count = 0
+ end
+ end
+
+ if defined?(Chef::Config)
+ after :each do
+ Chef::Config.chef_server_url = @old_chef_server_url
+ Chef::Config.node_name = @old_node_name
+ Chef::Config.client_key = @old_client_key
+ end
+ end
+
+ end
+
+end
+
diff --git a/spec/support/shared/integration/integration_helper.rb b/spec/support/shared/integration/integration_helper.rb
index abed4c2715..9b0f17d378 100644
--- a/spec/support/shared/integration/integration_helper.rb
+++ b/spec/support/shared/integration/integration_helper.rb
@@ -20,131 +20,133 @@
require 'tmpdir'
require 'fileutils'
require 'chef/config'
-require 'chef_zero/rspec'
+
+# Temporarily use our own copy of chef-zero rspec integration.
+# See support/shared/integration/chef_zero_support for details
+#require 'chef_zero/rspec'
+require 'support/shared/integration/chef_zero_support'
+
require 'json'
require 'support/shared/integration/knife_support'
require 'support/shared/integration/app_server_support'
require 'spec_helper'
module IntegrationSupport
- include ChefZero::RSpec
-
- def when_the_repository(description, *args, &block)
- context "When the local repository #{description}", *args do
- before :each do
- raise "Can only create one directory per test" if @repository_dir
- @repository_dir = Dir.mktmpdir('chef_repo')
- Chef::Config.chef_repo_path = @repository_dir
- %w(client cookbook data_bag environment node role user).each do |object_name|
- Chef::Config.delete("#{object_name}_path".to_sym)
- end
- end
+ include ChefZeroSupport
- after :each do
- if @repository_dir
- begin
- %w(client cookbook data_bag environment node role user).each do |object_name|
- Chef::Config.delete("#{object_name}_path".to_sym)
- end
- Chef::Config.delete(:chef_repo_path)
- FileUtils.remove_entry_secure(@repository_dir)
- ensure
- @repository_dir = nil
- end
- end
- end
+ module ClassMethods
- def directory(relative_path, &block)
- old_parent_path = @parent_path
- @parent_path = path_to(relative_path)
- FileUtils.mkdir_p(@parent_path)
- instance_eval(&block) if block
- @parent_path = old_parent_path
+ def when_the_chef_server(desc, *tags, &block)
+ context("when the chef server #{desc}", *tags) do
+ #include ChefZero::RSpec::Fixtures
+ include_context "With chef-zero running"
+ module_eval(&block)
end
+ end
- def file(relative_path, contents)
- filename = path_to(relative_path)
- dir = File.dirname(filename)
- FileUtils.mkdir_p(dir) unless dir == '.'
- File.open(filename, 'w') do |file|
- raw = case contents
- when Hash
- JSON.pretty_generate(contents)
- when Array
- contents.join("\n")
- else
- contents
- end
- file.write(raw)
- end
+ def when_the_repository(desc, *tags, &block)
+ context("when the chef repo #{desc}", *tags) do
+ include_context "with a chef repo"
+ module_eval(&block)
end
+ end
- def symlink(relative_path, relative_dest)
- filename = path_to(relative_path)
- dir = File.dirname(filename)
- FileUtils.mkdir_p(dir) unless dir == '.'
- dest_filename = path_to(relative_dest)
- File.symlink(dest_filename, filename)
+ def with_versioned_cookbooks(&block)
+ context("with versioned cookbooks") do
+ include_context "with versioned cookbooks"
+ module_eval(&block)
end
+ end
+ end
- def path_to(relative_path)
- File.expand_path(relative_path, (@parent_path || @repository_dir))
- end
+ def self.included(includer_class)
+ includer_class.extend(ClassMethods)
+ end
- def self.path_to(relative_path)
- File.expand_path(relative_path, (@parent_path || @repository_dir))
- end
+ def directory(relative_path, &block)
+ old_parent_path = @parent_path
+ @parent_path = path_to(relative_path)
+ FileUtils.mkdir_p(@parent_path)
+ instance_eval(&block) if block
+ @parent_path = old_parent_path
+ end
- def self.directory(relative_path, &block)
- before :each do
- directory(relative_path, &block)
- end
- end
+ def file(relative_path, contents)
+ filename = path_to(relative_path)
+ dir = File.dirname(filename)
+ FileUtils.mkdir_p(dir) unless dir == '.'
+ File.open(filename, 'w') do |file|
+ raw = case contents
+ when Hash
+ JSON.pretty_generate(contents)
+ when Array
+ contents.join("\n")
+ else
+ contents
+ end
+ file.write(raw)
+ end
+ end
- def self.file(relative_path, contents)
- before :each do
- file(relative_path, contents)
- end
- end
+ def symlink(relative_path, relative_dest)
+ filename = path_to(relative_path)
+ dir = File.dirname(filename)
+ FileUtils.mkdir_p(dir) unless dir == '.'
+ dest_filename = path_to(relative_dest)
+ File.symlink(dest_filename, filename)
+ end
- def self.symlink(relative_path, relative_dest)
- before :each do
- symlink(relative_path, relative_dest)
- end
+ def path_to(relative_path)
+ File.expand_path(relative_path, (@parent_path || @repository_dir))
+ end
+
+ def cb_metadata(name, version, extra_text="")
+ "name '#{name}'; version '#{version}'#{extra_text}"
+ end
+
+ def cwd(relative_path)
+ @old_cwd = Dir.pwd
+ Dir.chdir(path_to(relative_path))
+ end
+
+ RSpec.shared_context "with a chef repo" do
+ before :each do
+ raise "Can only create one directory per test" if @repository_dir
+ @repository_dir = Dir.mktmpdir('chef_repo')
+ Chef::Config.chef_repo_path = @repository_dir
+ %w(client cookbook data_bag environment node role user).each do |object_name|
+ Chef::Config.delete("#{object_name}_path".to_sym)
end
+ end
- def self.cwd(relative_path)
- before :each do
- @old_cwd = Dir.pwd
- Dir.chdir(path_to(relative_path))
- end
- after :each do
- Dir.chdir(@old_cwd)
+ after :each do
+ if @repository_dir
+ begin
+ %w(client cookbook data_bag environment node role user).each do |object_name|
+ Chef::Config.delete("#{object_name}_path".to_sym)
+ end
+ Chef::Config.delete(:chef_repo_path)
+ FileUtils.remove_entry_secure(@repository_dir)
+ ensure
+ @repository_dir = nil
end
end
-
- instance_eval(&block)
+ Dir.chdir(@old_cwd) if @old_cwd
end
+
end
# Versioned cookbooks
- def with_versioned_cookbooks(_metadata = {}, &block)
- _m = { :versioned_cookbooks => true }.merge(_metadata)
- context 'with versioned cookbooks', _m do
- before(:each) { Chef::Config[:versioned_cookbooks] = true }
- after(:each) { Chef::Config.delete(:versioned_cookbooks) }
- instance_eval(&block)
- end
+ RSpec.shared_context 'with versioned cookbooks', :versioned_cookbooks => true do
+ before(:each) { Chef::Config[:versioned_cookbooks] = true }
+ after(:each) { Chef::Config.delete(:versioned_cookbooks) }
end
- def without_versioned_cookbooks(_metadata = {}, &block)
- _m = { :versioned_cookbooks => false }.merge(_metadata)
- context 'with versioned cookbooks', _m do
- # Just make sure this goes back to default
- before(:each) { Chef::Config[:versioned_cookbooks] = false }
- after(:each) { Chef::Config.delete(:versioned_cookbooks) }
- instance_eval(&block)
- end
+ RSpec.shared_context "without versioned cookbooks", :versioned_cookbooks => false do
+ # Just make sure this goes back to default
+ before(:each) { Chef::Config[:versioned_cookbooks] = false }
+ after(:each) { Chef::Config.delete(:versioned_cookbooks) }
end
+
end