# # Author:: John Keiser () # Copyright:: Copyright (c) 2013 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. require "support/shared/integration/integration_helper" require "support/shared/context/config" require "chef/knife/list" require "chef/knife/show" describe "chef_repo_path tests", :workstation do include IntegrationSupport include KnifeSupport let(:error_rel_path_outside_repo) { /^ERROR: Attempt to use relative path '' when current directory is outside the repository path/ } # TODO alternate repo_path / *_path context "alternate *_path" do when_the_repository "has clients and clients2, cookbooks and cookbooks2, etc." do 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 Chef::Config.delete(:chef_repo_path) knife("list --local -Rfp --chef-repo-path #{path_to('chef_repo2')} /").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 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(< "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 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 < "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 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 <