require 'support/integration_helper' require 'chef/knife/list_essentials' require 'chef/knife/show_essentials' describe 'chef_repo_path tests' do extend 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', {} end context 'when all _paths are set to alternates' do before :each do %w(client cookbook data_bag environment node role user).each do |object_name| Chef::Config["#{object_name}_path".to_sym] = File.join(Chef::Config.chef_repo_path, "#{object_name}s2") end Chef::Config.chef_repo_path = File.join(Chef::Config.chef_repo_path, 'chef_repo2') end context 'when cwd is at the top level' do 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' 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' it 'knife list --local -Rfp lists everything' do knife('list --local -Rfp').should_succeed < "WARN: Cookbook 'blah' is empty or entirely chefignored at #{Chef::Config.cookbook_path[0]}/blah\n") /cookbooks/blah/ /cookbooks/blah/metadata.rb /cookbooks/cookbook1/ /cookbooks/cookbook1/metadata.rb /cookbooks/cookbook2/ /cookbooks/cookbook2/metadata.rb EOM end 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', '' it 'knife list -Rfp cookbooks shows files in the first cookbook and not the second' do knife('list --local -Rfp /cookbooks').should_succeed(< "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/ /cookbooks/blah/metadata.json /cookbooks/cookbook1/ /cookbooks/cookbook1/metadata.rb /cookbooks/cookbook2/ /cookbooks/cookbook2/metadata.rb EOM end 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', '' it 'knife list -Rfp data_bags shows files in blah' do knife('list --local -Rfp /data_bags').should_succeed < "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/ /data_bags/bag/item.json /data_bags/bag2/ /data_bags/bag2/item2.json /data_bags/blah/ /data_bags/blah/item1.json EOM end 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', {} it 'knife show /environments/blah.json succeeds' do knife('show --local /environments/blah.json').should_succeed <