diff options
Diffstat (limited to 'spec/integration')
73 files changed, 8428 insertions, 3616 deletions
diff --git a/spec/integration/client/client_spec.rb b/spec/integration/client/client_spec.rb index 314a9310be..7a8059066a 100644 --- a/spec/integration/client/client_spec.rb +++ b/spec/integration/client/client_spec.rb @@ -1,30 +1,29 @@ -require 'support/shared/integration/integration_helper' -require 'chef/mixin/shell_out' -require 'tiny_server' -require 'tmpdir' - +require "support/shared/integration/integration_helper" +require "chef/mixin/shell_out" +require "tiny_server" +require "tmpdir" describe "chef-client" do def recipes_filename - File.join(CHEF_SPEC_DATA, 'recipes.tgz') + File.join(CHEF_SPEC_DATA, "recipes.tgz") end - def start_tiny_server(server_opts={}) + def start_tiny_server(server_opts = {}) @server = TinyServer::Manager.new(server_opts) @server.start - @api = TinyServer::API.instance + @api = TinyServer::API.instance @api.clear # # trivial endpoints # # just a normal file # (expected_content should be uncompressed) - @api.get("/recipes.tgz", 200) { + @api.get("/recipes.tgz", 200) do File.open(recipes_filename, "rb") do |f| f.read end - } + end end def stop_tiny_server @@ -47,14 +46,15 @@ describe "chef-client" do # we're running `chef-client` from the source tree and not the external one. # cf. CHEF-4914 let(:chef_client) { "ruby '#{chef_dir}/chef-client' --minimal-ohai" } + let(:chef_solo) { "ruby '#{chef_dir}/chef-solo' --minimal-ohai" } - let(:critical_env_vars) { %w(PATH RUBYOPT BUNDLE_GEMFILE GEM_PATH).map {|o| "#{o}=#{ENV[o]}"} .join(' ') } + let(:critical_env_vars) { %w{_ORIGINAL_GEM_PATH GEM_PATH GEM_HOME GEM_ROOT BUNDLE_BIN_PATH BUNDLE_GEMFILE RUBYLIB RUBYOPT RUBY_ENGINE RUBY_ROOT RUBY_VERSION PATH}.map { |o| "#{o}=#{ENV[o]}" } .join(" ") } when_the_repository "has a cookbook with a no-op recipe" do - before { file 'cookbooks/x/recipes/default.rb', '' } + before { file "cookbooks/x/recipes/default.rb", "" } it "should complete with success" do - file 'config/client.rb', <<EOM + file "config/client.rb", <<EOM local_mode true cookbook_path "#{path_to('cookbooks')}" EOM @@ -63,7 +63,7 @@ EOM end it "should complete successfully with no other environment variables", :skip => (Chef::Platform.windows?) do - file 'config/client.rb', <<EOM + file "config/client.rb", <<EOM local_mode true cookbook_path "#{path_to('cookbooks')}" EOM @@ -79,7 +79,7 @@ EOM end it "should complete successfully with --no-listen" do - file 'config/client.rb', <<EOM + file "config/client.rb", <<EOM local_mode true cookbook_path "#{path_to('cookbooks')}" EOM @@ -90,32 +90,32 @@ EOM it "should be able to node.save with bad utf8 characters in the node data" do file "cookbooks/x/attributes/default.rb", 'default["badutf8"] = "Elan Ruusam\xE4e"' - result = shell_out("#{chef_client} -z -r 'x::default' --disable-config", :cwd => path_to('')) + result = shell_out("#{chef_client} -z -r 'x::default' --disable-config", :cwd => path_to("")) result.error! end - context 'and no config file' do - it 'should complete with success when cwd is just above cookbooks and paths are not specified' do - result = shell_out("#{chef_client} -z -o 'x::default' --disable-config", :cwd => path_to('')) + context "and no config file" do + it "should complete with success when cwd is just above cookbooks and paths are not specified" do + result = shell_out("#{chef_client} -z -o 'x::default' --disable-config", :cwd => path_to("")) result.error! end - it 'should complete with success when cwd is below cookbooks and paths are not specified' do - result = shell_out("#{chef_client} -z -o 'x::default' --disable-config", :cwd => path_to('cookbooks/x')) + it "should complete with success when cwd is below cookbooks and paths are not specified" do + result = shell_out("#{chef_client} -z -o 'x::default' --disable-config", :cwd => path_to("cookbooks/x")) result.error! end - it 'should fail when cwd is below high above and paths are not specified' do - result = shell_out("#{chef_client} -z -o 'x::default' --disable-config", :cwd => File.expand_path('..', path_to(''))) + it "should fail when cwd is below high above and paths are not specified" do + result = shell_out("#{chef_client} -z -o 'x::default' --disable-config", :cwd => File.expand_path("..", path_to(""))) expect(result.exitstatus).to eq(1) end end - context 'and a config file under .chef/knife.rb' do - before { file '.chef/knife.rb', 'xxx.xxx' } + context "and a config file under .chef/knife.rb" do + 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'", :cwd => path_to('')) + it "should load .chef/knife.rb when -z is specified" do + result = shell_out("#{chef_client} -z -o 'x::default'", :cwd => path_to("")) # FATAL: Configuration error NoMethodError: undefined method `xxx' for nil:NilClass expect(result.stdout).to include("xxx") end @@ -123,7 +123,7 @@ EOM end it "should complete with success" do - file 'config/client.rb', <<EOM + file "config/client.rb", <<EOM local_mode true cookbook_path "#{path_to('cookbooks')}" EOM @@ -132,9 +132,9 @@ EOM result.error! end - context 'and a private key' do + context "and a private key" do before do - file 'mykey.pem', <<EOM + file "mykey.pem", <<EOM -----BEGIN RSA PRIVATE KEY----- MIIEogIBAAKCAQEApubutqtYYQ5UiA9QhWP7UvSmsfHsAoPKEVVPdVW/e8Svwpyf 0Xef6OFWVmBE+W442ZjLOe2y6p2nSnaq4y7dg99NFz6X+16mcKiCbj0RCiGqCvCk @@ -166,7 +166,7 @@ EOM end it "should complete with success even with a client key" do - file 'config/client.rb', <<EOM + file "config/client.rb", <<EOM local_mode true client_key #{path_to('mykey.pem').inspect} cookbook_path #{path_to('cookbooks').inspect} @@ -177,19 +177,19 @@ EOM end it "should run recipes specified directly on the command line" do - file 'config/client.rb', <<EOM + file "config/client.rb", <<EOM local_mode true client_key #{path_to('mykey.pem').inspect} cookbook_path #{path_to('cookbooks').inspect} EOM - file 'arbitrary.rb', <<EOM + file "arbitrary.rb", <<EOM file #{path_to('tempfile.txt').inspect} do content '1' end EOM - file 'arbitrary2.rb', <<EOM + file "arbitrary2.rb", <<EOM file #{path_to('tempfile2.txt').inspect} do content '2' end @@ -198,57 +198,57 @@ EOM result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" #{path_to('arbitrary.rb')} #{path_to('arbitrary2.rb')}", :cwd => chef_dir) result.error! - expect(IO.read(path_to('tempfile.txt'))).to eq('1') - expect(IO.read(path_to('tempfile2.txt'))).to eq('2') + expect(IO.read(path_to("tempfile.txt"))).to eq("1") + expect(IO.read(path_to("tempfile2.txt"))).to eq("2") end it "should run recipes specified as relative paths directly on the command line" do - file 'config/client.rb', <<EOM + file "config/client.rb", <<EOM local_mode true client_key #{path_to('mykey.pem').inspect} cookbook_path #{path_to('cookbooks').inspect} EOM - file 'arbitrary.rb', <<EOM + file "arbitrary.rb", <<EOM file #{path_to('tempfile.txt').inspect} do content '1' end EOM - result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" arbitrary.rb", :cwd => path_to('')) + result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" arbitrary.rb", :cwd => path_to("")) result.error! - expect(IO.read(path_to('tempfile.txt'))).to eq('1') + expect(IO.read(path_to("tempfile.txt"))).to eq("1") end it "should run recipes specified directly on the command line AFTER recipes in the run list" do - file 'config/client.rb', <<EOM + file "config/client.rb", <<EOM local_mode true client_key #{path_to('mykey.pem').inspect} cookbook_path #{path_to('cookbooks').inspect} EOM - file 'cookbooks/x/recipes/constant_definition.rb', <<EOM + file "cookbooks/x/recipes/constant_definition.rb", <<EOM class ::Blah THECONSTANT = '1' end EOM - file 'arbitrary.rb', <<EOM + file "arbitrary.rb", <<EOM file #{path_to('tempfile.txt').inspect} do content ::Blah::THECONSTANT end EOM - result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" -o x::constant_definition arbitrary.rb", :cwd => path_to('')) + result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" -o x::constant_definition arbitrary.rb", :cwd => path_to("")) result.error! - expect(IO.read(path_to('tempfile.txt'))).to eq('1') + expect(IO.read(path_to("tempfile.txt"))).to eq("1") end end it "should complete with success when passed the -z flag" do - file 'config/client.rb', <<EOM + file "config/client.rb", <<EOM chef_server_url 'http://omg.com/blah' cookbook_path "#{path_to('cookbooks')}" EOM @@ -258,7 +258,7 @@ EOM end it "should complete with success when passed the --local-mode flag" do - file 'config/client.rb', <<EOM + file "config/client.rb", <<EOM chef_server_url 'http://omg.com/blah' cookbook_path "#{path_to('cookbooks')}" EOM @@ -268,7 +268,7 @@ EOM end it "should not print SSL warnings when running in local-mode" do - file 'config/client.rb', <<EOM + file "config/client.rb", <<EOM chef_server_url 'http://omg.com/blah' cookbook_path "#{path_to('cookbooks')}" EOM @@ -279,7 +279,7 @@ EOM end it "should complete with success when passed -z and --chef-zero-port" do - file 'config/client.rb', <<EOM + file "config/client.rb", <<EOM chef_server_url 'http://omg.com/blah' cookbook_path "#{path_to('cookbooks')}" EOM @@ -289,7 +289,7 @@ EOM end it "should complete with success when setting the run list with -r" do - file 'config/client.rb', <<EOM + file "config/client.rb", <<EOM chef_server_url 'http://omg.com/blah' cookbook_path "#{path_to('cookbooks')}" EOM @@ -302,7 +302,7 @@ EOM end it "should complete with success when using --profile-ruby and output a profile file" do - file 'config/client.rb', <<EOM + file "config/client.rb", <<EOM local_mode true cookbook_path "#{path_to('cookbooks')}" EOM @@ -311,7 +311,7 @@ EOM end it "doesn't produce a profile when --profile-ruby is not present" do - file 'config/client.rb', <<EOM + file "config/client.rb", <<EOM local_mode true cookbook_path "#{path_to('cookbooks')}" EOM @@ -320,9 +320,74 @@ EOM end end + when_the_repository "has a cookbook that should fail chef_version checks" do + before do + file "cookbooks/x/recipes/default.rb", "" + file "cookbooks/x/metadata.rb", <<EOM +name 'x' +version '0.0.1' +chef_version '~> 999.99' +EOM + file "config/client.rb", <<EOM +local_mode true +cookbook_path "#{path_to('cookbooks')}" +EOM + end + it "should fail the chef client run" do + command = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" -o 'x::default' --no-fork", :cwd => chef_dir) + expect(command.exitstatus).to eql(1) + expect(command.stdout).to match(/Chef::Exceptions::CookbookChefVersionMismatch/) + end + end + + when_the_repository "has a cookbook that uses cheffish resources" do + before do + file "cookbooks/x/recipes/default.rb", <<-EOM + raise "Cheffish was loaded before we used any cheffish things!" if defined?(Cheffish::VERSION) + ran_block = false + got_server = with_chef_server 'https://blah.com' do + ran_block = true + run_context.cheffish.current_chef_server + end + raise "with_chef_server block was not run!" if !ran_block + raise "Cheffish was not loaded when we did cheffish things!" if !defined?(Cheffish::VERSION) + raise "current_chef_server did not return its value!" if got_server[:chef_server_url] != 'https://blah.com' + EOM + file "config/client.rb", <<-EOM + local_mode true + cookbook_path "#{path_to('cookbooks')}" + EOM + end + + it "the cheffish DSL is loaded lazily" do + command = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" -o 'x::default' --no-fork", :cwd => chef_dir) + expect(command.exitstatus).to eql(0) + end + end + + when_the_repository "has a cookbook that uses chef-provisioning resources" do + before do + file "cookbooks/x/recipes/default.rb", <<-EOM + with_driver 'blah' + EOM + file "config/client.rb", <<-EOM + local_mode true + cookbook_path "#{path_to('cookbooks')}" + EOM + end + + it "the cheffish DSL tries to load but fails (because chef-provisioning is not there)" do + # we'd need to have a custom bundle to fix this that omitted chef-provisioning, but that would dig our crazy even deeper, so lets not + skip "but if chef-provisioning is in our bundle or in our gemset then this test, very annoyingly, always fails" + command = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" -o 'x::default' --no-fork", :cwd => chef_dir) + expect(command.exitstatus).to eql(1) + expect(command.stdout).to match(/cannot load such file -- chef\/provisioning/) + end + end + when_the_repository "has a cookbook that generates deprecation warnings" do before do - file 'cookbooks/x/recipes/default.rb', <<-EOM + file "cookbooks/x/recipes/default.rb", <<-EOM class ::MyResource < Chef::Resource use_automatic_resource_name property :x, default: [] @@ -349,7 +414,7 @@ EOM end it "should output each deprecation warning only once, at the end of the run" do - file 'config/client.rb', <<EOM + file "config/client.rb", <<EOM local_mode true cookbook_path "#{path_to('cookbooks')}" # Mimick what happens when you are on the console @@ -357,7 +422,7 @@ formatters << :doc log_level :warn EOM - ENV.delete('CHEF_TREAT_DEPRECATION_WARNINGS_AS_ERRORS') + ENV.delete("CHEF_TREAT_DEPRECATION_WARNINGS_AS_ERRORS") result = shell_out!("#{chef_client} -c \"#{path_to('config/client.rb')}\" -o 'x::default'", :cwd => chef_dir) expect(result.error?).to be_falsey @@ -367,14 +432,14 @@ EOM expect(run_complete).to be >= 0 # Make sure there is exactly one result for each, and that it occurs *after* the complete message. - expect(match_indices(/nil currently does not overwrite the value of/, result.stdout)).to match([ be > run_complete ]) + expect(match_indices(/An attempt was made to change x from \[\] to nil by calling x\(nil\). In Chef 12, this does a get rather than a set. In Chef 13, this will change to set the value to nil./, result.stdout)).to match([ be > run_complete ]) end end when_the_repository "has a cookbook with only an audit recipe" do before do - file 'config/client.rb', <<EOM + file "config/client.rb", <<EOM local_mode true cookbook_path "#{path_to('cookbooks')}" audit_mode :enabled @@ -382,7 +447,7 @@ EOM end it "should exit with a zero code when there is not an audit failure" do - file 'cookbooks/audit_test/recipes/succeed.rb', <<-RECIPE + file "cookbooks/audit_test/recipes/succeed.rb", <<-RECIPE control_group "control group without top level control" do it "should succeed" do expect(2 - 2).to eq(0) @@ -396,7 +461,7 @@ end end it "should exit with a non-zero code when there is an audit failure" do - file 'cookbooks/audit_test/recipes/fail.rb', <<-RECIPE + file "cookbooks/audit_test/recipes/fail.rb", <<-RECIPE control_group "control group without top level control" do it "should fail" do expect(2 - 2).to eq(1) @@ -412,27 +477,59 @@ end # Fails on appveyor, but works locally on windows and on windows hosts in Ci. context "when using recipe-url", :skip_appveyor do - before(:all) do + before(:each) do start_tiny_server end - after(:all) do + after(:each) do stop_tiny_server end let(:tmp_dir) { Dir.mktmpdir("recipe-url") } it "should complete with success when passed -z and --recipe-url" do - file 'config/client.rb', <<EOM + file "config/client.rb", <<EOM chef_repo_path "#{tmp_dir}" EOM result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" --recipe-url=http://localhost:9000/recipes.tgz -o 'x::default' -z", :cwd => tmp_dir) result.error! end - it 'should fail when passed --recipe-url and not passed -z' do + it "should fail when passed --recipe-url and not passed -z" do result = shell_out("#{chef_client} --recipe-url=http://localhost:9000/recipes.tgz", :cwd => tmp_dir) expect(result.exitstatus).not_to eq(0) end end + + when_the_repository "has a cookbook with broken metadata.rb, but has metadata.json" do + before do + file "cookbooks/x/recipes/default.rb", "" + file "cookbooks/x/metadata.rb", <<EOM +name 'x' +version '0.0.1' +raise "TEH SADNESS" +EOM + file "cookbooks/x/metadata.json", <<EOM +{ + "name": "x", + "version": "0.0.1" +} +EOM + + file "config/client.rb", <<EOM +local_mode true +cookbook_path "#{path_to('cookbooks')}" +EOM + end + + it "the chef client run should succeed" do + command = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" -o 'x::default' --no-fork", :cwd => chef_dir) + command.error! + end + + it "a chef-solo run should succeed" do + command = shell_out("#{chef_solo} -c \"#{path_to('config/client.rb')}\" -o 'x::default' --no-fork", :cwd => chef_dir) + command.error! + end + end end diff --git a/spec/integration/client/exit_code_spec.rb b/spec/integration/client/exit_code_spec.rb new file mode 100644 index 0000000000..30020f6a3f --- /dev/null +++ b/spec/integration/client/exit_code_spec.rb @@ -0,0 +1,245 @@ + +require "support/shared/integration/integration_helper" +require "chef/mixin/shell_out" +require "tiny_server" +require "tmpdir" +require "chef/platform" + +describe "chef-client" do + + include IntegrationSupport + include Chef::Mixin::ShellOut + + let(:chef_dir) { File.join(File.dirname(__FILE__), "..", "..", "..", "bin") } + + # Invoke `chef-client` as `ruby PATH/TO/chef-client`. This ensures the + # following constraints are satisfied: + # * Windows: windows can only run batch scripts as bare executables. Rubygems + # creates batch wrappers for installed gems, but we don't have batch wrappers + # in the source tree. + # * Other `chef-client` in PATH: A common case is running the tests on a + # machine that has omnibus chef installed. In that case we need to ensure + # we're running `chef-client` from the source tree and not the external one. + # cf. CHEF-4914 + let(:chef_client) { "ruby '#{chef_dir}/chef-client' --no-fork --minimal-ohai" } + + let(:critical_env_vars) { %w{PATH RUBYOPT BUNDLE_GEMFILE GEM_PATH}.map { |o| "#{o}=#{ENV[o]}" } .join(" ") } + + when_the_repository "does not have exit_status configured" do + + def setup_client_rb + file "config/client.rb", <<EOM +local_mode true +cookbook_path "#{path_to('cookbooks')}" +EOM + end + + def setup_client_rb_with_audit_mode + file "config/client.rb", <<EOM +local_mode true +cookbook_path "#{path_to('cookbooks')}" +audit_mode :audit_only +EOM + end + + def run_chef_client_and_expect_exit_code(exit_code) + shell_out!( + "#{chef_client} -c \"#{path_to('config/client.rb')}\" -o 'x::default'", + :cwd => chef_dir, + :returns => [exit_code]) + end + + context "has a cookbook" do + context "with a library" do + context "which cannot be loaded" do + before do + file "cookbooks/x/recipes/default.rb", "" + file "cookbooks/x/libraries/error.rb", "require 'does/not/exist'" + end + + it "exits with GENERIC_FAILURE, 1" do + setup_client_rb + run_chef_client_and_expect_exit_code 1 + end + end + end + + context "with an audit recipe" do + context "which fails" do + before do + file "cookbooks/x/recipes/default.rb", <<-RECIPE +control_group "control group without top level control" do + it "should fail" do + expect(2 - 2).to eq(1) + end +end +RECIPE + end + + it "exits with GENERIC_FAILURE, 1" do + setup_client_rb_with_audit_mode + run_chef_client_and_expect_exit_code 1 + end + end + end + + context "with a recipe" do + context "which throws an error" do + before { file "cookbooks/x/recipes/default.rb", "raise 'BOOM'" } + + it "exits with GENERIC_FAILURE, 1" do + setup_client_rb + run_chef_client_and_expect_exit_code 1 + end + end + + context "with a recipe which calls Chef::Application.fatal with a non-RFC exit code" do + before { file "cookbooks/x/recipes/default.rb", "Chef::Application.fatal!('BOOM', 123)" } + + it "exits with the specified exit code" do + setup_client_rb + run_chef_client_and_expect_exit_code 123 + end + end + + context "with a recipe which calls Chef::Application.exit with a non-RFC exit code" do + before { file "cookbooks/x/recipes/default.rb", "Chef::Application.exit!('BOOM', 231)" } + + it "exits with the specified exit code" do + setup_client_rb + run_chef_client_and_expect_exit_code 231 + end + end + end + + context "when an attempt to reboot fails (like from the reboot resource)" do + before do + file "cookbooks/x/recipes/default.rb", <<EOM +raise Chef::Exceptions::RebootFailed.new +EOM + end + + it "exits with GENERIC_FAILURE, 1" do + setup_client_rb + run_chef_client_and_expect_exit_code 1 + end + end + end + end + + when_the_repository "does has exit_status enabled" do + + def setup_client_rb + file "config/client.rb", <<EOM +local_mode true +cookbook_path "#{path_to('cookbooks')}" +exit_status :enabled +EOM + end + + def setup_client_rb_with_audit_mode + file "config/client.rb", <<EOM +local_mode true +cookbook_path "#{path_to('cookbooks')}" +exit_status :enabled +audit_mode :audit_only +EOM + end + + def run_chef_client_and_expect_exit_code(exit_code) + shell_out!("#{chef_client} -c \"#{path_to('config/client.rb')}\" -o 'x::default'", + :cwd => chef_dir, + :returns => [exit_code]) + end + + context "has a cookbook" do + context "with a library" do + context "which cannot be loaded" do + before do + file "cookbooks/x/recipes/default.rb", "" + file "cookbooks/x/libraries/error.rb", "require 'does/not/exist'" + end + + it "exits with GENERIC_FAILURE, 1" do + setup_client_rb + run_chef_client_and_expect_exit_code 1 + end + end + end + + context "with an audit recipe" do + context "which fails" do + before do + file "cookbooks/x/recipes/default.rb", <<-RECIPE +control_group "control group without top level control" do + it "should fail" do + expect(4 - 4).to eq(1) + end +end +RECIPE + end + + it "exits with AUDIT_MODE_FAILURE, 42" do + setup_client_rb_with_audit_mode + run_chef_client_and_expect_exit_code 42 + end + end + end + + context "with a recipe" do + context "which throws an error" do + before { file "cookbooks/x/recipes/default.rb", "raise 'BOOM'" } + + it "exits with GENERIC_FAILURE, 1" do + setup_client_rb + run_chef_client_and_expect_exit_code 1 + end + end + + context "with a recipe which calls Chef::Application.fatal with a non-RFC exit code" do + before { file "cookbooks/x/recipes/default.rb", "Chef::Application.fatal!('BOOM', 123)" } + + it "exits with the GENERIC_FAILURE exit code, 1" do + setup_client_rb + run_chef_client_and_expect_exit_code 1 + end + end + + context "with a recipe which calls Chef::Application.exit with a non-RFC exit code" do + before { file "cookbooks/x/recipes/default.rb", "Chef::Application.exit!('BOOM', 231)" } + + it "exits with the GENERIC_FAILURE exit code, 1" do + setup_client_rb + run_chef_client_and_expect_exit_code 1 + end + end + + context "when a reboot exception is raised (like from the reboot resource)" do + before do + file "cookbooks/x/recipes/default.rb", <<EOM +raise Chef::Exceptions::Reboot.new +EOM + end + + it "exits with REBOOT_SCHEDULED, 35" do + setup_client_rb + run_chef_client_and_expect_exit_code 35 + end + end + + context "when an attempt to reboot fails (like from the reboot resource)" do + before do + file "cookbooks/x/recipes/default.rb", <<EOM +raise Chef::Exceptions::RebootFailed.new +EOM + end + + it "exits with REBOOT_FAILED, 41" do + setup_client_rb + run_chef_client_and_expect_exit_code 41 + end + end + end + end + end +end diff --git a/spec/integration/client/ipv6_spec.rb b/spec/integration/client/ipv6_spec.rb index 8be873edf4..68c58bb8ea 100644 --- a/spec/integration/client/ipv6_spec.rb +++ b/spec/integration/client/ipv6_spec.rb @@ -1,6 +1,6 @@ # -# Author:: Daniel DeLeo (<dan@opscode.com>) -# Copyright:: Copyright (c) 2013 Opscode, Inc. +# Author:: Daniel DeLeo (<dan@chef.io>) +# Copyright:: Copyright 2013-2016, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,14 +15,14 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'support/shared/integration/integration_helper' -require 'chef/mixin/shell_out' +require "support/shared/integration/integration_helper" +require "chef/mixin/shell_out" describe "chef-client" do include IntegrationSupport include Chef::Mixin::ShellOut - let(:chef_zero_opts) { {:host => "::1"} } + let(:chef_zero_opts) { { :host => "::1" } } let(:validation_pem) do <<-END_VALIDATION_PEM @@ -73,10 +73,9 @@ END_CLIENT_RB basic_config_file end - let(:chef_dir) { File.join(File.dirname(__FILE__), "..", "..", "..", "bin") } - let(:chef_client_cmd) { %Q[ruby '#{chef_dir}/chef-client' --minimal-ohai -c "#{path_to('config/client.rb')}" -lwarn] } + let(:chef_client_cmd) { %Q{ruby '#{chef_dir}/chef-client' --minimal-ohai -c "#{path_to('config/client.rb')}" -lwarn} } after do FileUtils.rm_rf(cache_path) @@ -84,13 +83,13 @@ END_CLIENT_RB # Some Solaris test platforms are too old for IPv6. These tests should not # otherwise be platform dependent, so exclude solaris - when_the_chef_server "is running on IPv6", :not_supported_on_solaris do + when_the_chef_server "is running on IPv6", :not_supported_on_solaris, :not_supported_on_gce do when_the_repository "has a cookbook with a no-op recipe" do 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 + cookbook "noop", "1.0.0", {}, "recipes" => { "default.rb" => "#raise 'foo'" } + file "config/client.rb", client_rb_content + file "config/validator.pem", validation_pem end it "should complete with success" do @@ -103,7 +102,7 @@ END_CLIENT_RB when_the_repository "has a cookbook that hits server APIs" do before do - recipe=<<-END_RECIPE + 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" @@ -115,14 +114,14 @@ END_CLIENT_RB 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', { }, "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 - file 'config/validator.pem', validation_pem + file "config/client.rb", client_rb_content + file "config/validator.pem", validation_pem end it "should complete with success" do diff --git a/spec/integration/knife/chef_fs_data_store_spec.rb b/spec/integration/knife/chef_fs_data_store_spec.rb index c1f2c7134f..02508b799d 100644 --- a/spec/integration/knife/chef_fs_data_store_spec.rb +++ b/spec/integration/knife/chef_fs_data_store_spec.rb @@ -1,6 +1,6 @@ # -# Author:: John Keiser (<jkeiser@opscode.com>) -# Copyright:: Copyright (c) 2013 Opscode, Inc. +# Author:: John Keiser (<jkeiser@chef.io>) +# Copyright:: Copyright 2013-2016, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,36 +15,77 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'support/shared/integration/integration_helper' -require 'chef/knife/list' -require 'chef/knife/delete' -require 'chef/knife/show' -require 'chef/knife/raw' -require 'chef/knife/cookbook_upload' +require "support/shared/integration/integration_helper" +require "chef/knife/list" +require "chef/knife/delete" +require "chef/knife/show" +require "chef/knife/raw" +require "chef/knife/cookbook_upload" -describe 'ChefFSDataStore tests', :workstation do +describe "ChefFSDataStore tests", :workstation do include IntegrationSupport include KnifeSupport let(:cookbook_x_100_metadata_rb) { cb_metadata("x", "1.0.0") } let(:cookbook_z_100_metadata_rb) { cb_metadata("z", "1.0.0") } - when_the_repository "has one of each thing" do + describe "with repo mode 'hosted_everything' (default)" do before do - file 'clients/x.json', {} - file 'cookbooks/x/metadata.rb', cookbook_x_100_metadata_rb - file 'data_bags/x/y.json', {} - file 'environments/x.json', {} - file 'nodes/x.json', {} - file 'roles/x.json', {} - file 'users/x.json', {} + Chef::Config.chef_zero.osc_compat = false end - context 'GET /TYPE' do - it 'knife list -z -R returns everything' do - knife('list -z -Rfp /').should_succeed <<EOM + when_the_repository "has one of each thing" do + before do + file "clients/x.json", {} + file "cookbook_artifacts/x-111/metadata.rb", cookbook_x_100_metadata_rb + file "cookbooks/x/metadata.rb", cookbook_x_100_metadata_rb + file "data_bags/x/y.json", {} + file "environments/x.json", {} + file "nodes/x.json", {} + file "roles/x.json", {} + # file "users/x.json", {} + file "containers/x.json", {} + file "groups/x.json", {} + file "containers/x.json", {} + file "groups/x.json", {} + file "policies/x-111.json", {} + file "policy_groups/x.json", {} + end + + context "GET /TYPE" do + it "knife list -z -R returns everything" do + knife("list -z -Rfp /").should_succeed <<EOM +/acls/ +/acls/clients/ +/acls/clients/x.json +/acls/containers/ +/acls/containers/x.json +/acls/cookbook_artifacts/ +/acls/cookbook_artifacts/x.json +/acls/cookbooks/ +/acls/cookbooks/x.json +/acls/data_bags/ +/acls/data_bags/x.json +/acls/environments/ +/acls/environments/x.json +/acls/groups/ +/acls/groups/x.json +/acls/nodes/ +/acls/nodes/x.json +/acls/organization.json +/acls/policies/ +/acls/policies/x.json +/acls/policy_groups/ +/acls/policy_groups/x.json +/acls/roles/ +/acls/roles/x.json /clients/ /clients/x.json +/containers/ +/containers/x.json +/cookbook_artifacts/ +/cookbook_artifacts/x-111/ +/cookbook_artifacts/x-111/metadata.rb /cookbooks/ /cookbooks/x/ /cookbooks/x/metadata.rb @@ -53,317 +94,462 @@ describe 'ChefFSDataStore tests', :workstation do /data_bags/x/y.json /environments/ /environments/x.json +/groups/ +/groups/x.json +/invitations.json +/members.json /nodes/ /nodes/x.json +/org.json +/policies/ +/policies/x-111.json +/policy_groups/ +/policy_groups/x.json /roles/ /roles/x.json -/users/ -/users/x.json EOM + end end - end - context 'DELETE /TYPE/NAME' do - it 'knife delete -z /clients/x.json works' do - knife('delete -z /clients/x.json').should_succeed "Deleted /clients/x.json\n" - knife('list -z -Rfp /clients').should_succeed '' - end + context "DELETE /TYPE/NAME" do + it "knife delete -z /clients/x.json works" do + knife("delete -z /clients/x.json").should_succeed "Deleted /clients/x.json\n" + knife("list -z -Rfp /clients").should_succeed "" + end - it 'knife delete -z -r /cookbooks/x works' do - knife('delete -z -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n" - knife('list -z -Rfp /cookbooks').should_succeed '' - end + it "knife delete -z -r /cookbooks/x works" do + knife("delete -z -r /cookbooks/x").should_succeed "Deleted /cookbooks/x\n" + knife("list -z -Rfp /cookbooks").should_succeed "" + end - it 'knife delete -z -r /data_bags/x works' do - knife('delete -z -r /data_bags/x').should_succeed "Deleted /data_bags/x\n" - knife('list -z -Rfp /data_bags').should_succeed '' - end + it "knife delete -z -r /data_bags/x works" do + knife("delete -z -r /data_bags/x").should_succeed "Deleted /data_bags/x\n" + knife("list -z -Rfp /data_bags").should_succeed "" + end - it 'knife delete -z /data_bags/x/y.json works' do - knife('delete -z /data_bags/x/y.json').should_succeed "Deleted /data_bags/x/y.json\n" - knife('list -z -Rfp /data_bags').should_succeed "/data_bags/x/\n" - end + it "knife delete -z /data_bags/x/y.json works" do + knife("delete -z /data_bags/x/y.json").should_succeed "Deleted /data_bags/x/y.json\n" + knife("list -z -Rfp /data_bags").should_succeed "/data_bags/x/\n" + end - it 'knife delete -z /environments/x.json works' do - knife('delete -z /environments/x.json').should_succeed "Deleted /environments/x.json\n" - knife('list -z -Rfp /environments').should_succeed '' - end + it "knife delete -z /environments/x.json works" do + knife("delete -z /environments/x.json").should_succeed "Deleted /environments/x.json\n" + knife("list -z -Rfp /environments").should_succeed "" + end - it 'knife delete -z /nodes/x.json works' do - knife('delete -z /nodes/x.json').should_succeed "Deleted /nodes/x.json\n" - knife('list -z -Rfp /nodes').should_succeed '' - end + it "knife delete -z /nodes/x.json works" do + knife("delete -z /nodes/x.json").should_succeed "Deleted /nodes/x.json\n" + knife("list -z -Rfp /nodes").should_succeed "" + end - it 'knife delete -z /roles/x.json works' do - knife('delete -z /roles/x.json').should_succeed "Deleted /roles/x.json\n" - knife('list -z -Rfp /roles').should_succeed '' - end + it "knife delete -z /roles/x.json works" do + knife("delete -z /roles/x.json").should_succeed "Deleted /roles/x.json\n" + knife("list -z -Rfp /roles").should_succeed "" + end - it 'knife delete -z /users/x.json works' do - knife('delete -z /users/x.json').should_succeed "Deleted /users/x.json\n" - knife('list -z -Rfp /users').should_succeed '' end - end - context 'GET /TYPE/NAME' do - it 'knife show -z /clients/x.json works' do - knife('show -z /clients/x.json').should_succeed( /"x"/ ) - end + context "GET /TYPE/NAME" do + it "knife show -z /clients/x.json works" do + knife("show -z /clients/x.json").should_succeed( /"x"/ ) + end - it 'knife show -z /cookbooks/x/metadata.rb works' do - knife('show -z /cookbooks/x/metadata.rb').should_succeed "/cookbooks/x/metadata.rb:\n#{cookbook_x_100_metadata_rb}\n" - end + it "knife show -z /cookbooks/x/metadata.rb works" do + knife("show -z /cookbooks/x/metadata.rb").should_succeed "/cookbooks/x/metadata.rb:\n#{cookbook_x_100_metadata_rb}\n" + end - it 'knife show -z /data_bags/x/y.json works' do - knife('show -z /data_bags/x/y.json').should_succeed( /"y"/ ) - end + it "knife show -z /data_bags/x/y.json works" do + 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"/ ) - end + it "knife show -z /environments/x.json works" do + 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"/ ) - end + it "knife show -z /nodes/x.json works" do + 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"/ ) - end + it "knife show -z /roles/x.json works" do + 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"/ ) end - end - context 'PUT /TYPE/NAME' do - before do - file 'empty.json', {} - file 'dummynode.json', { "name" => "x", "chef_environment" => "rspec" , "json_class" => "Chef::Node", "normal" => {"foo" => "bar"}} - file 'rolestuff.json', '{"description":"hi there","name":"x"}' - file 'cookbooks_to_upload/x/metadata.rb', cookbook_x_100_metadata_rb - end + context "PUT /TYPE/NAME" do + before do + file "empty.json", {} + file "dummynode.json", { "name" => "x", "chef_environment" => "rspec" , "json_class" => "Chef::Node", "normal" => { "foo" => "bar" } } + file "rolestuff.json", '{"description":"hi there","name":"x"}' + file "cookbooks_to_upload/x/metadata.rb", cookbook_x_100_metadata_rb + 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('list --local /clients').should_succeed "/clients/x.json\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("list --local /clients").should_succeed "/clients/x.json\n" + end - it 'knife cookbook upload works' do - knife("cookbook upload -z --cookbook-path #{path_to('cookbooks_to_upload')} x").should_succeed :stderr => <<EOM + it "knife cookbook upload works" do + knife("cookbook upload -z --cookbook-path #{path_to('cookbooks_to_upload')} x").should_succeed :stderr => <<EOM Uploading x [1.0.0] Uploaded 1 cookbook. EOM - knife('list --local -Rfp /cookbooks').should_succeed "/cookbooks/x/\n/cookbooks/x/metadata.rb\n" - 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('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('list --local /environments').should_succeed "/environments/x.json\n" - end - - it 'knife raw -z -i dummynode.json -m PUT /nodes/x' do - knife("raw -z -i #{path_to('dummynode.json')} -m PUT /nodes/x").should_succeed( /"x"/ ) - knife('list --local /nodes').should_succeed "/nodes/x.json\n" - knife('show -z /nodes/x.json --verbose').should_succeed /"bar"/ - 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('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('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', :skip => (RUBY_VERSION < "1.9") do - knife("raw -z -i #{path_to('rolestuff.json')} -m PUT /roles/x").should_succeed( /"x"/ ) - expect(IO.read(path_to('roles/x.json'))).to eq <<EOM.strip + knife("list --local -Rfp /cookbooks").should_succeed "/cookbooks/x/\n/cookbooks/x/metadata.rb\n" + 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("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("list --local /environments").should_succeed "/environments/x.json\n" + end + + it "knife raw -z -i dummynode.json -m PUT /nodes/x" do + knife("raw -z -i #{path_to('dummynode.json')} -m PUT /nodes/x").should_succeed( /"x"/ ) + knife("list --local /nodes").should_succeed "/nodes/x.json\n" + knife("show -z /nodes/x.json --verbose").should_succeed(/"bar"/) + 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("list --local /roles").should_succeed "/roles/x.json\n" + end + + it "After knife raw -z -i rolestuff.json -m PUT /roles/x, the output is pretty", :skip => (RUBY_VERSION < "1.9") do + knife("raw -z -i #{path_to('rolestuff.json')} -m PUT /roles/x").should_succeed( /"x"/ ) + expect(IO.read(path_to("roles/x.json"))).to eq <<EOM.strip { "name": "x", "description": "hi there" } EOM + end end end - end - - when_the_repository 'is empty' do - context 'POST /TYPE/NAME' do - before do - file 'empty.json', { 'name' => 'z' } - file 'dummynode.json', { "name" => "z", "chef_environment" => "rspec" , "json_class" => "Chef::Node", "normal" => {"foo" => "bar"}} - 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', cookbook_z_100_metadata_rb - 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('list --local /clients').should_succeed "/clients/z.json\n" - end - - it 'knife cookbook upload works' do - knife("cookbook upload -z --cookbook-path #{path_to('cookbooks_to_upload')} z").should_succeed :stderr => <<EOM + when_the_repository "is empty" do + context "POST /TYPE/NAME" do + before do + file "empty.json", { "name" => "z" } + file "dummynode.json", { "name" => "z", "chef_environment" => "rspec" , "json_class" => "Chef::Node", "normal" => { "foo" => "bar" } } + 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", cookbook_z_100_metadata_rb + 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("list --local /clients").should_succeed "/clients/z.json\n" + end + + it "knife cookbook upload works" do + knife("cookbook upload -z --cookbook-path #{path_to('cookbooks_to_upload')} z").should_succeed :stderr => <<EOM Uploading z [1.0.0] Uploaded 1 cookbook. EOM - knife('list --local -Rfp /cookbooks').should_succeed "/cookbooks/z/\n/cookbooks/z/metadata.rb\n" - 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('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('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('list --local /environments').should_succeed "/environments/z.json\n" - end - - it 'knife raw -z -i dummynode.json -m POST /nodes' do - knife("raw -z -i #{path_to('dummynode.json')} -m POST /nodes").should_succeed( /uri/ ) - knife('list --local /nodes').should_succeed "/nodes/z.json\n" - knife('show -z /nodes/z.json').should_succeed /"bar"/ - 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('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('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', :skip => (RUBY_VERSION < "1.9") do - knife("raw -z -i #{path_to('rolestuff.json')} -m POST /roles").should_succeed( /uri/ ) - expect(IO.read(path_to('roles/x.json'))).to eq <<EOM.strip + knife("list --local -Rfp /cookbooks").should_succeed "/cookbooks/z/\n/cookbooks/z/metadata.rb\n" + 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("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("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("list --local /environments").should_succeed "/environments/z.json\n" + end + + it "knife raw -z -i dummynode.json -m POST /nodes" do + knife("raw -z -i #{path_to('dummynode.json')} -m POST /nodes").should_succeed( /uri/ ) + knife("list --local /nodes").should_succeed "/nodes/z.json\n" + knife("show -z /nodes/z.json").should_succeed(/"bar"/) + 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("list --local /roles").should_succeed "/roles/z.json\n" + end + + it "After knife raw -z -i rolestuff.json -m POST /roles, the output is pretty", :skip => (RUBY_VERSION < "1.9") do + knife("raw -z -i #{path_to('rolestuff.json')} -m POST /roles").should_succeed( /uri/ ) + expect(IO.read(path_to("roles/x.json"))).to eq <<EOM.strip { "name": "x", "description": "hi there" } EOM - end - end - - it 'knife list -z -R returns nothing' do - knife('list -z -Rfp /').should_succeed <<EOM + end + end + + it "knife list -z -R returns nothing" do + knife("list -z -Rfp /").should_succeed <<EOM +/acls/ +/acls/clients/ +/acls/containers/ +/acls/cookbook_artifacts/ +/acls/cookbooks/ +/acls/data_bags/ +/acls/environments/ +/acls/groups/ +/acls/nodes/ +/acls/organization.json +/acls/policies/ +/acls/policy_groups/ +/acls/roles/ /clients/ +/containers/ +/cookbook_artifacts/ /cookbooks/ /data_bags/ /environments/ +/groups/ +/invitations.json +/members.json /nodes/ +/org.json +/policies/ +/policy_groups/ /roles/ -/users/ EOM - end - - context 'DELETE /TYPE/NAME' do - it 'knife delete -z /clients/x.json fails with an error' do - knife('delete -z /clients/x.json').should_fail "ERROR: /clients/x.json: No such file or directory\n" end - it 'knife delete -z -r /cookbooks/x fails with an error' do - knife('delete -z -r /cookbooks/x').should_fail "ERROR: /cookbooks/x: No such file or directory\n" - end + context "DELETE /TYPE/NAME" do + it "knife delete -z /clients/x.json fails with an error" do + knife("delete -z /clients/x.json").should_fail "ERROR: /clients/x.json: No such file or directory\n" + end - it 'knife delete -z -r /data_bags/x fails with an error' do - knife('delete -z -r /data_bags/x').should_fail "ERROR: /data_bags/x: No such file or directory\n" - end + it "knife delete -z -r /cookbooks/x fails with an error" do + knife("delete -z -r /cookbooks/x").should_fail "ERROR: /cookbooks/x: No such file or directory\n" + end - it 'knife delete -z /data_bags/x/y.json fails with an error' do - knife('delete -z /data_bags/x/y.json').should_fail "ERROR: /data_bags/x/y.json: No such file or directory\n" - end + it "knife delete -z -r /data_bags/x fails with an error" do + knife("delete -z -r /data_bags/x").should_fail "ERROR: /data_bags/x: No such file or directory\n" + end - it 'knife delete -z /environments/x.json fails with an error' do - knife('delete -z /environments/x.json').should_fail "ERROR: /environments/x.json: No such file or directory\n" - end + it "knife delete -z /data_bags/x/y.json fails with an error" do + knife("delete -z /data_bags/x/y.json").should_fail "ERROR: /data_bags/x/y.json: No such file or directory\n" + end - it 'knife delete -z /nodes/x.json fails with an error' do - knife('delete -z /nodes/x.json').should_fail "ERROR: /nodes/x.json: No such file or directory\n" - end + it "knife delete -z /environments/x.json fails with an error" do + knife("delete -z /environments/x.json").should_fail "ERROR: /environments/x.json: No such file or directory\n" + end - it 'knife delete -z /roles/x.json fails with an error' do - knife('delete -z /roles/x.json').should_fail "ERROR: /roles/x.json: No such file or directory\n" - end + it "knife delete -z /nodes/x.json fails with an error" do + knife("delete -z /nodes/x.json").should_fail "ERROR: /nodes/x.json: No such file or directory\n" + end - it 'knife delete -z /users/x.json fails with an error' do - knife('delete -z /users/x.json').should_fail "ERROR: /users/x.json: No such file or directory\n" - end - end + it "knife delete -z /roles/x.json fails with an error" do + knife("delete -z /roles/x.json").should_fail "ERROR: /roles/x.json: No such file or directory\n" + end - context 'GET /TYPE/NAME' do - it 'knife show -z /clients/x.json fails with an error' do - knife('show -z /clients/x.json').should_fail "ERROR: /clients/x.json: No such file or directory\n" end - it 'knife show -z /cookbooks/x/metadata.rb fails with an error' do - knife('show -z /cookbooks/x/metadata.rb').should_fail "ERROR: /cookbooks/x/metadata.rb: No such file or directory\n" - end + context "GET /TYPE/NAME" do + it "knife show -z /clients/x.json fails with an error" do + knife("show -z /clients/x.json").should_fail "ERROR: /clients/x.json: No such file or directory\n" + end - it 'knife show -z /data_bags/x/y.json fails with an error' do - knife('show -z /data_bags/x/y.json').should_fail "ERROR: /data_bags/x/y.json: No such file or directory\n" - end + it "knife show -z /cookbooks/x/metadata.rb fails with an error" do + knife("show -z /cookbooks/x/metadata.rb").should_fail "ERROR: /cookbooks/x/metadata.rb: No such file or directory\n" + end - it 'knife show -z /environments/x.json fails with an error' do - knife('show -z /environments/x.json').should_fail "ERROR: /environments/x.json: No such file or directory\n" - end + it "knife show -z /data_bags/x/y.json fails with an error" do + knife("show -z /data_bags/x/y.json").should_fail "ERROR: /data_bags/x/y.json: No such file or directory\n" + end - it 'knife show -z /nodes/x.json fails with an error' do - knife('show -z /nodes/x.json').should_fail "ERROR: /nodes/x.json: No such file or directory\n" - end + it "knife show -z /environments/x.json fails with an error" do + knife("show -z /environments/x.json").should_fail "ERROR: /environments/x.json: No such file or directory\n" + end + + it "knife show -z /nodes/x.json fails with an error" do + knife("show -z /nodes/x.json").should_fail "ERROR: /nodes/x.json: No such file or directory\n" + end + + it "knife show -z /roles/x.json fails with an error" do + knife("show -z /roles/x.json").should_fail "ERROR: /roles/x.json: No such file or directory\n" + end - it 'knife show -z /roles/x.json fails with an error' do - knife('show -z /roles/x.json').should_fail "ERROR: /roles/x.json: No such file or directory\n" end - it 'knife show -z /users/x.json fails with an error' do - knife('show -z /users/x.json').should_fail "ERROR: /users/x.json: No such file or directory\n" + context "PUT /TYPE/NAME" do + 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/ ) + 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/ ) + 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/ ) + 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/ ) + 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/ ) + end + end end + end - context 'PUT /TYPE/NAME' do + # We have to configure Zero for Chef 11 mode in order to test users because: + # 1. local mode overrides your `chef_server_url` to something like "http://localhost:PORT" + # 2. single org mode maps requests like "https://localhost:PORT/users" so + # they're functionally equivalent to "https://localhost:PORT/organizations/DEFAULT/users" + # 3. Users are global objects in Chef 12, and should be accessed at URLs like + # "https://localhost:PORT/users" (there is an org-specific users endpoint, + # but it's for listing users in an org, not for managing users). + # 4. Therefore you can't hit the _real_ users endpoint in local mode when + # configured for Chef Server 12 mode. + # + # Because of this, we have to configure Zero for Chef 11 OSC mode in order to + # test the users part of the data store with local mode. + describe "with repo mode 'everything'" do + before do + Chef::Config.repo_mode = "everything" + Chef::Config.chef_zero.osc_compat = true + end + + when_the_repository "has one of each thing" do before do - file 'empty.json', {} + file "clients/x.json", {} + file "cookbooks/x/metadata.rb", cookbook_x_100_metadata_rb + 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 + knife("list -z -Rfp /").should_succeed <<EOM +/clients/ +/clients/x.json +/cookbooks/ +/cookbooks/x/ +/cookbooks/x/metadata.rb +/data_bags/ +/data_bags/x/ +/data_bags/x/y.json +/environments/ +/environments/x.json +/nodes/ +/nodes/x.json +/roles/ +/roles/x.json +/users/ +/users/x.json +EOM + end 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/ ) + context "DELETE /TYPE/NAME" do + it "knife delete -z /users/x.json works" do + knife("delete -z /users/x.json").should_succeed "Deleted /users/x.json\n" + knife("list -z -Rfp /users").should_succeed "" + end 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/ ) + context "GET /TYPE/NAME" do + it "knife show -z /users/x.json works" do + knife("show -z /users/x.json").should_succeed( /"x"/ ) + end + end + + context "PUT /TYPE/NAME" do + before do + file "empty.json", {} + file "dummynode.json", { "name" => "x", "chef_environment" => "rspec" , "json_class" => "Chef::Node", "normal" => { "foo" => "bar" } } + file "rolestuff.json", '{"description":"hi there","name":"x"}' + file "cookbooks_to_upload/x/metadata.rb", cookbook_x_100_metadata_rb + 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("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", :skip => (RUBY_VERSION < "1.9") do + knife("raw -z -i #{path_to('rolestuff.json')} -m PUT /roles/x").should_succeed( /"x"/ ) + expect(IO.read(path_to("roles/x.json"))).to eq <<EOM.strip +{ + "name": "x", + "description": "hi there" +} +EOM + end end + 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/ ) + when_the_repository "is empty" do + context "POST /TYPE/NAME" do + before do + file "empty.json", { "name" => "z" } + file "dummynode.json", { "name" => "z", "chef_environment" => "rspec" , "json_class" => "Chef::Node", "normal" => { "foo" => "bar" } } + 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", cookbook_z_100_metadata_rb + 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("list --local /users").should_succeed "/users/z.json\n" + end + end + + it "knife list -z -R returns nothing" do + knife("list -z -Rfp /").should_succeed <<EOM +/clients/ +/cookbooks/ +/data_bags/ +/environments/ +/nodes/ +/roles/ +/users/ +EOM 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/ ) + context "DELETE /TYPE/NAME" do + it "knife delete -z /users/x.json fails with an error" do + knife("delete -z /users/x.json").should_fail "ERROR: /users/x.json: No such file or directory\n" + end 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/ ) + context "GET /TYPE/NAME" do + it "knife show -z /users/x.json fails with an error" do + knife("show -z /users/x.json").should_fail "ERROR: /users/x.json: No such file or directory\n" + end 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/ ) + context "PUT /TYPE/NAME" do + before do + file "empty.json", {} + 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/ ) + end end end end diff --git a/spec/integration/knife/chef_repo_path_spec.rb b/spec/integration/knife/chef_repo_path_spec.rb index 908657e5f7..e609fa60b3 100644 --- a/spec/integration/knife/chef_repo_path_spec.rb +++ b/spec/integration/knife/chef_repo_path_spec.rb @@ -1,6 +1,6 @@ # -# Author:: John Keiser (<jkeiser@opscode.com>) -# Copyright:: Copyright (c) 2013 Opscode, Inc. +# Author:: John Keiser (<jkeiser@chef.io>) +# Copyright:: Copyright 2013-2016, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,49 +15,49 @@ # 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' +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 +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 + 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', {} + 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", "name 'cookbook3'" + 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 + 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 <<EOM /clients/ @@ -79,15 +79,84 @@ describe 'chef_repo_path tests', :workstation do EOM end - context 'when all _paths are set to alternates' do + it "knife list --local -Rfp --chef-repo-path chef_r~1 / grabs chef_repo2 stuff", :windows_only do + Chef::Config.delete(:chef_repo_path) + knife("list --local -Rfp --chef-repo-path #{path_to('chef_r~1')} /").should_succeed <<EOM +/clients/ +/clients/client3.json +/cookbooks/ +/cookbooks/cookbook3/ +/cookbooks/cookbook3/metadata.rb +/data_bags/ +/data_bags/bag3/ +/data_bags/bag3/item3.json +/environments/ +/environments/env3.json +/nodes/ +/nodes/node3.json +/roles/ +/roles/role3.json +/users/ +/users/user3.json +EOM + end + + it "knife list --local -Rfp --chef-repo-path chef_r~1 / grabs chef_repo2 stuff", :windows_only do + Chef::Config.delete(:chef_repo_path) + knife("list -z -Rfp --chef-repo-path #{path_to('chef_r~1')} /").should_succeed <<EOM +/acls/ +/acls/clients/ +/acls/clients/client3.json +/acls/containers/ +/acls/cookbook_artifacts/ +/acls/cookbooks/ +/acls/cookbooks/cookbook3.json +/acls/data_bags/ +/acls/data_bags/bag3.json +/acls/environments/ +/acls/environments/env3.json +/acls/groups/ +/acls/nodes/ +/acls/nodes/node3.json +/acls/organization.json +/acls/policies/ +/acls/policy_groups/ +/acls/roles/ +/acls/roles/role3.json +/clients/ +/clients/client3.json +/containers/ +/cookbook_artifacts/ +/cookbooks/ +/cookbooks/cookbook3/ +/cookbooks/cookbook3/metadata.rb +/data_bags/ +/data_bags/bag3/ +/data_bags/bag3/item3.json +/environments/ +/environments/env3.json +/groups/ +/invitations.json +/members.json +/nodes/ +/nodes/node3.json +/org.json +/policies/ +/policy_groups/ +/roles/ +/roles/role3.json +EOM + 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| + %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') + Chef::Config.chef_repo_path = File.join(Chef::Config.chef_repo_path, "chef_repo2") end - it 'knife list --local -Rfp --chef-repo-path chef_repo2 / grabs chef_repo2 stuff' do + it "knife list --local -Rfp --chef-repo-path chef_repo2 / grabs chef_repo2 stuff" do knife("list --local -Rfp --chef-repo-path #{path_to('chef_repo2')} /").should_succeed <<EOM /clients/ /clients/client3.json @@ -108,24 +177,24 @@ EOM EOM end - context 'when cwd is at the top level' do - before { cwd '.' } - it 'knife list --local -Rfp fails' do - knife('list --local -Rfp').should_fail(error_rel_path_outside_repo) + context "when cwd is at the top level" do + before { cwd "." } + it "knife list --local -Rfp fails" do + knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) end end - context 'when cwd is inside the data_bags directory' do - before { cwd 'data_bags' } - it 'knife list --local -Rfp fails' do - knife('list --local -Rfp').should_fail(error_rel_path_outside_repo) + context "when cwd is inside the data_bags directory" do + before { cwd "data_bags" } + it "knife list --local -Rfp fails" do + knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) end end - context 'when cwd is inside chef_repo2' do - before { cwd 'chef_repo2' } - it 'knife list --local -Rfp lists everything' do - knife('list --local -Rfp').should_succeed <<EOM + context "when cwd is inside chef_repo2" do + before { cwd "chef_repo2" } + it "knife list --local -Rfp lists everything" do + knife("list --local -Rfp").should_succeed <<EOM clients/ clients/client2.json cookbooks/ @@ -146,31 +215,31 @@ EOM end end - context 'when cwd is inside data_bags2' do - before { cwd 'data_bags2' } - it 'knife list --local -Rfp lists data bags' do - knife('list --local -Rfp').should_succeed <<EOM + context "when cwd is inside data_bags2" do + before { cwd "data_bags2" } + it "knife list --local -Rfp lists data bags" do + knife("list --local -Rfp").should_succeed <<EOM bag2/ bag2/item2.json EOM end - it 'knife list --local -Rfp ../roles lists roles' do - knife('list --local -Rfp ../roles').should_succeed "/roles/role2.json\n" + it "knife list --local -Rfp ../roles lists roles" do + knife("list --local -Rfp ../roles").should_succeed "/roles/role2.json\n" end end end - context 'when all _paths except chef_repo_path are set to alternates' do + context "when all _paths except chef_repo_path are set to alternates" do before :each do - %w(client cookbook data_bag environment node role user).each do |object_name| + %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 end - context 'when cwd is at the top level' do - before { cwd '.' } - it 'knife list --local -Rfp lists everything' do - knife('list --local -Rfp').should_succeed <<EOM + context "when cwd is at the top level" do + before { cwd "." } + it "knife list --local -Rfp lists everything" do + knife("list --local -Rfp").should_succeed <<EOM clients/ clients/client2.json cookbooks/ @@ -191,24 +260,24 @@ EOM end end - context 'when cwd is inside the data_bags directory' do - before { cwd 'data_bags' } - it 'knife list --local -Rfp fails' do - knife('list --local -Rfp').should_fail(error_rel_path_outside_repo) + context "when cwd is inside the data_bags directory" do + before { cwd "data_bags" } + it "knife list --local -Rfp fails" do + knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) end end - context 'when cwd is inside chef_repo2' do - before { cwd 'chef_repo2' } - it 'knife list -Rfp fails' do - knife('list --local -Rfp').should_fail(error_rel_path_outside_repo) + context "when cwd is inside chef_repo2" do + before { cwd "chef_repo2" } + it "knife list -Rfp fails" do + knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) end end - context 'when cwd is inside data_bags2' do - before { cwd 'data_bags2' } - it 'knife list --local -Rfp lists data bags' do - knife('list --local -Rfp').should_succeed <<EOM + context "when cwd is inside data_bags2" do + before { cwd "data_bags2" } + it "knife list --local -Rfp lists data bags" do + knife("list --local -Rfp").should_succeed <<EOM bag2/ bag2/item2.json EOM @@ -216,32 +285,32 @@ EOM end end - context 'when only chef_repo_path is set to its alternate' do + context "when only chef_repo_path is set to its alternate" do before :each do - %w(client cookbook data_bag environment node role user).each do |object_name| + %w{client cookbook data_bag environment node role user}.each do |object_name| Chef::Config.delete("#{object_name}_path".to_sym) end - Chef::Config.chef_repo_path = File.join(Chef::Config.chef_repo_path, 'chef_repo2') + Chef::Config.chef_repo_path = File.join(Chef::Config.chef_repo_path, "chef_repo2") end - context 'when cwd is at the top level' do - before { cwd '.' } - it 'knife list --local -Rfp fails' do - knife('list --local -Rfp').should_fail(error_rel_path_outside_repo) + context "when cwd is at the top level" do + before { cwd "." } + it "knife list --local -Rfp fails" do + knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) end end - context 'when cwd is inside the data_bags directory' do - before { cwd 'data_bags' } - it 'knife list --local -Rfp fails' do - knife('list --local -Rfp').should_fail(error_rel_path_outside_repo) + context "when cwd is inside the data_bags directory" do + before { cwd "data_bags" } + it "knife list --local -Rfp fails" do + knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) end end - context 'when cwd is inside chef_repo2' do - before { cwd 'chef_repo2' } - it 'knife list --local -Rfp lists everything' do - knife('list --local -Rfp').should_succeed <<EOM + context "when cwd is inside chef_repo2" do + before { cwd "chef_repo2" } + it "knife list --local -Rfp lists everything" do + knife("list --local -Rfp").should_succeed <<EOM clients/ clients/client3.json cookbooks/ @@ -262,10 +331,10 @@ EOM end end - context 'when cwd is inside chef_repo2/data_bags' do - before { cwd 'chef_repo2/data_bags' } - it 'knife list --local -Rfp lists data bags' do - knife('list --local -Rfp').should_succeed <<EOM + context "when cwd is inside chef_repo2/data_bags" do + before { cwd "chef_repo2/data_bags" } + it "knife list --local -Rfp lists data bags" do + knife("list --local -Rfp").should_succeed <<EOM bag3/ bag3/item3.json EOM @@ -273,24 +342,24 @@ EOM end end - context 'when paths are set to point to both versions of each' do + context "when paths are set to point to both versions of each" do before :each do - %w(client cookbook data_bag environment node role user).each do |object_name| + %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}s"), - File.join(Chef::Config.chef_repo_path, "#{object_name}s2") + 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') + Chef::Config.chef_repo_path = File.join(Chef::Config.chef_repo_path, "chef_repo2") end - context 'when there is a directory in clients1 and file in clients2 with the same name' do + context "when there is a directory in clients1 and file in clients2 with the same name" do before do - directory 'clients/blah.json' - file 'clients2/blah.json', {} + 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 + it "knife show /clients/blah.json succeeds" do + knife("show --local /clients/blah.json").should_succeed <<EOM /clients/blah.json: { @@ -299,13 +368,13 @@ EOM end end - context 'when there is a file in cookbooks1 and directory in cookbooks2 with the same name' do + context "when there is a file in cookbooks1 and directory in cookbooks2 with the same name" do before do - file 'cookbooks/blah', '' - file 'cookbooks2/blah/metadata.rb', '' + 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 + it "knife list -Rfp cookbooks shows files in blah" do + knife("list --local -Rfp /cookbooks").should_succeed <<EOM /cookbooks/blah/ /cookbooks/blah/metadata.rb /cookbooks/cookbook1/ @@ -316,13 +385,13 @@ EOM end end - context 'when there is an empty directory in cookbooks1 and a real cookbook in cookbooks2 with the same name' do + context "when there is an empty directory in cookbooks1 and a real cookbook in cookbooks2 with the same name" do before do - directory 'cookbooks/blah' - file 'cookbooks2/blah/metadata.rb', '' + 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") + 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/ /cookbooks/blah/metadata.rb /cookbooks/cookbook1/ @@ -333,13 +402,13 @@ EOM end end - context 'when there is a cookbook in cookbooks1 and a cookbook in cookbooks2 with the same name' do + 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', '' + 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") + 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/ /cookbooks/blah/metadata.json /cookbooks/cookbook1/ @@ -350,13 +419,13 @@ EOM end end - context 'when there is a file in data_bags1 and a directory in data_bags2 with the same name' do + 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', '' + 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 + it "knife list -Rfp data_bags shows files in blah" do + knife("list --local -Rfp /data_bags").should_succeed <<EOM /data_bags/bag/ /data_bags/bag/item.json /data_bags/bag2/ @@ -367,13 +436,13 @@ EOM end end - context 'when there is a data bag in data_bags1 and a data bag in data_bags2 with the same name' do + context "when there is a data bag in data_bags1 and a data bag in data_bags2 with the same name" do before do - file 'data_bags/blah/item1.json', '' - file 'data_bags2/blah/item2.json', '' + 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") + 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/ /data_bags/bag/item.json /data_bags/bag2/ @@ -384,13 +453,13 @@ EOM end end - context 'when there is a directory in environments1 and file in environments2 with the same name' do + 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', {} + 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 + it "knife show /environments/blah.json succeeds" do + knife("show --local /environments/blah.json").should_succeed <<EOM /environments/blah.json: { @@ -399,13 +468,13 @@ EOM end end - context 'when there is a directory in nodes1 and file in nodes2 with the same name' do + context "when there is a directory in nodes1 and file in nodes2 with the same name" do before do - directory 'nodes/blah.json' - file 'nodes2/blah.json', {} + 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 + it "knife show /nodes/blah.json succeeds" do + knife("show --local /nodes/blah.json").should_succeed <<EOM /nodes/blah.json: { @@ -414,13 +483,13 @@ EOM end end - context 'when there is a directory in roles1 and file in roles2 with the same name' do + context "when there is a directory in roles1 and file in roles2 with the same name" do before do - directory 'roles/blah.json' - file 'roles2/blah.json', {} + 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 + it "knife show /roles/blah.json succeeds" do + knife("show --local /roles/blah.json").should_succeed <<EOM /roles/blah.json: { @@ -429,13 +498,13 @@ EOM end end - context 'when there is a directory in users1 and file in users2 with the same name' do + context "when there is a directory in users1 and file in users2 with the same name" do before do - directory 'users/blah.json' - file 'users2/blah.json', {} + 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 + it "knife show /users/blah.json succeeds" do + knife("show --local /users/blah.json").should_succeed <<EOM /users/blah.json: { @@ -444,17 +513,17 @@ EOM end end - context 'when cwd is at the top level' do - before { cwd '.' } - it 'knife list --local -Rfp fails' do - knife('list --local -Rfp').should_fail(error_rel_path_outside_repo) + context "when cwd is at the top level" do + before { cwd "." } + it "knife list --local -Rfp fails" do + knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) end end - context 'when cwd is inside the data_bags directory' do - before { cwd 'data_bags' } - it 'knife list --local -Rfp lists data bags' do - knife('list --local -Rfp').should_succeed <<EOM + context "when cwd is inside the data_bags directory" do + before { cwd "data_bags" } + it "knife list --local -Rfp lists data bags" do + knife("list --local -Rfp").should_succeed <<EOM bag/ bag/item.json bag2/ @@ -463,10 +532,10 @@ EOM end end - context 'when cwd is inside chef_repo2' do - before { cwd 'chef_repo2' } - it 'knife list --local -Rfp lists everything' do - knife('list --local -Rfp').should_succeed <<EOM + context "when cwd is inside chef_repo2" do + before { cwd "chef_repo2" } + it "knife list --local -Rfp lists everything" do + knife("list --local -Rfp").should_succeed <<EOM clients/ clients/client1.json clients/client2.json @@ -496,10 +565,10 @@ EOM end end - context 'when cwd is inside data_bags2' do - before { cwd 'data_bags2' } - it 'knife list --local -Rfp lists data bags' do - knife('list --local -Rfp').should_succeed <<EOM + context "when cwd is inside data_bags2" do + before { cwd "data_bags2" } + it "knife list --local -Rfp lists data bags" do + knife("list --local -Rfp").should_succeed <<EOM bag/ bag/item.json bag2/ @@ -509,21 +578,21 @@ EOM end end - context 'when when chef_repo_path is set to both places and no other _path is set' do + context "when when chef_repo_path is set to both places and no other _path is set" do before :each do - %w(client cookbook data_bag environment node role user).each do |object_name| + %w{client cookbook data_bag environment node role user}.each do |object_name| Chef::Config.delete("#{object_name}_path".to_sym) end Chef::Config.chef_repo_path = [ Chef::Config.chef_repo_path, - File.join(Chef::Config.chef_repo_path, 'chef_repo2') + File.join(Chef::Config.chef_repo_path, "chef_repo2"), ] end - context 'when cwd is at the top level' do - before { cwd '.' } - it 'knife list --local -Rfp lists everything' do - knife('list --local -Rfp').should_succeed <<EOM + context "when cwd is at the top level" do + before { cwd "." } + it "knife list --local -Rfp lists everything" do + knife("list --local -Rfp").should_succeed <<EOM clients/ clients/client1.json clients/client3.json @@ -553,10 +622,10 @@ EOM end end - context 'when cwd is inside the data_bags directory' do - before { cwd 'data_bags' } - it 'knife list --local -Rfp lists data bags' do - knife('list --local -Rfp').should_succeed <<EOM + context "when cwd is inside the data_bags directory" do + before { cwd "data_bags" } + it "knife list --local -Rfp lists data bags" do + knife("list --local -Rfp").should_succeed <<EOM bag/ bag/item.json bag3/ @@ -565,10 +634,10 @@ EOM end end - context 'when cwd is inside chef_repo2' do - before { cwd 'chef_repo2' } - it 'knife list --local -Rfp lists everything' do - knife('list --local -Rfp').should_succeed <<EOM + context "when cwd is inside chef_repo2" do + before { cwd "chef_repo2" } + it "knife list --local -Rfp lists everything" do + knife("list --local -Rfp").should_succeed <<EOM clients/ clients/client1.json clients/client3.json @@ -598,10 +667,10 @@ EOM end end - context 'when cwd is inside chef_repo2/data_bags' do - before { cwd 'chef_repo2/data_bags' } - it 'knife list --local -Rfp lists data bags' do - knife('list --local -Rfp').should_succeed <<EOM + context "when cwd is inside chef_repo2/data_bags" do + before { cwd "chef_repo2/data_bags" } + it "knife list --local -Rfp lists data bags" do + knife("list --local -Rfp").should_succeed <<EOM bag/ bag/item.json bag3/ @@ -611,33 +680,33 @@ EOM end end - context 'when cookbook_path is set and nothing else' do + context "when cookbook_path is set and nothing else" do before :each do - %w(client data_bag environment node role user).each do |object_name| + %w{client 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) - Chef::Config.cookbook_path = File.join(@repository_dir, 'chef_repo2', 'cookbooks') + Chef::Config.cookbook_path = File.join(@repository_dir, "chef_repo2", "cookbooks") end - context 'when cwd is at the top level' do - before { cwd '.' } - it 'knife list --local -Rfp fails' do - knife('list --local -Rfp').should_fail(error_rel_path_outside_repo) + context "when cwd is at the top level" do + before { cwd "." } + it "knife list --local -Rfp fails" do + knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) end end - context 'when cwd is inside the data_bags directory' do - before { cwd 'data_bags' } - it 'knife list --local -Rfp fails' do - knife('list --local -Rfp').should_fail(error_rel_path_outside_repo) + context "when cwd is inside the data_bags directory" do + before { cwd "data_bags" } + it "knife list --local -Rfp fails" do + knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) end end - context 'when cwd is inside chef_repo2' do - before { cwd 'chef_repo2' } - it 'knife list --local -Rfp lists everything' do - knife('list --local -Rfp').should_succeed <<EOM + context "when cwd is inside chef_repo2" do + before { cwd "chef_repo2" } + it "knife list --local -Rfp lists everything" do + knife("list --local -Rfp").should_succeed <<EOM clients/ clients/client3.json cookbooks/ @@ -658,10 +727,10 @@ EOM end end - context 'when cwd is inside chef_repo2/data_bags' do - before { cwd 'chef_repo2/data_bags' } - it 'knife list --local -Rfp lists data bags' do - knife('list --local -Rfp').should_succeed <<EOM + context "when cwd is inside chef_repo2/data_bags" do + before { cwd "chef_repo2/data_bags" } + it "knife list --local -Rfp lists data bags" do + knife("list --local -Rfp").should_succeed <<EOM bag3/ bag3/item3.json EOM @@ -669,22 +738,22 @@ EOM end end - context 'when cookbook_path is set to multiple places and nothing else is set' do + context "when cookbook_path is set to multiple places and nothing else is set" do before :each do - %w(client data_bag environment node role user).each do |object_name| + %w{client 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) Chef::Config.cookbook_path = [ - File.join(@repository_dir, 'cookbooks'), - File.join(@repository_dir, 'chef_repo2', 'cookbooks') + File.join(@repository_dir, "cookbooks"), + File.join(@repository_dir, "chef_repo2", "cookbooks"), ] end - context 'when cwd is at the top level' do - before { cwd '.' } - it 'knife list --local -Rfp lists everything' do - knife('list --local -Rfp').should_succeed <<EOM + context "when cwd is at the top level" do + before { cwd "." } + it "knife list --local -Rfp lists everything" do + knife("list --local -Rfp").should_succeed <<EOM clients/ clients/client1.json clients/client3.json @@ -714,10 +783,10 @@ EOM end end - context 'when cwd is inside the data_bags directory' do - before { cwd 'data_bags' } - it 'knife list --local -Rfp lists data bags' do - knife('list --local -Rfp').should_succeed <<EOM + context "when cwd is inside the data_bags directory" do + before { cwd "data_bags" } + it "knife list --local -Rfp lists data bags" do + knife("list --local -Rfp").should_succeed <<EOM bag/ bag/item.json bag3/ @@ -726,10 +795,10 @@ EOM end end - context 'when cwd is inside chef_repo2' do - before { cwd 'chef_repo2' } - it 'knife list --local -Rfp lists everything' do - knife('list --local -Rfp').should_succeed <<EOM + context "when cwd is inside chef_repo2" do + before { cwd "chef_repo2" } + it "knife list --local -Rfp lists everything" do + knife("list --local -Rfp").should_succeed <<EOM clients/ clients/client1.json clients/client3.json @@ -759,10 +828,10 @@ EOM end end - context 'when cwd is inside chef_repo2/data_bags' do - before { cwd 'chef_repo2/data_bags' } - it 'knife list --local -Rfp lists data bags' do - knife('list --local -Rfp').should_succeed <<EOM + context "when cwd is inside chef_repo2/data_bags" do + before { cwd "chef_repo2/data_bags" } + it "knife list --local -Rfp lists data bags" do + knife("list --local -Rfp").should_succeed <<EOM bag/ bag/item.json bag3/ @@ -772,36 +841,36 @@ EOM end end - context 'when data_bag_path and chef_repo_path are set, and nothing else' do + context "when data_bag_path and chef_repo_path are set, and nothing else" do before :each do - %w(client cookbook environment node role user).each do |object_name| + %w{client cookbook environment node role user}.each do |object_name| Chef::Config.delete("#{object_name}_path".to_sym) end - Chef::Config.data_bag_path = File.join(Chef::Config.chef_repo_path, 'data_bags') - Chef::Config.chef_repo_path = File.join(Chef::Config.chef_repo_path, 'chef_repo2') + Chef::Config.data_bag_path = File.join(Chef::Config.chef_repo_path, "data_bags") + Chef::Config.chef_repo_path = File.join(Chef::Config.chef_repo_path, "chef_repo2") end - context 'when cwd is at the top level' do - before { cwd '.' } - it 'knife list --local -Rfp fails' do - knife('list --local -Rfp').should_fail(error_rel_path_outside_repo) + context "when cwd is at the top level" do + before { cwd "." } + it "knife list --local -Rfp fails" do + knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) end end - context 'when cwd is inside the data_bags directory' do - before { cwd 'data_bags' } - it 'knife list --local -Rfp lists data bags' do - knife('list --local -Rfp').should_succeed <<EOM + context "when cwd is inside the data_bags directory" do + before { cwd "data_bags" } + it "knife list --local -Rfp lists data bags" do + knife("list --local -Rfp").should_succeed <<EOM bag/ bag/item.json EOM end end - context 'when cwd is inside chef_repo2' do - before { cwd 'chef_repo2' } - it 'knife list --local -Rfp lists everything' do - knife('list --local -Rfp').should_succeed <<EOM + context "when cwd is inside chef_repo2" do + before { cwd "chef_repo2" } + it "knife list --local -Rfp lists everything" do + knife("list --local -Rfp").should_succeed <<EOM clients/ clients/client3.json cookbooks/ @@ -822,44 +891,44 @@ EOM end end - context 'when cwd is inside chef_repo2/data_bags' do - before { cwd 'chef_repo2/data_bags' } - it 'knife list --local -Rfp fails' do - knife('list --local -Rfp').should_fail(error_rel_path_outside_repo) + context "when cwd is inside chef_repo2/data_bags" do + before { cwd "chef_repo2/data_bags" } + it "knife list --local -Rfp fails" do + knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) end end end - context 'when data_bag_path is set and nothing else' do + context "when data_bag_path is set and nothing else" do include_context "default config options" before :each do - %w(client cookbook environment node role user).each do |object_name| + %w{client cookbook environment node role user}.each do |object_name| Chef::Config.delete("#{object_name}_path".to_sym) end Chef::Config.delete(:chef_repo_path) - Chef::Config.data_bag_path = File.join(@repository_dir, 'data_bags') + Chef::Config.data_bag_path = File.join(@repository_dir, "data_bags") end - it 'knife list --local -Rfp / lists data bags' do - knife('list --local -Rfp /').should_succeed <<EOM + it "knife list --local -Rfp / lists data bags" do + knife("list --local -Rfp /").should_succeed <<EOM /data_bags/ /data_bags/bag/ /data_bags/bag/item.json EOM end - it 'knife list --local -Rfp /data_bags lists data bags' do - knife('list --local -Rfp /data_bags').should_succeed <<EOM + it "knife list --local -Rfp /data_bags lists data bags" do + knife("list --local -Rfp /data_bags").should_succeed <<EOM /data_bags/bag/ /data_bags/bag/item.json EOM end - context 'when cwd is inside the data_bags directory' do - before { cwd 'data_bags' } - it 'knife list --local -Rfp lists data bags' do - knife('list --local -Rfp').should_succeed <<EOM + context "when cwd is inside the data_bags directory" do + before { cwd "data_bags" } + it "knife list --local -Rfp lists data bags" do + knife("list --local -Rfp").should_succeed <<EOM bag/ bag/item.json EOM @@ -868,21 +937,21 @@ EOM end end - when_the_repository 'is empty' do - context 'when the repository _paths point to places that do not exist' do + when_the_repository "is empty" do + context "when the repository _paths point to places that do not exist" 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, 'nowhere', object_name) + %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, "nowhere", object_name) end - Chef::Config.chef_repo_path = File.join(Chef::Config.chef_repo_path, 'nowhere') + Chef::Config.chef_repo_path = File.join(Chef::Config.chef_repo_path, "nowhere") end - it 'knife list --local -Rfp / fails' do - knife('list --local -Rfp /').should_succeed '' + it "knife list --local -Rfp / fails" do + knife("list --local -Rfp /").should_succeed "" end - it 'knife list --local -Rfp /data_bags fails' do - knife('list --local -Rfp /data_bags').should_fail("ERROR: /data_bags: No such file or directory\n") + it "knife list --local -Rfp /data_bags fails" do + knife("list --local -Rfp /data_bags").should_fail("ERROR: /data_bags: No such file or directory\n") end end end diff --git a/spec/integration/knife/chef_repository_file_system_spec.rb b/spec/integration/knife/chef_repository_file_system_spec.rb index 34afd228f3..cc538c98c0 100644 --- a/spec/integration/knife/chef_repository_file_system_spec.rb +++ b/spec/integration/knife/chef_repository_file_system_spec.rb @@ -1,6 +1,6 @@ # -# Author:: John Keiser (<jkeiser@opscode.com>) -# Copyright:: Copyright (c) 2013 Opscode, Inc. +# Author:: John Keiser (<jkeiser@chef.io>) +# Copyright:: Copyright 2013-2016, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,15 +15,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'support/shared/integration/integration_helper' -require 'chef/knife/list' -require 'chef/knife/show' +require "support/shared/integration/integration_helper" +require "chef/knife/list" +require "chef/knife/show" -describe 'General chef_repo file system checks', :workstation do +describe "General chef_repo file system checks", :workstation do include IntegrationSupport include KnifeSupport - context 'directories and files that should/should not be ignored' do + context "directories and files that should/should not be ignored" do when_the_repository "has empty roles, environments and data bag item directories" do before do directory "roles" @@ -32,7 +32,7 @@ describe 'General chef_repo file system checks', :workstation do end it "knife list --local -Rfp / returns them" do - knife('list --local -Rfp /').should_succeed <<EOM + knife("list --local -Rfp /").should_succeed <<EOM /data_bags/ /data_bags/bag1/ /environments/ @@ -45,25 +45,25 @@ EOM before { directory "data_bags" } it "knife list --local / returns it" do - knife('list --local /').should_succeed "/data_bags\n" + knife("list --local /").should_succeed "/data_bags\n" end end when_the_repository "has an empty cookbook directory" do - before { 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") + 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") /cookbooks/ EOM end end when_the_repository "has only empty cookbook subdirectories" do - before { 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") + 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") /cookbooks/ EOM end @@ -71,12 +71,12 @@ EOM when_the_repository "has empty and non-empty cookbook subdirectories" do before do - directory 'cookbooks/cookbook1/recipes' - file 'cookbooks/cookbook1/templates/default/x.txt', '' + 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 + knife("list --local -Rfp /").should_succeed <<EOM /cookbooks/ /cookbooks/cookbook1/ /cookbooks/cookbook1/templates/ @@ -87,10 +87,10 @@ EOM end when_the_repository "has only empty cookbook sub-sub-directories" do - before { 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") + 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") /cookbooks/ EOM end @@ -98,13 +98,13 @@ EOM when_the_repository "has empty cookbook sub-sub-directories alongside non-empty ones" do before do - file 'cookbooks/cookbook1/templates/default/x.txt', '' - directory 'cookbooks/cookbook1/templates/rhel' - directory 'cookbooks/cookbook1/files/default' + 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 + knife("list --local -Rfp /").should_succeed <<EOM /cookbooks/ /cookbooks/cookbook1/ /cookbooks/cookbook1/templates/ @@ -122,7 +122,7 @@ EOM end it "knife list --local -Rfp / should NOT return it" do - knife('list --local -Rfp /').should_succeed "" + knife("list --local -Rfp /").should_succeed "" end end @@ -146,7 +146,7 @@ EOM end it "knife list --local -Rfp / should NOT return them" do - knife('list --local -Rfp /').should_succeed <<EOM + knife("list --local -Rfp /").should_succeed <<EOM /data_bags/ /data_bags/bag1/ /data_bags/bag1/item1.json @@ -160,62 +160,62 @@ EOM when_the_repository "has extraneous subdirectories and files under a cookbook" do before 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', {} + 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', {} + 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', {} + 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', {} + 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', {} + 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', {} + 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', {} + 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', {} + directory "providers" do + file "a.rb", "" + file "b.json", {} + file "c/d.rb", "" + file "c/e.json", {} end end end it "knife list --local -Rfp / should NOT return them" do - knife('list --local -Rfp /').should_succeed <<EOM + knife("list --local -Rfp /").should_succeed <<EOM /cookbooks/ /cookbooks/cookbook1/ /cookbooks/cookbook1/a.rb @@ -231,6 +231,10 @@ EOM /cookbooks/cookbook1/files/c/e.json /cookbooks/cookbook1/libraries/ /cookbooks/cookbook1/libraries/a.rb +/cookbooks/cookbook1/libraries/b.json +/cookbooks/cookbook1/libraries/c/ +/cookbooks/cookbook1/libraries/c/d.rb +/cookbooks/cookbook1/libraries/c/e.json /cookbooks/cookbook1/providers/ /cookbooks/cookbook1/providers/a.rb /cookbooks/cookbook1/providers/c/ @@ -252,41 +256,41 @@ EOM end when_the_repository "has a file in cookbooks/" do - before { file 'cookbooks/file', '' } - it 'does not show up in list -Rfp' do - knife('list --local -Rfp /').should_succeed <<EOM + before { file "cookbooks/file", "" } + it "does not show up in list -Rfp" do + knife("list --local -Rfp /").should_succeed <<EOM /cookbooks/ EOM end end when_the_repository "has a file in data_bags/" do - before { file 'data_bags/file', '' } - it 'does not show up in list -Rfp' do - knife('list --local -Rfp /').should_succeed <<EOM + before { file "data_bags/file", "" } + it "does not show up in list -Rfp" do + knife("list --local -Rfp /").should_succeed <<EOM /data_bags/ EOM end end end - when_the_repository 'has a cookbook starting with .' do + when_the_repository "has a cookbook starting with ." do before do - file 'cookbooks/.svn/metadata.rb', '' - file 'cookbooks/a.b/metadata.rb', '' + 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" + 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 + when_the_repository "has a data bag starting with ." do before do - file 'data_bags/.svn/x.json', {} - file 'data_bags/a.b/x.json', {} + 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" + it "knife list does not show it" do + knife("list --local -fp /data_bags").should_succeed "/data_bags/a.b/\n" end end end diff --git a/spec/integration/knife/chefignore_spec.rb b/spec/integration/knife/chefignore_spec.rb index 34bf391f88..aa5a3979cc 100644 --- a/spec/integration/knife/chefignore_spec.rb +++ b/spec/integration/knife/chefignore_spec.rb @@ -1,6 +1,6 @@ # -# Author:: John Keiser (<jkeiser@opscode.com>) -# Copyright:: Copyright (c) 2013 Opscode, Inc. +# Author:: John Keiser (<jkeiser@chef.io>) +# Copyright:: Copyright 2013-2016, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,37 +15,37 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'support/shared/integration/integration_helper' -require 'chef/knife/list' -require 'chef/knife/show' +require "support/shared/integration/integration_helper" +require "chef/knife/list" +require "chef/knife/show" -describe 'chefignore tests', :workstation do +describe "chefignore tests", :workstation do include IntegrationSupport include KnifeSupport when_the_repository "has lots of stuff in it" do before do - file 'roles/x.json', {} - file 'environments/x.json', {} - file 'data_bags/bag1/x.json', {} - file 'cookbooks/cookbook1/x.json', {} + 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 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 + 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 + it "matching files and directories get ignored" do # NOTE: many of the "chefignore" files should probably not show up # themselves, but we have other tests that talk about that - knife('list --local -Rfp /').should_succeed <<EOM + knife("list --local -Rfp /").should_succeed <<EOM /cookbooks/ /cookbooks/cookbook1/ /cookbooks/cookbook1/chefignore @@ -61,15 +61,15 @@ EOM end end - when_the_repository 'has a cookbook with only chefignored files' do + when_the_repository "has a cookbook with only chefignored files" do 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" + 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") + 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") /cookbooks/ EOM end @@ -77,17 +77,17 @@ EOM when_the_repository "has multiple cookbooks" do before do - file 'cookbooks/cookbook1/x.json', {} - file 'cookbooks/cookbook1/y.json', {} - file 'cookbooks/cookbook2/x.json', {} - file 'cookbooks/cookbook2/y.json', {} + 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 - before { file 'cookbooks/chefignore', "x.json\n" } + context "and has a chefignore with filenames" do + 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 + it "matching files and directories get ignored in all cookbooks" do + knife("list --local -Rfp /").should_succeed <<EOM /cookbooks/ /cookbooks/cookbook1/ /cookbooks/cookbook1/y.json @@ -99,12 +99,12 @@ EOM context "and has a chefignore with wildcards" do before do - file 'cookbooks/chefignore', "x.*\n" - file 'cookbooks/cookbook1/x.rb', '' + 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 + it "matching files and directories get ignored in all cookbooks" do + knife("list --local -Rfp /").should_succeed <<EOM /cookbooks/ /cookbooks/cookbook1/ /cookbooks/cookbook1/y.json @@ -116,13 +116,13 @@ EOM context "and has a chefignore with relative paths" do before do - file 'cookbooks/cookbook1/recipes/x.rb', '' - file 'cookbooks/cookbook2/recipes/y.rb', '' - file 'cookbooks/chefignore', "recipes/x.rb\n" + 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 + it "matching directories get ignored" do + knife("list --local -Rfp /").should_succeed <<EOM /cookbooks/ /cookbooks/cookbook1/ /cookbooks/cookbook1/x.json @@ -138,12 +138,12 @@ EOM context "and has a chefignore with subdirectories" do before do - file 'cookbooks/cookbook1/recipes/y.rb', '' - file 'cookbooks/chefignore', "recipes\nrecipes/\n" + 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 + it "matching directories do NOT get ignored" do + knife("list --local -Rfp /").should_succeed <<EOM /cookbooks/ /cookbooks/cookbook1/ /cookbooks/cookbook1/recipes/ @@ -159,13 +159,13 @@ EOM context "and has a chefignore that ignores all files in a subdirectory" do 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" + 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 + it "ignores the subdirectory entirely" do + knife("list --local -Rfp /").should_succeed <<EOM /cookbooks/ /cookbooks/cookbook1/ /cookbooks/cookbook1/x.json @@ -179,11 +179,11 @@ EOM context "and has an empty chefignore" do before do - file 'cookbooks/chefignore', "\n" + file "cookbooks/chefignore", "\n" end - it 'nothing is ignored' do - knife('list --local -Rfp /').should_succeed <<EOM + it "nothing is ignored" do + knife("list --local -Rfp /").should_succeed <<EOM /cookbooks/ /cookbooks/cookbook1/ /cookbooks/cookbook1/x.json @@ -197,11 +197,11 @@ EOM context "and has a chefignore with comments and empty lines" do before do - file 'cookbooks/chefignore', "\n\n # blah\n#\nx.json\n\n" + 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 + it "matching files and directories get ignored in all cookbooks" do + knife("list --local -Rfp /").should_succeed <<EOM /cookbooks/ /cookbooks/cookbook1/ /cookbooks/cookbook1/y.json @@ -215,25 +215,25 @@ EOM when_the_repository "has multiple cookbook paths" do before :each do Chef::Config.cookbook_path = [ - File.join(Chef::Config.chef_repo_path, 'cookbooks1'), - File.join(Chef::Config.chef_repo_path, 'cookbooks2') + File.join(Chef::Config.chef_repo_path, "cookbooks1"), + File.join(Chef::Config.chef_repo_path, "cookbooks2"), ] end before do - file 'cookbooks1/mycookbook/metadata.rb', '' - file 'cookbooks1/mycookbook/x.json', {} - file 'cookbooks2/yourcookbook/metadata.rb', '' - file 'cookbooks2/yourcookbook/x.json', '' + 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 before do - file 'cookbooks1/chefignore', "metadata.rb\n" - file 'cookbooks2/chefignore', "x.json\n" + 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 + knife("list --local -Rfp /").should_succeed <<EOM /cookbooks/ /cookbooks/mycookbook/ /cookbooks/mycookbook/x.json @@ -244,14 +244,14 @@ EOM context "and conflicting cookbooks" do before do - file 'cookbooks1/yourcookbook/metadata.rb', '' - file 'cookbooks1/yourcookbook/x.json', '' - file 'cookbooks1/yourcookbook/onlyincookbooks1.rb', '' - file 'cookbooks2/yourcookbook/onlyincookbooks2.rb', '' + 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") + 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") /cookbooks/ /cookbooks/mycookbook/ /cookbooks/mycookbook/x.json @@ -264,32 +264,32 @@ EOM end end - when_the_repository 'has a cookbook named chefignore' do + when_the_repository "has a cookbook named chefignore" do before do - file 'cookbooks/chefignore/metadata.rb', {} + file "cookbooks/chefignore/metadata.rb", {} end - it 'knife list -Rfp /cookbooks shows it' do - knife('list --local -Rfp /cookbooks').should_succeed <<EOM + it "knife list -Rfp /cookbooks shows it" do + knife("list --local -Rfp /cookbooks").should_succeed <<EOM /cookbooks/chefignore/ /cookbooks/chefignore/metadata.rb EOM end end - when_the_repository 'has multiple cookbook paths, one with a chefignore file and the other with a cookbook named chefignore' do + when_the_repository "has multiple cookbook paths, one with a chefignore file and the other with a cookbook named chefignore" do before do - file 'cookbooks1/chefignore', '' - file 'cookbooks1/blah/metadata.rb', '' - file 'cookbooks2/chefignore/metadata.rb', '' + 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'), - File.join(Chef::Config.chef_repo_path, 'cookbooks2') + File.join(Chef::Config.chef_repo_path, "cookbooks1"), + File.join(Chef::Config.chef_repo_path, "cookbooks2"), ] end - it 'knife list -Rfp /cookbooks shows the chefignore cookbook' do - knife('list --local -Rfp /cookbooks').should_succeed <<EOM + it "knife list -Rfp /cookbooks shows the chefignore cookbook" do + knife("list --local -Rfp /cookbooks").should_succeed <<EOM /cookbooks/blah/ /cookbooks/blah/metadata.rb /cookbooks/chefignore/ diff --git a/spec/integration/knife/client_bulk_delete_spec.rb b/spec/integration/knife/client_bulk_delete_spec.rb new file mode 100644 index 0000000000..a422401af6 --- /dev/null +++ b/spec/integration/knife/client_bulk_delete_spec.rb @@ -0,0 +1,130 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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" + +describe "knife client bulk delete", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + when_the_chef_server "has some clients" do + before do + client "concat", {} + client "cons", {} + client "car", {} + client "cdr", {} + client "cat", {} + end + + it "deletes all matching clients" do + knife("client bulk delete ^ca.*", input: "Y").should_succeed <<EOM +The following clients will be deleted: + +car cat + +Are you sure you want to delete these clients? (Y/N) Deleted client car +Deleted client cat +EOM + + knife("client list").should_succeed <<EOM +cdr +chef-validator +chef-webui +concat +cons +EOM + end + + it "deletes all matching clients when unanchored" do + knife("client bulk delete ca.*", input: "Y").should_succeed <<EOM +The following clients will be deleted: + +car cat concat + +Are you sure you want to delete these clients? (Y/N) Deleted client car +Deleted client cat +Deleted client concat +EOM + + knife("client list").should_succeed <<EOM +cdr +chef-validator +chef-webui +cons +EOM + end + end + + when_the_chef_server "has a validator client" do + before do + client "cons", {} + client "car", {} + client "car-validator", { validator: true } + client "cdr", {} + client "cat", {} + end + + it "refuses to delete a validator normally" do + knife("client bulk delete ^ca.*", input: "Y").should_succeed <<EOM +The following clients are validators and will not be deleted: + +car-validator + +You must specify --delete-validators to delete the validator clients +The following clients will be deleted: + +car cat + +Are you sure you want to delete these clients? (Y/N) Deleted client car +Deleted client cat +EOM + + knife("client list").should_succeed <<EOM +car-validator +cdr +chef-validator +chef-webui +cons +EOM + end + + it "deletes a validator when told to" do + knife("client bulk delete ^ca.* -D", input: "Y\nY").should_succeed <<EOM +The following validators will be deleted: + +car-validator + +Are you sure you want to delete these validators? (Y/N) Deleted client car-validator +The following clients will be deleted: + +car cat + +Are you sure you want to delete these clients? (Y/N) Deleted client car +Deleted client cat +EOM + + knife("client list").should_succeed <<EOM +cdr +chef-validator +chef-webui +cons +EOM + end + end +end diff --git a/spec/integration/knife/client_create_spec.rb b/spec/integration/knife/client_create_spec.rb new file mode 100644 index 0000000000..10172833c8 --- /dev/null +++ b/spec/integration/knife/client_create_spec.rb @@ -0,0 +1,69 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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 "openssl" + +describe "knife client create", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + let(:out) { "Created client[bah]\n" } + + when_the_chef_server "is empty" do + it "creates a new client" do + knife("client create -k bah").should_succeed stderr: out + end + + it "creates a new validator client" do + knife("client create -k --validator bah").should_succeed stderr: out + knife("client show bah").should_succeed <<EOM +admin: false +chef_type: client +name: bah +validator: true +EOM + end + + it "refuses to add an existing client" do + pending "Knife client create must not blindly overwrite an existing client" + knife("client create -k bah").should_succeed stderr: out + expect { knife("client create -k bah") }.to raise_error(Net::HTTPServerException) + end + + it "saves the private key to a file" do + Dir.mktmpdir do |tgt| + knife("client create -f #{tgt}/bah.pem bah").should_succeed stderr: out + expect(File).to exist("#{tgt}/bah.pem") + end + end + + it "reads the public key from a file" do + Dir.mktmpdir do |tgt| + key = OpenSSL::PKey::RSA.generate(1024) + File.open("#{tgt}/public.pem", "w") { |pub| pub.write(key.public_key.to_pem) } + knife("client create -p #{tgt}/public.pem bah").should_succeed stderr: out + end + end + + it "refuses to run if conflicting options are passed" do + knife("client create -p public.pem --prevent-keygen blah").should_fail stderr: "FATAL: You cannot pass --public-key and --prevent-keygen\n", stdout: /^USAGE.*/ + end + end +end diff --git a/spec/integration/knife/client_delete_spec.rb b/spec/integration/knife/client_delete_spec.rb new file mode 100644 index 0000000000..d135dd0a5b --- /dev/null +++ b/spec/integration/knife/client_delete_spec.rb @@ -0,0 +1,63 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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" + +describe "knife client delete", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + when_the_chef_server "has some clients" do + before do + client "cons", {} + client "car", {} + client "car-validator", { validator: true } + client "cdr", {} + client "cat", {} + end + + it "deletes a client" do + knife("client delete car", input: "Y").should_succeed <<EOM +Do you really want to delete car? (Y/N) Deleted client[car] +EOM + + knife("client list").should_succeed <<EOM +car-validator +cat +cdr +chef-validator +chef-webui +cons +EOM + end + + it "refuses to delete a validator normally" do + knife("client delete car-validator", input: "Y").should_fail exit_code: 2, stdout: "Do you really want to delete car-validator? (Y/N) ", stderr: <<EOM +FATAL: You must specify --delete-validators to delete the validator client car-validator +EOM + end + + it "deletes a validator correctly" do + knife("client delete car-validator -D", input: "Y").should_succeed <<EOM +Do you really want to delete car-validator? (Y/N) Deleted client[car-validator] +EOM + end + + end +end diff --git a/spec/integration/knife/client_key_create_spec.rb b/spec/integration/knife/client_key_create_spec.rb new file mode 100644 index 0000000000..b588afbe50 --- /dev/null +++ b/spec/integration/knife/client_key_create_spec.rb @@ -0,0 +1,65 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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 "openssl" + +describe "knife client key create", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + let(:out) { "Created key: new" } + + when_the_chef_server "has a client" do + before do + client "bah", {} + end + + it "creates a new client key" do + knife("client key create -k new bah").should_succeed stderr: /^#{out}/, stdout: /.*BEGIN RSA PRIVATE KEY/ + end + + it "creates a new client key with an expiration date" do + date = "2017-12-31T23:59:59Z" + knife("client key create -k new -e #{date} bah").should_succeed stderr: /^#{out}/, stdout: /.*BEGIN RSA PRIVATE KEY/ + knife("client key show bah new").should_succeed /expiration_date:.*#{date}/ + end + + it "refuses to add an already existing key" do + knife("client key create -k new bah") + expect { knife("client key create -k new bah") }.to raise_error(Net::HTTPServerException) + end + + it "saves the private key to a file" do + Dir.mktmpdir do |tgt| + knife("client key create -f #{tgt}/bah.pem -k new bah").should_succeed stderr: /^#{out}/ + expect(File).to exist("#{tgt}/bah.pem") + end + end + + it "reads the public key from a file" do + Dir.mktmpdir do |tgt| + key = OpenSSL::PKey::RSA.generate(1024) + File.open("#{tgt}/public.pem", "w") { |pub| pub.write(key.public_key.to_pem) } + knife("client key create -p #{tgt}/public.pem -k new bah").should_succeed stderr: /^#{out}/ + end + end + + end +end diff --git a/spec/integration/knife/client_key_delete_spec.rb b/spec/integration/knife/client_key_delete_spec.rb new file mode 100644 index 0000000000..d5827aa545 --- /dev/null +++ b/spec/integration/knife/client_key_delete_spec.rb @@ -0,0 +1,42 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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" + +describe "knife client key delete", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + when_the_chef_server "has a client" do + before do + client "car", {} + end + + it "deletes a client" do + out = "Do you really want to delete the key named new for the client named car? (Y/N) " + knife("client key create -k new car") + knife("client key delete car new", input: "Y").should_succeed stdout: out, stderr: <<EOM +Deleted key named new for the client named car +EOM + + knife("client key list car").should_succeed "" + end + + end +end diff --git a/spec/integration/knife/client_key_list_spec.rb b/spec/integration/knife/client_key_list_spec.rb new file mode 100644 index 0000000000..de9894622e --- /dev/null +++ b/spec/integration/knife/client_key_list_spec.rb @@ -0,0 +1,60 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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 "date" + +describe "knife client key list", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + let(:now) { DateTime.now } + let(:last_month) { (now << 1).strftime("%FT%TZ") } + let(:next_month) { (now >> 1).strftime("%FT%TZ") } + + when_the_chef_server "has a client" do + before do + client "cons", {} + knife("client key create cons -k new") + knife("client key create cons -k next_month -e #{next_month}") + knife("client key create cons -k expired -e #{last_month}") + end + + it "lists the keys for a client" do + knife("client key list cons").should_succeed "expired\nnew\nnext_month\n" + end + + it "shows detailed output" do + knife("client key list -w cons").should_succeed <<EOM +expired: http://127.0.0.1:8900/clients/cons/keys/expired (expired) +new: http://127.0.0.1:8900/clients/cons/keys/new +next_month: http://127.0.0.1:8900/clients/cons/keys/next_month +EOM + end + + it "lists the expired keys for a client" do + knife("client key list -e cons").should_succeed "expired\n" + end + + it "lists the unexpired keys for a client" do + knife("client key list -n cons").should_succeed "new\nnext_month\n" + end + + end +end diff --git a/spec/integration/knife/client_key_show_spec.rb b/spec/integration/knife/client_key_show_spec.rb new file mode 100644 index 0000000000..e96ff3b6fe --- /dev/null +++ b/spec/integration/knife/client_key_show_spec.rb @@ -0,0 +1,44 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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 "date" + +describe "knife client key show", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + let(:now) { DateTime.now } + let(:last_month) { (now << 1).strftime("%FT%TZ") } + let(:next_month) { (now >> 1).strftime("%FT%TZ") } + + when_the_chef_server "has a client" do + before do + client "cons", {} + knife("client key create cons -k new") + knife("client key create cons -k next_month -e #{next_month}") + knife("client key create cons -k expired -e #{last_month}") + end + + it "shows a key for a client" do + knife("client key show cons new").should_succeed stdout: /.*name:.*new/ + end + + end +end diff --git a/spec/integration/knife/client_list_spec.rb b/spec/integration/knife/client_list_spec.rb new file mode 100644 index 0000000000..4159df73f1 --- /dev/null +++ b/spec/integration/knife/client_list_spec.rb @@ -0,0 +1,48 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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" + +describe "knife client list", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + when_the_chef_server "has some clients" do + before do + client "cons", {} + client "car", {} + client "car-validator", { validator: true } + client "cdr", {} + client "cat", {} + end + + it "lists the clients" do + knife("client list").should_succeed <<EOM +car +car-validator +cat +cdr +chef-validator +chef-webui +cons +EOM + end + + end +end diff --git a/spec/integration/knife/client_show_spec.rb b/spec/integration/knife/client_show_spec.rb new file mode 100644 index 0000000000..23ac204d77 --- /dev/null +++ b/spec/integration/knife/client_show_spec.rb @@ -0,0 +1,36 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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" + +describe "knife client show", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + when_the_chef_server "has a client" do + before do + client "cons", {} + end + + it "shows a client" do + knife("client show cons").should_succeed stdout: /.*name:.*cons/ + end + + end +end diff --git a/spec/integration/knife/common_options_spec.rb b/spec/integration/knife/common_options_spec.rb index b2e2e3fc2a..c941dcc1ee 100644 --- a/spec/integration/knife/common_options_spec.rb +++ b/spec/integration/knife/common_options_spec.rb @@ -1,6 +1,6 @@ # -# Author:: John Keiser (<jkeiser@opscode.com>) -# Copyright:: Copyright (c) 2013 Opscode, Inc. +# Author:: John Keiser (<jkeiser@chef.io>) +# Copyright:: Copyright 2013-2016, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,46 +15,46 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'support/shared/integration/integration_helper' -require 'chef/knife/raw' +require "support/shared/integration/integration_helper" +require "chef/knife/raw" -describe 'knife common options', :workstation do +describe "knife common options", :workstation do include IntegrationSupport include KnifeSupport when_the_repository "has a node" do - before { file 'nodes/x.json', {} } + before { file "nodes/x.json", {} } - context 'When chef_zero.enabled is true' do + context "When chef_zero.enabled is true" do before(:each) do Chef::Config.chef_zero.enabled = true end - it 'knife raw /nodes/x should retrieve the node' do - knife('raw /nodes/x').should_succeed( /"name": "x"/ ) + it "knife raw /nodes/x should retrieve the node" do + knife("raw /nodes/x").should_succeed( /"name": "x"/ ) end - context 'And chef_zero.port is 9999' do + 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"/ ) - expect(Chef::Config.chef_server_url).to eq('chefzero://localhost:9999') + it "knife raw /nodes/x should retrieve the node" do + knife("raw /nodes/x").should_succeed( /"name": "x"/ ) + expect(Chef::Config.chef_server_url).to eq("chefzero://localhost:9999") end end # 0.0.0.0 is not a valid address to bind to on windows. - context 'And chef_zero.host is 0.0.0.0', :unix_only do - before(:each) { Chef::Config.chef_zero.host = '0.0.0.0' } + context "And chef_zero.host is 0.0.0.0", :unix_only 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"/ ) + it "knife raw /nodes/x should retrieve the role" do + knife("raw /nodes/x").should_succeed( /"name": "x"/ ) end end - context 'and there is a private key' do + context "and there is a private key" do before do - file 'mykey.pem', <<EOM + file "mykey.pem", <<EOM -----BEGIN RSA PRIVATE KEY----- MIIEogIBAAKCAQEApubutqtYYQ5UiA9QhWP7UvSmsfHsAoPKEVVPdVW/e8Svwpyf 0Xef6OFWVmBE+W442ZjLOe2y6p2nSnaq4y7dg99NFz6X+16mcKiCbj0RCiGqCvCk @@ -85,29 +85,29 @@ syHLXYFNy0OxMtH/bBAXBGNHd9gf5uOnqh0pYcbe/uRAxumC7Rl0cL509eURiA2T EOM end - it 'knife raw /nodes/x should retrieve the node' do - knife('raw /nodes/x').should_succeed( /"name": "x"/ ) + it "knife raw /nodes/x should retrieve the node" do + 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"/ ) + it "knife raw -z /nodes/x retrieves the node" do + 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"/ ) + it "knife raw --local-mode /nodes/x retrieves the node" do + 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"/ ) - expect(Chef::Config.chef_server_url).to eq('chefzero://localhost:9999') + 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"/ ) + expect(Chef::Config.chef_server_url).to eq("chefzero://localhost:9999") end - context 'when the default port (8889) is already bound' do + context "when the default port (8889) is already bound" do before :each do begin - @server = ChefZero::Server.new(:host => 'localhost', :port => 8889) + @server = ChefZero::Server.new(:host => "localhost", :port => 8889) @server.start_background rescue Errno::EADDRINUSE # OK. Don't care who has it in use, as long as *someone* does. @@ -117,16 +117,16 @@ EOM @server.stop if @server end - it 'knife raw -z /nodes/x retrieves the node' do - knife('raw -z /nodes/x').should_succeed( /"name": "x"/ ) + it "knife raw -z /nodes/x retrieves the node" do + knife("raw -z /nodes/x").should_succeed( /"name": "x"/ ) expect(URI(Chef::Config.chef_server_url).port).to be > 8889 end end - context 'when port 9999 is already bound' do + context "when port 9999 is already bound" do before :each do begin - @server = ChefZero::Server.new(:host => 'localhost', :port => 9999) + @server = ChefZero::Server.new(:host => "localhost", :port => 9999) @server.start_background rescue Errno::EADDRINUSE # OK. Don't care who has it in use, as long as *someone* does. @@ -136,20 +136,20 @@ EOM @server.stop if @server 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"/ ) + 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"/ ) 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"/ ) + 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"/ ) 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"/ ) - expect(Chef::Config.chef_server_url).to eq('chefzero://localhost:9999') + 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"/ ) + expect(Chef::Config.chef_server_url).to eq("chefzero://localhost:9999") end end end diff --git a/spec/integration/knife/cookbook_api_ipv6_spec.rb b/spec/integration/knife/cookbook_api_ipv6_spec.rb index 3d468be7f6..0a4a6a6e94 100644 --- a/spec/integration/knife/cookbook_api_ipv6_spec.rb +++ b/spec/integration/knife/cookbook_api_ipv6_spec.rb @@ -1,6 +1,6 @@ # -# Author:: Daniel DeLeo (<dan@opscode.com>) -# Copyright:: Copyright (c) 2013 Opscode, Inc. +# Author:: Daniel DeLeo (<dan@chef.io>) +# Copyright:: Copyright 2013-2016, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,15 +15,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'support/shared/integration/integration_helper' -require 'chef/mixin/shell_out' +require "support/shared/integration/integration_helper" +require "chef/mixin/shell_out" -describe "Knife cookbook API integration with IPv6", :workstation do +describe "Knife cookbook API integration with IPv6", :workstation, :not_supported_on_gce do include IntegrationSupport include Chef::Mixin::ShellOut when_the_chef_server "is bound to IPv6" do - let(:chef_zero_opts) { {:host => "::1"} } + let(:chef_zero_opts) { { :host => "::1" } } let(:client_key) do <<-END_VALIDATION_PEM @@ -84,8 +84,8 @@ END_CLIENT_RB end before do - file 'config/knife.rb', knife_rb_content - file 'config/knifeuser.pem', client_key + file "config/knife.rb", knife_rb_content + file "config/knifeuser.pem", client_key end it "successfully uploads a cookbook" do @@ -102,7 +102,7 @@ END_CLIENT_RB it "downloads the cookbook" do shell_out!("knife cookbook download apache2 #{knife_config_flag} -d #{cache_path}", :cwd => chef_dir) - expect(Dir["#{cache_path}/*"].map {|entry| File.basename(entry)}).to include("apache2-0.0.1") + expect(Dir["#{cache_path}/*"].map { |entry| File.basename(entry) }).to include("apache2-0.0.1") end end diff --git a/spec/integration/knife/cookbook_bulk_delete_spec.rb b/spec/integration/knife/cookbook_bulk_delete_spec.rb new file mode 100644 index 0000000000..4740813ce1 --- /dev/null +++ b/spec/integration/knife/cookbook_bulk_delete_spec.rb @@ -0,0 +1,64 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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/cookbook_bulk_delete" + +describe "knife cookbook bulk delete", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + when_the_chef_server "has a cookbook" do + before do + cookbook "foo", "1.0.0" + cookbook "foo", "0.6.5" + cookbook "fox", "0.6.0" + cookbook "fox", "0.6.5" + cookbook "fax", "0.6.0" + cookbook "zfa", "0.6.5" + end + + # rubocop:disable Style/TrailingWhitespace + it "knife cookbook bulk delete deletes all matching cookbooks" do + stdout = <<EOM +All versions of the following cookbooks will be deleted: + +foo fox + +Do you really want to delete these cookbooks? (Y/N) +EOM + + stderr = <<EOM +Deleted cookbook foo [1.0.0] +Deleted cookbook foo [0.6.5] +Deleted cookbook fox [0.6.5] +Deleted cookbook fox [0.6.0] +EOM + + knife("cookbook bulk delete ^fo.*", input: "Y").should_succeed(stderr: stderr, stdout: stdout) + + knife("cookbook list -a").should_succeed <<EOM +fax 0.6.0 +zfa 0.6.5 +EOM + end + # rubocop:enable Style/TrailingWhitespace + + end +end diff --git a/spec/integration/knife/cookbook_download_spec.rb b/spec/integration/knife/cookbook_download_spec.rb new file mode 100644 index 0000000000..2fbffb9dea --- /dev/null +++ b/spec/integration/knife/cookbook_download_spec.rb @@ -0,0 +1,95 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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/cookbook_download" +require "tmpdir" + +describe "knife cookbook download", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + let(:tmpdir) { Dir.mktmpdir } + + when_the_chef_server "has only one cookbook" do + before do + cookbook "x", "1.0.1" + end + + it "knife cookbook download downloads the latest version" do + knife("cookbook download -d #{tmpdir} x").should_succeed stderr: <<EOM +Downloading x cookbook version 1.0.1 +Downloading resources +Downloading providers +Downloading recipes +Downloading definitions +Downloading libraries +Downloading attributes +Downloading files +Downloading templates +Downloading root_files +Cookbook downloaded to #{tmpdir}/x-1.0.1 +EOM + end + + it "knife cookbook download with a version downloads the specified version" do + knife("cookbook download -d #{tmpdir} x 1.0.1").should_succeed stderr: <<EOM +Downloading x cookbook version 1.0.1 +Downloading resources +Downloading providers +Downloading recipes +Downloading definitions +Downloading libraries +Downloading attributes +Downloading files +Downloading templates +Downloading root_files +Cookbook downloaded to #{tmpdir}/x-1.0.1 +EOM + end + + it "knife cookbook download with an unknown version raises an error" do + expect { knife("cookbook download -d #{tmpdir} x 1.0.0") }.to raise_error(Net::HTTPServerException) + end + end + + when_the_chef_server "has multiple cookbook versions" do + before do + cookbook "x", "1.0.1" + cookbook "x", "1.0.0" + end + + it "knife cookbook download with no version prompts" do + knife("cookbook download -d #{tmpdir} x", input: "2\n").should_succeed(stderr: <<EOM, stdout: "Which version do you want to download?\n1. x 1.0.0\n2. x 1.0.1\n\n" +Downloading x cookbook version 1.0.1 +Downloading resources +Downloading providers +Downloading recipes +Downloading definitions +Downloading libraries +Downloading attributes +Downloading files +Downloading templates +Downloading root_files +Cookbook downloaded to #{tmpdir}/x-1.0.1 +EOM +) + end + end +end diff --git a/spec/integration/knife/cookbook_list_spec.rb b/spec/integration/knife/cookbook_list_spec.rb new file mode 100644 index 0000000000..65578696f2 --- /dev/null +++ b/spec/integration/knife/cookbook_list_spec.rb @@ -0,0 +1,54 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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/cookbook_list" + +describe "knife cookbook list", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + when_the_chef_server "has a cookbook" do + before do + cookbook "x", "1.0.0" + cookbook "x", "0.6.5" + cookbook "x", "0.6.0" + cookbook "y", "0.6.5" + cookbook "y", "0.6.0" + cookbook "z", "0.6.5" + end + + it "knife cookbook list shows all the cookbooks" do + knife("cookbook list").should_succeed <<EOM +x 1.0.0 +y 0.6.5 +z 0.6.5 +EOM + end + + it "knife cookbook list -a shows all the versions of all the cookbooks" do + knife("cookbook list -a").should_succeed <<EOM +x 1.0.0 0.6.5 0.6.0 +y 0.6.5 0.6.0 +z 0.6.5 +EOM + end + + end +end diff --git a/spec/integration/knife/cookbook_show_spec.rb b/spec/integration/knife/cookbook_show_spec.rb new file mode 100644 index 0000000000..c001d66b97 --- /dev/null +++ b/spec/integration/knife/cookbook_show_spec.rb @@ -0,0 +1,159 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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/cookbook_show" + +describe "knife cookbook show", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + when_the_chef_server "has a cookbook" do + before do + cookbook "x", "1.0.0", { "recipes" => { "default.rb" => "file 'n'", "x.rb" => "" } } + cookbook "x", "0.6.5" + end + + it "knife cookbook show x shows all the versions" do + knife("cookbook show x").should_succeed "x 1.0.0 0.6.5\n" + end + + # rubocop:disable Style/TrailingWhitespace + it "knife cookbook show x 1.0.0 shows the correct version" do + knife("cookbook show x 1.0.0").should_succeed <<EOM +attributes: +chef_type: cookbook_version +cookbook_name: x +definitions: +files: +frozen?: false +json_class: Chef::CookbookVersion +libraries: +metadata: + attributes: + chef_versions: + conflicting: + dependencies: + description: + gems: + groupings: + issues_url: + license: All rights reserved + long_description: + maintainer: + maintainer_email: + name: x + ohai_versions: + platforms: + privacy: false + providing: + recipes: + recommendations: + replacing: + source_url: + suggestions: + version: 1.0.0 +name: x-1.0.0 +providers: +recipes: + checksum: 4631b34cf58de10c5ef1304889941b2e + name: default.rb + path: recipes/default.rb + specificity: default + url: http://127.0.0.1:8900/file_store/checksums/4631b34cf58de10c5ef1304889941b2e + + checksum: d41d8cd98f00b204e9800998ecf8427e + name: x.rb + path: recipes/x.rb + specificity: default + url: http://127.0.0.1:8900/file_store/checksums/d41d8cd98f00b204e9800998ecf8427e +resources: +root_files: + checksum: 8226671f751ba102dea6a6b6bd32fa8d + name: metadata.rb + path: metadata.rb + specificity: default + url: http://127.0.0.1:8900/file_store/checksums/8226671f751ba102dea6a6b6bd32fa8d +templates: +version: 1.0.0 +EOM + end + + it "knife cookbook show x 1.0.0 metadata shows the metadata" do + knife("cookbook show x 1.0.0 metadata").should_succeed <<EOM +attributes: +chef_versions: +conflicting: +dependencies: +description: +gems: +groupings: +issues_url: +license: All rights reserved +long_description: +maintainer: +maintainer_email: +name: x +ohai_versions: +platforms: +privacy: false +providing: +recipes: +recommendations: +replacing: +source_url: +suggestions: +version: 1.0.0 +EOM + end + + it "knife cookbook show x 1.0.0 recipes shows all the recipes" do + knife("cookbook show x 1.0.0 recipes").should_succeed <<EOM +checksum: 4631b34cf58de10c5ef1304889941b2e +name: default.rb +path: recipes/default.rb +specificity: default +url: http://127.0.0.1:8900/file_store/checksums/4631b34cf58de10c5ef1304889941b2e + +checksum: d41d8cd98f00b204e9800998ecf8427e +name: x.rb +path: recipes/x.rb +specificity: default +url: http://127.0.0.1:8900/file_store/checksums/d41d8cd98f00b204e9800998ecf8427e +EOM + end + # rubocop:enable Style/TrailingWhitespace + + it "knife cookbook show x 1.0.0 recipes default.rb shows the default recipe" do + knife("cookbook show x 1.0.0 recipes default.rb").should_succeed "file 'n'\n" + end + + it "knife cookbook show with a non-existent file displays an error" do + expect { knife("cookbook show x 1.0.0 recipes moose.rb") }.to raise_error(Chef::Exceptions::FileNotFound) + end + + it "knife cookbook show with a non-existent version displays an error" do + expect { knife("cookbook show x 1.0.1") }.to raise_error(Net::HTTPServerException) + end + + it "knife cookbook show with a non-existent cookbook displays an error" do + expect { knife("cookbook show y") }.to raise_error(Net::HTTPServerException) + end + end +end diff --git a/spec/integration/knife/cookbook_upload_spec.rb b/spec/integration/knife/cookbook_upload_spec.rb new file mode 100644 index 0000000000..a0de725603 --- /dev/null +++ b/spec/integration/knife/cookbook_upload_spec.rb @@ -0,0 +1,90 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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/cookbook_upload" + +describe "knife cookbook upload", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + let (:cb_dir) { "#{@repository_dir}/cookbooks" } + + when_the_chef_server "is empty" do + when_the_repository "has a cookbook" do + before do + file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0") + end + + it "knife cookbook upload uploads the cookbook" do + knife("cookbook upload x -o #{cb_dir}").should_succeed stderr: <<EOM +Uploading x [1.0.0] +Uploaded 1 cookbook. +EOM + end + + it "knife cookbook upload --freeze uploads and freezes the cookbook" do + knife("cookbook upload x -o #{cb_dir} --freeze").should_succeed stderr: <<EOM +Uploading x [1.0.0] +Uploaded 1 cookbook. +EOM + # Modify the file, attempt to reupload + file "cookbooks/x/metadata.rb", 'name "x"; version "1.0.0"#different' + knife("cookbook upload x -o #{cb_dir} --freeze").should_fail stderr: <<EOM +Uploading x [1.0.0] +ERROR: Version 1.0.0 of cookbook x is frozen. Use --force to override. +WARNING: Not updating version constraints for x in the environment as the cookbook is frozen. +ERROR: Failed to upload 1 cookbook. +EOM + end + end + + when_the_repository "has a cookbook that depends on another cookbook" do + before do + file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0", "\ndepends 'y'") + file "cookbooks/y/metadata.rb", cb_metadata("y", "1.0.0") + end + + it "knife cookbook upload --include-dependencies uploads both cookbooks" do + knife("cookbook upload --include-dependencies x -o #{cb_dir}").should_succeed stderr: <<EOM +Uploading x [1.0.0] +Uploading y [1.0.0] +Uploaded 2 cookbooks. +EOM + end + + it "knife cookbook upload fails due to missing dependencies" do + knife("cookbook upload x -o #{cb_dir}").should_fail stderr: <<EOM +Uploading x [1.0.0] +ERROR: Cookbook x depends on cookbooks which are not currently +ERROR: being uploaded and cannot be found on the server. +ERROR: The missing cookbook(s) are: 'y' version '>= 0.0.0' +EOM + end + + it "knife cookbook upload -a uploads both cookbooks" do + knife("cookbook upload -a -o #{cb_dir}").should_succeed stderr: <<EOM +Uploading x [1.0.0] +Uploading y [1.0.0] +Uploaded all cookbooks. +EOM + end + end + end +end diff --git a/spec/integration/knife/data_bag_create_spec.rb b/spec/integration/knife/data_bag_create_spec.rb new file mode 100644 index 0000000000..dc61d55fd5 --- /dev/null +++ b/spec/integration/knife/data_bag_create_spec.rb @@ -0,0 +1,55 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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/data_bag_create" + +describe "knife data bag create", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + let(:err) { "Created data_bag[foo]\n" } + let(:out) { "Created data_bag_item[bar]\n" } + let(:exists) { "Data bag foo already exists\n" } + + when_the_chef_server "is empty" do + it "creates a new data bag" do + knife("data bag create foo").should_succeed stderr: err + end + + it "creates a new data bag and item" do + knife("data bag create foo bar").should_succeed stdout: out, stderr: err + end + + it "adds a new item to an existing bag" do + knife("data bag create foo").should_succeed stderr: err + knife("data bag create foo bar").should_succeed stdout: out, stderr: exists + end + + it "refuses to add an existing data bag" do + knife("data bag create foo").should_succeed stderr: err + knife("data bag create foo").should_succeed stderr: exists + end + + it "fails to add an existing item" do + knife("data bag create foo bar").should_succeed stdout: out, stderr: err + expect { knife("data bag create foo bar") }.to raise_error(Net::HTTPServerException) + end + end +end diff --git a/spec/integration/knife/data_bag_delete_spec.rb b/spec/integration/knife/data_bag_delete_spec.rb new file mode 100644 index 0000000000..96345b0d2b --- /dev/null +++ b/spec/integration/knife/data_bag_delete_spec.rb @@ -0,0 +1,58 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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/data_bag_delete" + +describe "knife data bag delete", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + when_the_chef_server "has some data bags" do + before do + data_bag "x", {} + data_bag "canteloupe", {} + data_bag "rocket", { "falcon9" => { heavy: "true" }, "atlas" => {}, "ariane" => {} } + end + + it "with an empty data bag" do + knife("data bag delete canteloupe", input: "y").should_succeed <<EOM +Do you really want to delete canteloupe? (Y/N) Deleted data_bag[canteloupe] +EOM + end + + it "with a bag with some items" do + knife("data bag delete rocket", input: "y").should_succeed <<EOM +Do you really want to delete rocket? (Y/N) Deleted data_bag[rocket] +EOM + end + + it "with a single item" do + knife("data bag delete rocket falcon9", input: "y").should_succeed <<EOM +Do you really want to delete falcon9? (Y/N) Deleted data_bag_item[falcon9] +EOM + end + + it "choosing not to delete" do + knife("data bag delete rocket falcon9", input: "n").should_succeed <<EOM, exit_code: 3 +Do you really want to delete falcon9? (Y/N) You said no, so I'm done here. +EOM + end + end +end diff --git a/spec/integration/knife/data_bag_from_file_spec.rb b/spec/integration/knife/data_bag_from_file_spec.rb new file mode 100644 index 0000000000..ca8f743487 --- /dev/null +++ b/spec/integration/knife/data_bag_from_file_spec.rb @@ -0,0 +1,115 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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" + +describe "knife data bag from file", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + let (:db_dir) { "#{@repository_dir}/data_bags" } + + when_the_chef_server "has an empty data bag" do + before do + data_bag "foo", {} + data_bag "bar", {} + end + + when_the_repository "has some data bag items" do + before do + file "data_bags/foo/bar.json", { "id" => "bar", "foo" => "bar " } + file "data_bags/foo/bzr.json", { "id" => "bzr", "foo" => "bar " } + file "data_bags/foo/cat.json", { "id" => "cat", "foo" => "bar " } + file "data_bags/foo/dog.json", { "id" => "dog", "foo" => "bar " } + file "data_bags/foo/encrypted.json", <<EOM +{ + "id": "encrypted", + "password": { + "encrypted_data": "H6ab5RY9a9JAkS8A0RCMspXtOJh0ai8cNeA4Q3gLO8s=\\n", + "iv": "uWKKKxrJgtELlGMCOLJdkA==\\n", + "version": 1, + "cipher": "aes-256-cbc" + } +} +EOM + file "data_bags/bar/round_trip.json", <<EOM +{ + "name": "data_bag_item_bar_round_trip", + "json_class": "Chef::DataBagItem", + "chef_type": "data_bag_item", + "data_bag": "bar", + "raw_data": { + "id": "round_trip", + "root_password": { + "encrypted_data": "noDOsTpsTAZlTU5sprhmYZzUDfr8du7hH/zRDOjRAmoTJHTZyfYoR221EOOW\\nXJ1D\\n", + "iv": "Bnqhfy6n0Hx1wCe9pxHLoA==\\n", + "version": 1, + "cipher": "aes-256-cbc" + }, + "admin_password": { + "encrypted_data": "TcC7dU1gx6OnE5Ab4i/k42UEf0Nnr7cAyuTHId/LNjNOwpNf7XZc27DQSjuy\\nHPlt\\n", + "iv": "+TAWJuPWCI2+WB8lGJAyvw==\\n", + "version": 1, + "cipher": "aes-256-cbc" + } + } +} +EOM + end + + it "uploads a single file" do + knife("data bag from file foo #{db_dir}/foo/bar.json").should_succeed stderr: <<EOM +Updated data_bag_item[foo::bar] +EOM + end + + it "uploads a single encrypted file" do + knife("data bag from file foo #{db_dir}/foo/encrypted.json").should_succeed stderr: <<EOM +Updated data_bag_item[foo::encrypted] +EOM + end + + it "uploads a file in chef's internal format" do + pending "chef/chef#4815" + knife("data bag from file bar #{db_dir}/bar/round_trip.json").should_succeed stderr: <<EOM +Updated data_bag_item[bar::round_trip] +EOM + end + + it "uploads many files" do + knife("data bag from file foo #{db_dir}/foo/bar.json #{db_dir}/foo/bzr.json").should_succeed stderr: <<EOM +Updated data_bag_item[foo::bar] +Updated data_bag_item[foo::bzr] +EOM + end + + it "uploads a whole directory" do + knife("data bag from file foo #{db_dir}/foo") + knife("data bag show foo").should_succeed <<EOM +bar +bzr +cat +dog +encrypted +EOM + end + + end + end +end diff --git a/spec/integration/knife/data_bag_list_spec.rb b/spec/integration/knife/data_bag_list_spec.rb new file mode 100644 index 0000000000..7db9638660 --- /dev/null +++ b/spec/integration/knife/data_bag_list_spec.rb @@ -0,0 +1,43 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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/data_bag_list" + +describe "knife data bag list", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + when_the_chef_server "has some data bags" do + before do + data_bag "x", {} + data_bag "canteloupe", {} + data_bag "rocket", {} + end + + it "knife data bag list shows all the cookbooks" do + knife("data bag list").should_succeed <<EOM +canteloupe +rocket +x +EOM + end + + end +end diff --git a/spec/integration/knife/data_bag_show_spec.rb b/spec/integration/knife/data_bag_show_spec.rb new file mode 100644 index 0000000000..22381adb9e --- /dev/null +++ b/spec/integration/knife/data_bag_show_spec.rb @@ -0,0 +1,53 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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/data_bag_show" + +describe "knife data bag show", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + when_the_chef_server "has some data bags" do + before do + data_bag "x", {} + data_bag "canteloupe", {} + data_bag "rocket", { "falcon9" => { heavy: "true" }, "atlas" => {}, "ariane" => {} } + end + + it "with an empty data bag" do + knife("data bag show canteloupe").should_succeed "\n" + end + + it "with a bag with some items" do + knife("data bag show rocket").should_succeed <<EOM +ariane +atlas +falcon9 +EOM + end + + it "with a single item" do + knife("data bag show rocket falcon9").should_succeed <<EOM, stderr: "WARNING: Unencrypted data bag detected, ignoring any provided secret options.\n" +heavy: true +id: falcon9 +EOM + end + end +end diff --git a/spec/integration/knife/delete_spec.rb b/spec/integration/knife/delete_spec.rb index 733a7ef72b..1c69fbf9c9 100644 --- a/spec/integration/knife/delete_spec.rb +++ b/spec/integration/knife/delete_spec.rb @@ -1,6 +1,6 @@ # -# Author:: John Keiser (<jkeiser@opscode.com>) -# Copyright:: Copyright (c) 2013 Opscode, Inc. +# Author:: John Keiser (<jkeiser@chef.io>) +# Copyright:: Copyright 2013-2016, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,12 +15,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'support/shared/integration/integration_helper' -require 'chef/knife/delete' -require 'chef/knife/list' -require 'chef/knife/raw' +require "support/shared/integration/integration_helper" +require "chef/knife/delete" +require "chef/knife/list" +require "chef/knife/raw" -describe 'knife delete', :workstation do +describe "knife delete", :workstation do include IntegrationSupport include KnifeSupport @@ -100,39 +100,39 @@ EOM when_the_chef_server "has one of each thing" do before do - client 'x', '{}' - cookbook 'x', '1.0.0' - data_bag 'x', { 'y' => '{}' } - environment 'x', '{}' - node 'x', '{}' - role 'x', '{}' - user 'x', '{}' + 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 + when_the_repository "also has one of each thing" do 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 + 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 ERROR: /cookbooks/x (remote) must be deleted recursively! Pass -r to knife delete. ERROR: /cookbooks/x (local) must be deleted recursively! Pass -r to knife delete. EOM - knife('list -Rf /').should_succeed server_everything - knife('list -Rf --local /').should_succeed everything + knife("list -Rf /").should_succeed server_everything + knife("list -Rf --local /").should_succeed everything end - it 'knife delete --both -r /cookbooks/x deletes x' do - knife('delete --both -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n" - knife('list -Rf /').should_succeed <<EOM + it "knife delete --both -r /cookbooks/x deletes x" do + knife("delete --both -r /cookbooks/x").should_succeed "Deleted /cookbooks/x\n" + knife("list -Rf /").should_succeed <<EOM /clients /clients/chef-validator.json /clients/chef-webui.json @@ -152,7 +152,7 @@ EOM /users/admin.json /users/x.json EOM - knife('list -Rf --local /').should_succeed <<EOM + knife("list -Rf --local /").should_succeed <<EOM /clients /clients/x.json /cookbooks @@ -171,10 +171,10 @@ EOM EOM end - it 'knife delete -r --local /cookbooks/x deletes x locally but not remotely' do - knife('delete -r --local /cookbooks/x').should_succeed "Deleted /cookbooks/x\n" - knife('list -Rf /').should_succeed server_everything - knife('list -Rf --local /').should_succeed <<EOM + it "knife delete -r --local /cookbooks/x deletes x locally but not remotely" do + knife("delete -r --local /cookbooks/x").should_succeed "Deleted /cookbooks/x\n" + knife("list -Rf /").should_succeed server_everything + knife("list -Rf --local /").should_succeed <<EOM /clients /clients/x.json /cookbooks @@ -193,9 +193,9 @@ EOM EOM end - it 'knife delete -r /cookbooks/x deletes x remotely but not locally' do - knife('delete -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n" - knife('list -Rf /').should_succeed <<EOM + it "knife delete -r /cookbooks/x deletes x remotely but not locally" do + knife("delete -r /cookbooks/x").should_succeed "Deleted /cookbooks/x\n" + knife("list -Rf /").should_succeed <<EOM /clients /clients/chef-validator.json /clients/chef-webui.json @@ -215,22 +215,22 @@ EOM /users/admin.json /users/x.json EOM - knife('list -Rf --local /').should_succeed everything + knife("list -Rf --local /").should_succeed everything end # TODO delete empty data bag (particularly different on local side) - context 'with an empty data bag on both' do + context "with an empty data bag on both" do before do - data_bag 'empty', {} - directory 'data_bags/empty' + 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 + 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. ERROR: /data_bags/empty (local) must be deleted recursively! Pass -r to knife delete. EOM - knife('list -Rf /').should_succeed <<EOM + knife("list -Rf /").should_succeed <<EOM /clients /clients/chef-validator.json /clients/chef-webui.json @@ -253,7 +253,7 @@ EOM /users/admin.json /users/x.json EOM - knife('list -Rf --local /').should_succeed <<EOM + knife("list -Rf --local /").should_succeed <<EOM /clients /clients/x.json /cookbooks @@ -276,18 +276,18 @@ EOM end end - it 'knife delete --both /data_bags/x fails' do - knife('delete --both /data_bags/x').should_fail <<EOM + it "knife delete --both /data_bags/x fails" do + knife("delete --both /data_bags/x").should_fail <<EOM ERROR: /data_bags/x (remote) must be deleted recursively! Pass -r to knife delete. ERROR: /data_bags/x (local) must be deleted recursively! Pass -r to knife delete. EOM - knife('list -Rf /').should_succeed server_everything - knife('list -Rf --local /').should_succeed everything + knife("list -Rf /").should_succeed server_everything + knife("list -Rf --local /").should_succeed everything end - it 'knife delete --both -r /data_bags/x deletes x' do - knife('delete --both -r /data_bags/x').should_succeed "Deleted /data_bags/x\n" - knife('list -Rf /').should_succeed <<EOM + it "knife delete --both -r /data_bags/x deletes x" do + knife("delete --both -r /data_bags/x").should_succeed "Deleted /data_bags/x\n" + knife("list -Rf /").should_succeed <<EOM /clients /clients/chef-validator.json /clients/chef-webui.json @@ -307,7 +307,7 @@ EOM /users/admin.json /users/x.json EOM - knife('list -Rf --local /').should_succeed <<EOM + knife("list -Rf --local /").should_succeed <<EOM /clients /clients/x.json /cookbooks @@ -326,9 +326,9 @@ EOM EOM end - it 'knife delete --both /environments/x.json deletes x' do - knife('delete --both /environments/x.json').should_succeed "Deleted /environments/x.json\n" - knife('list -Rf /').should_succeed <<EOM + it "knife delete --both /environments/x.json deletes x" do + knife("delete --both /environments/x.json").should_succeed "Deleted /environments/x.json\n" + knife("list -Rf /").should_succeed <<EOM /clients /clients/chef-validator.json /clients/chef-webui.json @@ -349,7 +349,7 @@ EOM /users/admin.json /users/x.json EOM - knife('list -Rf --local /').should_succeed <<EOM + knife("list -Rf --local /").should_succeed <<EOM /clients /clients/x.json /cookbooks @@ -369,9 +369,9 @@ EOM EOM end - it 'knife delete --both /roles/x.json deletes x' do - knife('delete --both /roles/x.json').should_succeed "Deleted /roles/x.json\n" - knife('list -Rf /').should_succeed <<EOM + it "knife delete --both /roles/x.json deletes x" do + knife("delete --both /roles/x.json").should_succeed "Deleted /roles/x.json\n" + knife("list -Rf /").should_succeed <<EOM /clients /clients/chef-validator.json /clients/chef-webui.json @@ -392,7 +392,7 @@ EOM /users/admin.json /users/x.json EOM - knife('list -Rf --local /').should_succeed <<EOM + knife("list -Rf --local /").should_succeed <<EOM /clients /clients/x.json /cookbooks @@ -412,10 +412,10 @@ EOM EOM end - it 'knife delete --both /environments/_default.json fails but still deletes the local copy' do - knife('delete --both /environments/_default.json').should_fail :stderr => "ERROR: /environments/_default.json (remote) cannot be deleted (default environment cannot be modified).\n", :stdout => "Deleted /environments/_default.json\n" - knife('list -Rf /').should_succeed server_everything - knife('list -Rf --local /').should_succeed <<EOM + it "knife delete --both /environments/_default.json fails but still deletes the local copy" do + knife("delete --both /environments/_default.json").should_fail :stderr => "ERROR: /environments/_default.json (remote) cannot be deleted (default environment cannot be modified).\n", :stdout => "Deleted /environments/_default.json\n" + knife("list -Rf /").should_succeed server_everything + knife("list -Rf --local /").should_succeed <<EOM /clients /clients/x.json /cookbooks @@ -435,23 +435,23 @@ EOM EOM end - it 'knife delete --both /environments/nonexistent.json fails' do - knife('delete --both /environments/nonexistent.json').should_fail "ERROR: /environments/nonexistent.json: No such file or directory\n" - knife('list -Rf /').should_succeed server_everything - knife('list -Rf --local /').should_succeed everything + it "knife delete --both /environments/nonexistent.json fails" do + knife("delete --both /environments/nonexistent.json").should_fail "ERROR: /environments/nonexistent.json: No such file or directory\n" + knife("list -Rf /").should_succeed server_everything + knife("list -Rf --local /").should_succeed everything end - it 'knife delete --both / fails' do - knife('delete --both /').should_fail <<EOM + it "knife delete --both / fails" do + knife("delete --both /").should_fail <<EOM ERROR: / (remote) cannot be deleted. ERROR: / (local) cannot be deleted. EOM - knife('list -Rf /').should_succeed server_everything - knife('list -Rf --local /').should_succeed everything + knife("list -Rf /").should_succeed server_everything + knife("list -Rf --local /").should_succeed everything end - it 'knife delete --both -r /* fails' do - knife('delete --both -r /*').should_fail <<EOM + it "knife delete --both -r /* fails" do + knife("delete --both -r /*").should_fail <<EOM ERROR: / (remote) cannot be deleted. ERROR: / (local) cannot be deleted. ERROR: /clients (remote) cannot be deleted. @@ -469,31 +469,31 @@ ERROR: /roles (local) cannot be deleted. ERROR: /users (remote) cannot be deleted. ERROR: /users (local) cannot be deleted. EOM - knife('list -Rf /').should_succeed server_everything - knife('list -Rf --local /').should_succeed everything + knife("list -Rf /").should_succeed server_everything + knife("list -Rf --local /").should_succeed everything end end - when_the_repository 'has only top-level directories' do + when_the_repository "has only top-level directories" do before do - directory 'clients' - directory 'cookbooks' - directory 'data_bags' - directory 'environments' - directory 'nodes' - directory 'roles' - directory 'users' + 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" - knife('list -Rf /').should_succeed server_everything - knife('list -Rf --local /').should_succeed nothing + 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" + knife("list -Rf /").should_succeed server_everything + knife("list -Rf --local /").should_succeed nothing end - it 'knife delete --both -r /cookbooks/x deletes x' do - knife('delete --both -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n" - knife('list -Rf /').should_succeed <<EOM + it "knife delete --both -r /cookbooks/x deletes x" do + knife("delete --both -r /cookbooks/x").should_succeed "Deleted /cookbooks/x\n" + knife("list -Rf /").should_succeed <<EOM /clients /clients/chef-validator.json /clients/chef-webui.json @@ -513,18 +513,18 @@ EOM /users/admin.json /users/x.json EOM - knife('list -Rf --local /').should_succeed nothing + knife("list -Rf --local /").should_succeed nothing end - it 'knife delete --both /data_bags/x fails' do - knife('delete --both /data_bags/x').should_fail "ERROR: /data_bags/x (remote) must be deleted recursively! Pass -r to knife delete.\n" - knife('list -Rf /').should_succeed server_everything - knife('list -Rf --local /').should_succeed nothing + it "knife delete --both /data_bags/x fails" do + knife("delete --both /data_bags/x").should_fail "ERROR: /data_bags/x (remote) must be deleted recursively! Pass -r to knife delete.\n" + knife("list -Rf /").should_succeed server_everything + knife("list -Rf --local /").should_succeed nothing end - it 'knife delete --both -r /data_bags/x deletes x' do - knife('delete --both -r /data_bags/x').should_succeed "Deleted /data_bags/x\n" - knife('list -Rf /').should_succeed <<EOM + it "knife delete --both -r /data_bags/x deletes x" do + knife("delete --both -r /data_bags/x").should_succeed "Deleted /data_bags/x\n" + knife("list -Rf /").should_succeed <<EOM /clients /clients/chef-validator.json /clients/chef-webui.json @@ -544,12 +544,12 @@ EOM /users/admin.json /users/x.json EOM - knife('list -Rf --local /').should_succeed nothing + knife("list -Rf --local /").should_succeed nothing end - it 'knife delete --both /environments/x.json deletes x' do - knife('delete --both /environments/x.json').should_succeed "Deleted /environments/x.json\n" - knife('list -Rf /').should_succeed <<EOM + it "knife delete --both /environments/x.json deletes x" do + knife("delete --both /environments/x.json").should_succeed "Deleted /environments/x.json\n" + knife("list -Rf /").should_succeed <<EOM /clients /clients/chef-validator.json /clients/chef-webui.json @@ -570,12 +570,12 @@ EOM /users/admin.json /users/x.json EOM - knife('list -Rf --local /').should_succeed nothing + knife("list -Rf --local /").should_succeed nothing end - it 'knife delete --both /roles/x.json deletes x' do - knife('delete --both /roles/x.json').should_succeed "Deleted /roles/x.json\n" - knife('list -Rf /').should_succeed <<EOM + it "knife delete --both /roles/x.json deletes x" do + knife("delete --both /roles/x.json").should_succeed "Deleted /roles/x.json\n" + knife("list -Rf /").should_succeed <<EOM /clients /clients/chef-validator.json /clients/chef-webui.json @@ -596,23 +596,23 @@ EOM /users/admin.json /users/x.json EOM - knife('list -Rf --local /').should_succeed nothing + knife("list -Rf --local /").should_succeed nothing end - it 'knife delete --both /environments/_default.json fails' do - knife('delete --both /environments/_default.json').should_fail "", :stderr => "ERROR: /environments/_default.json (remote) cannot be deleted (default environment cannot be modified).\n" - knife('list -Rf /').should_succeed server_everything - knife('list -Rf --local /').should_succeed nothing + it "knife delete --both /environments/_default.json fails" do + knife("delete --both /environments/_default.json").should_fail "", :stderr => "ERROR: /environments/_default.json (remote) cannot be deleted (default environment cannot be modified).\n" + knife("list -Rf /").should_succeed server_everything + knife("list -Rf --local /").should_succeed nothing end - it 'knife delete --both / fails' do - knife('delete --both /').should_fail "ERROR: / (remote) cannot be deleted.\nERROR: / (local) cannot be deleted.\n" - knife('list -Rf /').should_succeed server_everything - knife('list -Rf --local /').should_succeed nothing + it "knife delete --both / fails" do + knife("delete --both /").should_fail "ERROR: / (remote) cannot be deleted.\nERROR: / (local) cannot be deleted.\n" + knife("list -Rf /").should_succeed server_everything + knife("list -Rf --local /").should_succeed nothing end - it 'knife delete --both -r /* fails' do - knife('delete --both -r /*').should_fail <<EOM + it "knife delete --both -r /* fails" do + knife("delete --both -r /*").should_fail <<EOM ERROR: / (remote) cannot be deleted. ERROR: / (local) cannot be deleted. ERROR: /clients (remote) cannot be deleted. @@ -630,21 +630,21 @@ ERROR: /roles (local) cannot be deleted. ERROR: /users (remote) cannot be deleted. ERROR: /users (local) cannot be deleted. EOM - knife('list -Rf /').should_succeed server_everything - knife('list -Rf --local /').should_succeed nothing + knife("list -Rf /").should_succeed server_everything + knife("list -Rf --local /").should_succeed nothing end - it 'knife delete --both /environments/nonexistent.json fails' do - knife('delete --both /environments/nonexistent.json').should_fail "ERROR: /environments/nonexistent.json: No such file or directory\n" - knife('list -Rf /').should_succeed server_everything - knife('list -Rf --local /').should_succeed nothing + it "knife delete --both /environments/nonexistent.json fails" do + knife("delete --both /environments/nonexistent.json").should_fail "ERROR: /environments/nonexistent.json: No such file or directory\n" + knife("list -Rf /").should_succeed server_everything + knife("list -Rf --local /").should_succeed nothing end - context 'and cwd is at the top level' do - 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 + context "and cwd is at the top level" do + before { cwd "." } + it "knife delete fails" do + knife("delete").should_fail "FATAL: You must specify at least one argument. If you want to delete everything in this directory, run \"knife delete --recurse .\"\n", :stdout => /USAGE/ + knife("list -Rf /").should_succeed <<EOM clients clients/chef-validator.json clients/chef-webui.json @@ -666,7 +666,7 @@ users users/admin.json users/x.json EOM - knife('list -Rf --local /').should_succeed <<EOM + knife("list -Rf --local /").should_succeed <<EOM clients cookbooks data_bags @@ -680,29 +680,29 @@ EOM end end - when_the_chef_server 'is empty' do - when_the_repository 'has one of each thing' do + when_the_chef_server "is empty" do + when_the_repository "has one of each thing" do 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" - knife('list -Rf /').should_succeed server_nothing - knife('list -Rf --local /').should_succeed everything - end - - it 'knife delete --both -r /cookbooks/x deletes x' do - knife('delete --both -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n" - knife('list -Rf /').should_succeed server_nothing - knife('list -Rf --local /').should_succeed <<EOM + 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" + knife("list -Rf /").should_succeed server_nothing + knife("list -Rf --local /").should_succeed everything + end + + it "knife delete --both -r /cookbooks/x deletes x" do + knife("delete --both -r /cookbooks/x").should_succeed "Deleted /cookbooks/x\n" + knife("list -Rf /").should_succeed server_nothing + knife("list -Rf --local /").should_succeed <<EOM /clients /clients/x.json /cookbooks @@ -721,16 +721,16 @@ EOM EOM end - it 'knife delete --both /data_bags/x fails' do - knife('delete --both /data_bags/x').should_fail "ERROR: /data_bags/x (local) must be deleted recursively! Pass -r to knife delete.\n" - knife('list -Rf /').should_succeed server_nothing - knife('list -Rf --local /').should_succeed everything + it "knife delete --both /data_bags/x fails" do + knife("delete --both /data_bags/x").should_fail "ERROR: /data_bags/x (local) must be deleted recursively! Pass -r to knife delete.\n" + knife("list -Rf /").should_succeed server_nothing + knife("list -Rf --local /").should_succeed everything end - it 'knife delete --both -r /data_bags/x deletes x' do - knife('delete --both -r /data_bags/x').should_succeed "Deleted /data_bags/x\n" - knife('list -Rf /').should_succeed server_nothing - knife('list -Rf --local /').should_succeed <<EOM + it "knife delete --both -r /data_bags/x deletes x" do + knife("delete --both -r /data_bags/x").should_succeed "Deleted /data_bags/x\n" + knife("list -Rf /").should_succeed server_nothing + knife("list -Rf --local /").should_succeed <<EOM /clients /clients/x.json /cookbooks @@ -749,10 +749,10 @@ EOM EOM end - it 'knife delete --both /environments/x.json deletes x' do - knife('delete --both /environments/x.json').should_succeed "Deleted /environments/x.json\n" - knife('list -Rf /').should_succeed server_nothing - knife('list -Rf --local /').should_succeed <<EOM + it "knife delete --both /environments/x.json deletes x" do + knife("delete --both /environments/x.json").should_succeed "Deleted /environments/x.json\n" + knife("list -Rf /").should_succeed server_nothing + knife("list -Rf --local /").should_succeed <<EOM /clients /clients/x.json /cookbooks @@ -772,10 +772,10 @@ EOM EOM end - it 'knife delete --both /roles/x.json deletes x' do - knife('delete --both /roles/x.json').should_succeed "Deleted /roles/x.json\n" - knife('list -Rf /').should_succeed server_nothing - knife('list -Rf --local /').should_succeed <<EOM + it "knife delete --both /roles/x.json deletes x" do + knife("delete --both /roles/x.json").should_succeed "Deleted /roles/x.json\n" + knife("list -Rf /").should_succeed server_nothing + knife("list -Rf --local /").should_succeed <<EOM /clients /clients/x.json /cookbooks @@ -795,10 +795,10 @@ EOM EOM end - it 'knife delete --both /environments/_default.json fails but still deletes the local copy' do - knife('delete --both /environments/_default.json').should_fail :stderr => "ERROR: /environments/_default.json (remote) cannot be deleted (default environment cannot be modified).\n", :stdout => "Deleted /environments/_default.json\n" - knife('list -Rf /').should_succeed server_nothing - knife('list -Rf --local /').should_succeed <<EOM + it "knife delete --both /environments/_default.json fails but still deletes the local copy" do + knife("delete --both /environments/_default.json").should_fail :stderr => "ERROR: /environments/_default.json (remote) cannot be deleted (default environment cannot be modified).\n", :stdout => "Deleted /environments/_default.json\n" + knife("list -Rf /").should_succeed server_nothing + knife("list -Rf --local /").should_succeed <<EOM /clients /clients/x.json /cookbooks @@ -818,14 +818,14 @@ EOM EOM end - it 'knife delete --both / fails' do - knife('delete --both /').should_fail "ERROR: / (remote) cannot be deleted.\nERROR: / (local) cannot be deleted.\n" - knife('list -Rf /').should_succeed server_nothing - knife('list -Rf --local /').should_succeed everything + it "knife delete --both / fails" do + knife("delete --both /").should_fail "ERROR: / (remote) cannot be deleted.\nERROR: / (local) cannot be deleted.\n" + knife("list -Rf /").should_succeed server_nothing + knife("list -Rf --local /").should_succeed everything end - it 'knife delete --both -r /* fails' do - knife('delete --both -r /*').should_fail <<EOM + it "knife delete --both -r /* fails" do + knife("delete --both -r /*").should_fail <<EOM ERROR: / (remote) cannot be deleted. ERROR: / (local) cannot be deleted. ERROR: /clients (remote) cannot be deleted. @@ -843,21 +843,21 @@ ERROR: /roles (local) cannot be deleted. ERROR: /users (remote) cannot be deleted. ERROR: /users (local) cannot be deleted. EOM - knife('list -Rf /').should_succeed server_nothing - knife('list -Rf --local /').should_succeed everything + knife("list -Rf /").should_succeed server_nothing + knife("list -Rf --local /").should_succeed everything end - it 'knife delete --both /environments/nonexistent.json fails' do - knife('delete --both /environments/nonexistent.json').should_fail "ERROR: /environments/nonexistent.json: No such file or directory\n" - knife('list -Rf /').should_succeed server_nothing - knife('list -Rf --local /').should_succeed everything + it "knife delete --both /environments/nonexistent.json fails" do + knife("delete --both /environments/nonexistent.json").should_fail "ERROR: /environments/nonexistent.json: No such file or directory\n" + knife("list -Rf /").should_succeed server_nothing + knife("list -Rf --local /").should_succeed everything end - context 'and cwd is at the top level' do - 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 + context "and cwd is at the top level" do + before { cwd "." } + it "knife delete fails" do + knife("delete").should_fail "FATAL: You must specify at least one argument. If you want to delete everything in this directory, run \"knife delete --recurse .\"\n", :stdout => /USAGE/ + knife("list -Rf /").should_succeed <<EOM clients clients/chef-validator.json clients/chef-webui.json @@ -870,7 +870,7 @@ roles users users/admin.json EOM - knife('list -Rf --local /').should_succeed <<EOM + knife("list -Rf --local /").should_succeed <<EOM clients clients/x.json cookbooks @@ -894,110 +894,124 @@ EOM end end - when_the_repository 'has a cookbook' do + when_the_repository "has a cookbook" do before do - file 'cookbooks/x/metadata.rb', 'version "1.0.0"' - file 'cookbooks/x/onlyin1.0.0.rb', 'old_text' + 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 + when_the_chef_server "has a later version for the cookbook" do before do - cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => '' } - cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => 'hi' } + 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 - knife('delete --both -r /cookbooks/x').should_succeed "Deleted /cookbooks/x\n" - knife('raw /cookbooks/x').should_succeed(/1.0.0/) - knife('list --local /cookbooks').should_succeed '' + it "knife delete --both -r /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" + knife("raw /cookbooks/x").should_succeed(/1.0.0/) + knife("list --local /cookbooks").should_succeed "" end end - when_the_chef_server 'has an earlier version for the cookbook' do + when_the_chef_server "has an earlier version for the cookbook" do before do - cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => ''} - cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => 'hi' } + 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" - knife('raw /cookbooks/x').should_succeed(/0.9.9/) - knife('list --local /cookbooks').should_succeed '' + 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" + knife("raw /cookbooks/x").should_succeed(/0.9.9/) + knife("list --local /cookbooks").should_succeed "" end end - when_the_chef_server 'has a later version for the cookbook, and no current version' do - before { cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => 'hi' } } + when_the_chef_server "has a later version for the cookbook, and no current version" do + 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" - knife('raw /cookbooks/x').should_fail(/404/) - knife('list --local /cookbooks').should_succeed '' + 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" + knife("raw /cookbooks/x").should_fail(/404/) + knife("list --local /cookbooks").should_succeed "" end end - when_the_chef_server 'has an earlier version for the cookbook, and no current version' do - before { cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => 'hi' } } + when_the_chef_server "has an earlier version for the cookbook, and no current version" do + 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" - knife('raw /cookbooks/x').should_fail(/404/) - knife('list --local /cookbooks').should_succeed '' + 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" + knife("raw /cookbooks/x").should_fail(/404/) + knife("list --local /cookbooks").should_succeed "" end end end - when_the_repository 'is empty' do - when_the_chef_server 'has two versions of a cookbook' do + when_the_repository "is empty" do + when_the_chef_server "has two versions of a cookbook" do before do - cookbook 'x', '2.0.11' - cookbook 'x', '11.0.0' + 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/ ) + 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/ ) end end end when_the_chef_server "is in Enterprise mode", :osc_compat => false, :single_org => false do before do - organization 'foo' do - container 'x', {} - group 'x', {} + organization "foo" do + container "x", {} + group "x", {} + policy "x", "1.2.3", {} + policy_group "x", { "policies" => { "x" => { "revision_id" => "1.2.3" } } } end end before :each do - Chef::Config.chef_server_url = URI.join(Chef::Config.chef_server_url, '/organizations/foo') + Chef::Config.chef_server_url = URI.join(Chef::Config.chef_server_url, "/organizations/foo") end - it 'knife delete /acls/containers/environments.json fails with a reasonable error' do - knife('delete /acls/containers/environments.json').should_fail "ERROR: /acls/containers/environments.json (remote) cannot be deleted.\n" + it "knife delete /acls/containers/environments.json fails with a reasonable error" do + knife("delete /acls/containers/environments.json").should_fail "ERROR: /acls/containers/environments.json (remote) ACLs cannot be deleted.\n" end - it 'knife delete /containers/x.json succeeds' do - knife('delete /containers/x.json').should_succeed "Deleted /containers/x.json\n" - knife('raw /containers/x.json').should_fail(/404/) + it "knife delete /containers/x.json succeeds" do + knife("delete /containers/x.json").should_succeed "Deleted /containers/x.json\n" + knife("raw /containers/x.json").should_fail(/404/) end - it 'knife delete /groups/x.json succeeds' do - knife('delete /groups/x.json').should_succeed "Deleted /groups/x.json\n" - knife('raw /groups/x.json').should_fail(/404/) + it "knife delete /groups/x.json succeeds" do + knife("delete /groups/x.json").should_succeed "Deleted /groups/x.json\n" + knife("raw /groups/x.json").should_fail(/404/) end - it 'knife delete /org.json fails with a reasonable error' do - knife('delete /org.json').should_fail "ERROR: /org.json (remote) cannot be deleted.\n" + it "knife delete /policies/x-1.2.3.json succeeds" do + knife("raw /policies/x/revisions/1.2.3").should_succeed "{\n \"name\": \"x\",\n \"revision_id\": \"1.2.3\",\n \"run_list\": [\n\n ],\n \"cookbook_locks\": {\n\n }\n}\n" + knife("delete /policies/x-1.2.3.json").should_succeed "Deleted /policies/x-1.2.3.json\n" + knife("raw /policies/x/revisions/1.2.3").should_fail(/404/) end - it 'knife delete /invitations.json fails with a reasonable error' do - knife('delete /invitations.json').should_fail "ERROR: /invitations.json (remote) cannot be deleted.\n" + it "knife delete /policy_groups/x.json succeeds" do + knife("raw /policy_groups/x").should_succeed "{\n \"uri\": \"http://127.0.0.1:8900/organizations/foo/policy_groups/x\",\n \"policies\": {\n \"x\": {\n \"revision_id\": \"1.2.3\"\n }\n }\n}\n" + knife("delete /policy_groups/x.json").should_succeed "Deleted /policy_groups/x.json\n" + knife("raw /policy_groups/x").should_fail(/404/) end - it 'knife delete /members.json fails with a reasonable error' do - knife('delete /members.json').should_fail "ERROR: /members.json (remote) cannot be deleted.\n" + it "knife delete /org.json fails with a reasonable error" do + knife("delete /org.json").should_fail "ERROR: /org.json (remote) cannot be deleted.\n" + end + + it "knife delete /invitations.json fails with a reasonable error" do + knife("delete /invitations.json").should_fail "ERROR: /invitations.json (remote) cannot be deleted.\n" + end + + it "knife delete /members.json fails with a reasonable error" do + knife("delete /members.json").should_fail "ERROR: /members.json (remote) cannot be deleted.\n" end end end diff --git a/spec/integration/knife/deps_spec.rb b/spec/integration/knife/deps_spec.rb index b7333cefda..292bce6002 100644 --- a/spec/integration/knife/deps_spec.rb +++ b/spec/integration/knife/deps_spec.rb @@ -1,6 +1,6 @@ # -# Author:: John Keiser (<jkeiser@opscode.com>) -# Copyright:: Copyright (c) 2013 Opscode, Inc. +# Author:: John Keiser (<jkeiser@chef.io>) +# Copyright:: Copyright 2013-2016, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,33 +15,33 @@ # 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/deps' +require "support/shared/integration/integration_helper" +require "support/shared/context/config" +require "chef/knife/deps" -describe 'knife deps', :workstation do +describe "knife deps", :workstation do include IntegrationSupport include KnifeSupport - context 'local' do - when_the_repository 'has a role with no run_list' do - before { file 'roles/starring.json', {} } - it 'knife deps reports no dependencies' do - knife('deps /roles/starring.json').should_succeed "/roles/starring.json\n" + context "local" do + when_the_repository "has a role with no run_list" do + 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 + when_the_repository "has a role with a default run_list" do 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 + 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 /cookbooks/quiche /cookbooks/soup @@ -50,17 +50,17 @@ EOM end end - when_the_repository 'has a role with an env_run_list' do + when_the_repository "has a role with an env_run_list" do 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 + 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 /cookbooks/quiche /cookbooks/soup @@ -69,32 +69,32 @@ EOM end end - when_the_repository 'has a node with no environment or run_list' do - before { file 'nodes/mort.json', {} } - it 'knife deps reports just the node' do - knife('deps /nodes/mort.json').should_succeed "/nodes/mort.json\n" + when_the_repository "has a node with no environment or run_list" do + 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 + when_the_repository "has a node with an environment" do before do - file 'environments/desert.json', {} - file 'nodes/mort.json', { 'chef_environment' => 'desert' } + 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" + 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 + when_the_repository "has a node with roles and recipes in its run_list" do 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 + 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 /cookbooks/quiche /cookbooks/soup @@ -102,53 +102,53 @@ EOM EOM end end - when_the_repository 'has a cookbook with no dependencies' do + when_the_repository "has a cookbook with no dependencies" do before do - file 'cookbooks/quiche/metadata.rb', 'name "quiche"' - file 'cookbooks/quiche/recipes/default.rb', '' + 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" + 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 + when_the_repository "has a cookbook with dependencies" do before do - file 'cookbooks/kettle/metadata.rb', 'name "kettle"' - file 'cookbooks/quiche/metadata.rb', 'name "quiche" + file "cookbooks/kettle/metadata.rb", 'name "kettle"' + file "cookbooks/quiche/metadata.rb", 'name "quiche" depends "kettle"' - file 'cookbooks/quiche/recipes/default.rb', '' + 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" + 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 - 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" + when_the_repository "has a data bag" do + 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 - before { file 'environments/desert.json', {} } - it 'knife deps reports just the environment' do - knife('deps /environments/desert.json').should_succeed "/environments/desert.json\n" + when_the_repository "has an environment" do + 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 + when_the_repository "has a deep dependency tree" do 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]' ] } + 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 + it "knife deps reports all dependencies" do + knife("deps /nodes/mort.json").should_succeed <<EOM /environments/desert.json /roles/minor.json /cookbooks/quiche @@ -157,8 +157,8 @@ depends "kettle"' /nodes/mort.json EOM end - it 'knife deps * reports all dependencies of all things' do - knife('deps /nodes/*').should_succeed <<EOM + it "knife deps * reports all dependencies of all things" do + knife("deps /nodes/*").should_succeed <<EOM /roles/minor.json /nodes/bart.json /environments/desert.json @@ -168,8 +168,8 @@ EOM /nodes/mort.json EOM end - it 'knife deps a b reports all dependencies of a and b' do - knife('deps /nodes/bart.json /nodes/mort.json').should_succeed <<EOM + it "knife deps a b reports all dependencies of a and b" do + knife("deps /nodes/bart.json /nodes/mort.json").should_succeed <<EOM /roles/minor.json /nodes/bart.json /environments/desert.json @@ -179,8 +179,8 @@ EOM /nodes/mort.json EOM end - it 'knife deps --tree /* shows dependencies in a tree' do - knife('deps --tree /nodes/*').should_succeed <<EOM + it "knife deps --tree /* shows dependencies in a tree" do + knife("deps --tree /nodes/*").should_succeed <<EOM /nodes/bart.json /roles/minor.json /nodes/mort.json @@ -191,8 +191,8 @@ EOM /cookbooks/soup EOM end - it 'knife deps --tree --no-recurse shows only the first level of dependencies' do - knife('deps --tree --no-recurse /nodes/*').should_succeed <<EOM + it "knife deps --tree --no-recurse shows only the first level of dependencies" do + knife("deps --tree --no-recurse /nodes/*").should_succeed <<EOM /nodes/bart.json /roles/minor.json /nodes/mort.json @@ -202,49 +202,49 @@ EOM end end - context 'circular dependencies' do - when_the_repository 'has cookbooks with circular dependencies' do + context "circular dependencies" do + when_the_repository "has cookbooks with circular dependencies" do before do - file 'cookbooks/foo/metadata.rb', 'name "foo" + file "cookbooks/foo/metadata.rb", 'name "foo" depends "bar"' - file 'cookbooks/bar/metadata.rb', 'name "bar" + file "cookbooks/bar/metadata.rb", 'name "bar" depends "baz"' - file 'cookbooks/baz/metadata.rb', 'name "baz" + file "cookbooks/baz/metadata.rb", 'name "baz" depends "foo"' - file 'cookbooks/self/metadata.rb', 'name "self" + file "cookbooks/self/metadata.rb", 'name "self" depends "self"' end - it 'knife deps prints each once' do - knife('deps /cookbooks/foo /cookbooks/self').should_succeed( + it "knife deps prints each once" do + knife("deps /cookbooks/foo /cookbooks/self").should_succeed( stdout: "/cookbooks/baz\n/cookbooks/bar\n/cookbooks/foo\n/cookbooks/self\n", stderr: "WARN: Ignoring self-dependency in cookbook self, please remove it (in the future this will be fatal).\n" ) end - it 'knife deps --tree prints each once' do - knife('deps --tree /cookbooks/foo /cookbooks/self').should_succeed( + it "knife deps --tree prints each once" do + knife("deps --tree /cookbooks/foo /cookbooks/self").should_succeed( stdout: "/cookbooks/foo\n /cookbooks/bar\n /cookbooks/baz\n /cookbooks/foo\n/cookbooks/self\n", stderr: "WARN: Ignoring self-dependency in cookbook self, please remove it (in the future this will be fatal).\n" ) end end - when_the_repository 'has roles with circular dependencies' do + when_the_repository "has roles with circular dependencies" do 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]' ] } + 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 + it "knife deps prints each once" do + knife("deps /roles/foo.json /roles/self.json").should_succeed <<EOM /roles/baz.json /roles/bar.json /roles/foo.json /roles/self.json EOM end - it 'knife deps --tree prints each once' do - knife('deps --tree /roles/foo.json /roles/self.json') do + it "knife deps --tree prints each once" do + knife("deps --tree /roles/foo.json /roles/self.json") do expect(stdout).to eq("/roles/foo.json\n /roles/bar.json\n /roles/baz.json\n /roles/foo.json\n/roles/self.json\n /roles/self.json\n") expect(stderr).to eq("WARNING: No knife configuration file found\n") end @@ -252,81 +252,81 @@ EOM end end - context 'missing objects' do - when_the_repository 'is empty' do - it 'knife deps /blah reports an error' do - knife('deps /blah').should_fail( + context "missing objects" do + when_the_repository "is empty" do + it "knife deps /blah reports an error" do + knife("deps /blah").should_fail( :exit_code => 2, :stdout => "/blah\n", :stderr => "ERROR: /blah: No such file or directory\n" ) end - it 'knife deps /roles/x.json reports an error' do - knife('deps /roles/x.json').should_fail( + it "knife deps /roles/x.json reports an error" do + knife("deps /roles/x.json").should_fail( :exit_code => 2, :stdout => "/roles/x.json\n", :stderr => "ERROR: /roles/x.json: No such file or directory\n" ) end - it 'knife deps /nodes/x.json reports an error' do - knife('deps /nodes/x.json').should_fail( + it "knife deps /nodes/x.json reports an error" do + knife("deps /nodes/x.json").should_fail( :exit_code => 2, :stdout => "/nodes/x.json\n", :stderr => "ERROR: /nodes/x.json: No such file or directory\n" ) end - it 'knife deps /environments/x.json reports an error' do - knife('deps /environments/x.json').should_fail( + it "knife deps /environments/x.json reports an error" do + knife("deps /environments/x.json").should_fail( :exit_code => 2, :stdout => "/environments/x.json\n", :stderr => "ERROR: /environments/x.json: No such file or directory\n" ) end - it 'knife deps /cookbooks/x reports an error' do - knife('deps /cookbooks/x').should_fail( + it "knife deps /cookbooks/x reports an error" do + knife("deps /cookbooks/x").should_fail( :exit_code => 2, :stdout => "/cookbooks/x\n", :stderr => "ERROR: /cookbooks/x: No such file or directory\n" ) end - it 'knife deps /data_bags/bag/item reports an error' do - knife('deps /data_bags/bag/item').should_fail( + it "knife deps /data_bags/bag/item.json reports an error" do + knife("deps /data_bags/bag/item.json").should_fail( :exit_code => 2, - :stdout => "/data_bags/bag/item\n", - :stderr => "ERROR: /data_bags/bag/item: No such file or directory\n" + :stdout => "/data_bags/bag/item.json\n", + :stderr => "ERROR: /data_bags/bag/item.json: No such file or directory\n" ) end end - when_the_repository 'is missing a dependent cookbook' do + when_the_repository "is missing a dependent cookbook" do before do - file 'roles/starring.json', { 'run_list' => [ 'recipe[quiche]'] } + 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( + it "knife deps reports the cookbook, along with an error" do + knife("deps /roles/starring.json").should_fail( :exit_code => 2, :stdout => "/cookbooks/quiche\n/roles/starring.json\n", :stderr => "ERROR: /cookbooks/quiche: No such file or directory\n" ) end end - when_the_repository 'is missing a dependent environment' do + when_the_repository "is missing a dependent environment" do before do - file 'nodes/mort.json', { 'chef_environment' => 'desert' } + 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( + it "knife deps reports the environment, along with an error" do + knife("deps /nodes/mort.json").should_fail( :exit_code => 2, :stdout => "/environments/desert.json\n/nodes/mort.json\n", :stderr => "ERROR: /environments/desert.json: No such file or directory\n" ) end end - when_the_repository 'is missing a dependent role' do + when_the_repository "is missing a dependent role" do before do - file 'roles/starring.json', { 'run_list' => [ 'role[minor]'] } + 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( + it "knife deps reports the role, along with an error" do + knife("deps /roles/starring.json").should_fail( :exit_code => 2, :stdout => "/roles/minor.json\n/roles/starring.json\n", :stderr => "ERROR: /roles/minor.json: No such file or directory\n" @@ -334,29 +334,29 @@ EOM end end end - context 'invalid objects' do - when_the_repository 'is empty' do - it 'knife deps / reports itself only' do - knife('deps /').should_succeed("/\n") + context "invalid objects" do + when_the_repository "is empty" do + it "knife deps / reports itself only" do + knife("deps /").should_succeed("/\n") end - it 'knife deps /roles reports an error' do - knife('deps /roles').should_fail( + it "knife deps /roles reports an error" do + knife("deps /roles").should_fail( :exit_code => 2, :stderr => "ERROR: /roles: No such file or directory\n", :stdout => "/roles\n" ) end end - when_the_repository 'has a data bag' do - 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") + when_the_repository "has a data bag" do + 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 - 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( + when_the_repository "has a cookbook" do + 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" ) end @@ -364,25 +364,25 @@ EOM end end - context 'remote' do + context "remote" do include_context "default config options" - when_the_chef_server 'has a role with no run_list' do - before { role 'starring', {} } - it 'knife deps reports no dependencies' do - knife('deps --remote /roles/starring.json').should_succeed "/roles/starring.json\n" + when_the_chef_server "has a role with no run_list" do + 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 + when_the_chef_server "has a role with a default run_list" do before do - role 'starring', { 'run_list' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) } - role 'minor', {} - cookbook 'quiche', '1.0.0', { 'metadata.rb' => %Q{name "quiche"\nversion "1.0.0"\n}, 'recipes' => { 'default.rb' => '' } } - cookbook 'soup', '1.0.0', { 'metadata.rb' => %Q{name "soup"\nversion "1.0.0"\n}, 'recipes' => { 'chicken.rb' => '' } } + role "starring", { "run_list" => %w{role[minor] recipe[quiche] recipe[soup::chicken]} } + role "minor", {} + cookbook "quiche", "1.0.0", { "metadata.rb" => %Q{name "quiche"\nversion "1.0.0"\n}, "recipes" => { "default.rb" => "" } } + cookbook "soup", "1.0.0", { "metadata.rb" => %Q{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 + it "knife deps reports all dependencies" do + knife("deps --remote /roles/starring.json").should_succeed <<EOM /roles/minor.json /cookbooks/quiche /cookbooks/soup @@ -391,15 +391,15 @@ EOM end end - when_the_chef_server 'has a role with an env_run_list' do + when_the_chef_server "has a role with an env_run_list" do 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' => %Q{name "quiche"\nversion "1.0.0"\n}, 'recipes' => { 'default.rb' => '' } } - cookbook 'soup', '1.0.0', { 'metadata.rb' => %Q{name "soup"\nversion "1.0.0"\n}, 'recipes' => { 'chicken.rb' => '' } } + role "starring", { "env_run_lists" => { "desert" => %w{role[minor] recipe[quiche] recipe[soup::chicken]} } } + role "minor", {} + cookbook "quiche", "1.0.0", { "metadata.rb" => %Q{name "quiche"\nversion "1.0.0"\n}, "recipes" => { "default.rb" => "" } } + cookbook "soup", "1.0.0", { "metadata.rb" => %Q{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 + it "knife deps reports all dependencies" do + knife("deps --remote /roles/starring.json").should_succeed <<EOM /roles/minor.json /cookbooks/quiche /cookbooks/soup @@ -408,30 +408,30 @@ EOM end end - when_the_chef_server 'has a node with no environment or run_list' do - before { node 'mort', {} } - it 'knife deps reports just the node' do - knife('deps --remote /nodes/mort.json').should_succeed "/nodes/mort.json\n" + when_the_chef_server "has a node with no environment or run_list" do + 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 + when_the_chef_server "has a node with an environment" do before do - environment 'desert', {} - node 'mort', { 'chef_environment' => 'desert' } + 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" + 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 + when_the_chef_server "has a node with roles and recipes in its run_list" do before do - role 'minor', {} - cookbook 'quiche', '1.0.0', { 'metadata.rb' => %Q{name "quiche"\nversion "1.0.0"\n}, 'recipes' => { 'default.rb' => '' } } - cookbook 'soup', '1.0.0', { 'metadata.rb' => %Q{name "soup"\nversion "1.0.0"\n}, 'recipes' => { 'chicken.rb' => '' } } - node 'mort', { 'run_list' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) } + role "minor", {} + cookbook "quiche", "1.0.0", { "metadata.rb" => %Q{name "quiche"\nversion "1.0.0"\n}, "recipes" => { "default.rb" => "" } } + cookbook "soup", "1.0.0", { "metadata.rb" => %Q{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 + it "knife deps reports just the node" do + knife("deps --remote /nodes/mort.json").should_succeed <<EOM /roles/minor.json /cookbooks/quiche /cookbooks/soup @@ -439,49 +439,49 @@ EOM EOM end end - when_the_chef_server 'has a cookbook with no dependencies' do + when_the_chef_server "has a cookbook with no dependencies" do before do - cookbook 'quiche', '1.0.0', { 'metadata.rb' => %Q{name "quiche"\nversion "1.0.0"\n}, 'recipes' => { 'default.rb' => '' } } + cookbook "quiche", "1.0.0", { "metadata.rb" => %Q{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" + 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 + when_the_chef_server "has a cookbook with dependencies" do before do - cookbook 'kettle', '1.0.0', { 'metadata.rb' => %Q{name "kettle"\nversion "1.0.0"\n} } - cookbook 'quiche', '1.0.0', { 'metadata.rb' => 'name "quiche" -depends "kettle"', 'recipes' => { 'default.rb' => '' } } + cookbook "kettle", "1.0.0", { "metadata.rb" => %Q{name "kettle"\nversion "1.0.0"\n} } + cookbook "quiche", "1.0.0", { "metadata.rb" => 'name "quiche" +depends "kettle"', "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" + 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 - 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" + when_the_chef_server "has a data bag" do + 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 - before { environment 'desert', {} } - it 'knife deps reports just the environment' do - knife('deps --remote /environments/desert.json').should_succeed "/environments/desert.json\n" + when_the_chef_server "has an environment" do + 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 + when_the_chef_server "has a deep dependency tree" do before do - role 'starring', { 'run_list' => %w(role[minor] recipe[quiche] recipe[soup::chicken]) } - role 'minor', {} - cookbook 'quiche', '1.0.0', { 'metadata.rb' => %Q{name "quiche"\nversion "1.0.0"\n}, 'recipes' => { 'default.rb' => '' } } - cookbook 'soup', '1.0.0', { 'metadata.rb' => %Q{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]' ] } + role "starring", { "run_list" => %w{role[minor] recipe[quiche] recipe[soup::chicken]} } + role "minor", {} + cookbook "quiche", "1.0.0", { "metadata.rb" => %Q{name "quiche"\nversion "1.0.0"\n}, "recipes" => { "default.rb" => "" } } + cookbook "soup", "1.0.0", { "metadata.rb" => %Q{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 + it "knife deps reports all dependencies" do + knife("deps --remote /nodes/mort.json").should_succeed <<EOM /environments/desert.json /roles/minor.json /cookbooks/quiche @@ -490,8 +490,8 @@ depends "kettle"', 'recipes' => { 'default.rb' => '' } } /nodes/mort.json EOM end - it 'knife deps * reports all dependencies of all things' do - knife('deps --remote /nodes/*').should_succeed <<EOM + it "knife deps * reports all dependencies of all things" do + knife("deps --remote /nodes/*").should_succeed <<EOM /roles/minor.json /nodes/bart.json /environments/desert.json @@ -501,8 +501,8 @@ EOM /nodes/mort.json EOM end - it 'knife deps a b reports all dependencies of a and b' do - knife('deps --remote /nodes/bart.json /nodes/mort.json').should_succeed <<EOM + it "knife deps a b reports all dependencies of a and b" do + knife("deps --remote /nodes/bart.json /nodes/mort.json").should_succeed <<EOM /roles/minor.json /nodes/bart.json /environments/desert.json @@ -512,8 +512,8 @@ EOM /nodes/mort.json EOM end - it 'knife deps --tree /* shows dependencies in a tree' do - knife('deps --remote --tree /nodes/*').should_succeed <<EOM + it "knife deps --tree /* shows dependencies in a tree" do + knife("deps --remote --tree /nodes/*").should_succeed <<EOM /nodes/bart.json /roles/minor.json /nodes/mort.json @@ -524,8 +524,8 @@ EOM /cookbooks/soup EOM end - it 'knife deps --tree --no-recurse shows only the first level of dependencies' do - knife('deps --remote --tree --no-recurse /nodes/*').should_succeed <<EOM + it "knife deps --tree --no-recurse shows only the first level of dependencies" do + knife("deps --remote --tree --no-recurse /nodes/*").should_succeed <<EOM /nodes/bart.json /roles/minor.json /nodes/mort.json @@ -535,28 +535,28 @@ EOM end end - context 'circular dependencies' do - when_the_chef_server 'has cookbooks with circular dependencies' do + context "circular dependencies" do + when_the_chef_server "has cookbooks with circular dependencies" do before do - cookbook 'foo', '1.0.0', { 'metadata.rb' => 'name "foo" + cookbook "foo", "1.0.0", { "metadata.rb" => 'name "foo" depends "bar"' } - cookbook 'bar', '1.0.0', { 'metadata.rb' => 'name "bar" + cookbook "bar", "1.0.0", { "metadata.rb" => 'name "bar" depends "baz"' } - cookbook 'baz', '1.0.0', { 'metadata.rb' => 'name "baz" + cookbook "baz", "1.0.0", { "metadata.rb" => 'name "baz" depends "foo"' } - cookbook 'self', '1.0.0', { 'metadata.rb' => 'name "self" + cookbook "self", "1.0.0", { "metadata.rb" => 'name "self" depends "self"' } end - it 'knife deps prints each once' do - knife('deps --remote /cookbooks/foo /cookbooks/self').should_succeed <<EOM + it "knife deps prints each once" do + knife("deps --remote /cookbooks/foo /cookbooks/self").should_succeed <<EOM /cookbooks/baz /cookbooks/bar /cookbooks/foo /cookbooks/self EOM end - it 'knife deps --tree prints each once' do - knife('deps --remote --tree /cookbooks/foo /cookbooks/self').should_succeed <<EOM + it "knife deps --tree prints each once" do + knife("deps --remote --tree /cookbooks/foo /cookbooks/self").should_succeed <<EOM /cookbooks/foo /cookbooks/bar /cookbooks/baz @@ -566,23 +566,23 @@ EOM EOM end end - when_the_chef_server 'has roles with circular dependencies' do + when_the_chef_server "has roles with circular dependencies" do 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]' ] } + 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 + it "knife deps prints each once" do + knife("deps --remote /roles/foo.json /roles/self.json").should_succeed <<EOM /roles/baz.json /roles/bar.json /roles/foo.json /roles/self.json EOM end - it 'knife deps --tree prints each once' do - knife('deps --remote --tree /roles/foo.json /roles/self.json') do + it "knife deps --tree prints each once" do + knife("deps --remote --tree /roles/foo.json /roles/self.json") do expect(stdout).to eq("/roles/foo.json\n /roles/bar.json\n /roles/baz.json\n /roles/foo.json\n/roles/self.json\n /roles/self.json\n") expect(stderr).to eq("WARNING: No knife configuration file found\n") end @@ -590,81 +590,81 @@ EOM end end - context 'missing objects' do - when_the_chef_server 'is empty' do - it 'knife deps /blah reports an error' do - knife('deps --remote /blah').should_fail( + context "missing objects" do + when_the_chef_server "is empty" do + it "knife deps /blah reports an error" do + knife("deps --remote /blah").should_fail( :exit_code => 2, :stdout => "/blah\n", :stderr => "ERROR: /blah: No such file or directory\n" ) end - it 'knife deps /roles/x.json reports an error' do - knife('deps --remote /roles/x.json').should_fail( + it "knife deps /roles/x.json reports an error" do + knife("deps --remote /roles/x.json").should_fail( :exit_code => 2, :stdout => "/roles/x.json\n", :stderr => "ERROR: /roles/x.json: No such file or directory\n" ) end - it 'knife deps /nodes/x.json reports an error' do - knife('deps --remote /nodes/x.json').should_fail( + it "knife deps /nodes/x.json reports an error" do + knife("deps --remote /nodes/x.json").should_fail( :exit_code => 2, :stdout => "/nodes/x.json\n", :stderr => "ERROR: /nodes/x.json: No such file or directory\n" ) end - it 'knife deps /environments/x.json reports an error' do - knife('deps --remote /environments/x.json').should_fail( + it "knife deps /environments/x.json reports an error" do + knife("deps --remote /environments/x.json").should_fail( :exit_code => 2, :stdout => "/environments/x.json\n", :stderr => "ERROR: /environments/x.json: No such file or directory\n" ) end - it 'knife deps /cookbooks/x reports an error' do - knife('deps --remote /cookbooks/x').should_fail( + it "knife deps /cookbooks/x reports an error" do + knife("deps --remote /cookbooks/x").should_fail( :exit_code => 2, :stdout => "/cookbooks/x\n", :stderr => "ERROR: /cookbooks/x: No such file or directory\n" ) end - it 'knife deps /data_bags/bag/item reports an error' do - knife('deps --remote /data_bags/bag/item').should_fail( + it "knife deps /data_bags/bag/item reports an error" do + knife("deps --remote /data_bags/bag/item.json").should_fail( :exit_code => 2, - :stdout => "/data_bags/bag/item\n", - :stderr => "ERROR: /data_bags/bag/item: No such file or directory\n" + :stdout => "/data_bags/bag/item.json\n", + :stderr => "ERROR: /data_bags/bag/item.json: No such file or directory\n" ) end end - when_the_chef_server 'is missing a dependent cookbook' do + when_the_chef_server "is missing a dependent cookbook" do before do - role 'starring', { 'run_list' => [ 'recipe[quiche]'] } + 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( + it "knife deps reports the cookbook, along with an error" do + knife("deps --remote /roles/starring.json").should_fail( :exit_code => 2, :stdout => "/cookbooks/quiche\n/roles/starring.json\n", :stderr => "ERROR: /cookbooks/quiche: No such file or directory\n" ) end end - when_the_chef_server 'is missing a dependent environment' do + when_the_chef_server "is missing a dependent environment" do before do - node 'mort', { 'chef_environment' => 'desert' } + 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( + it "knife deps reports the environment, along with an error" do + knife("deps --remote /nodes/mort.json").should_fail( :exit_code => 2, :stdout => "/environments/desert.json\n/nodes/mort.json\n", :stderr => "ERROR: /environments/desert.json: No such file or directory\n" ) end end - when_the_chef_server 'is missing a dependent role' do + when_the_chef_server "is missing a dependent role" do before do - role 'starring', { 'run_list' => [ 'role[minor]'] } + 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( + it "knife deps reports the role, along with an error" do + knife("deps --remote /roles/starring.json").should_fail( :exit_code => 2, :stdout => "/roles/minor.json\n/roles/starring.json\n", :stderr => "ERROR: /roles/minor.json: No such file or directory\n" @@ -672,27 +672,27 @@ EOM end end end - context 'invalid objects' do - when_the_chef_server 'is empty' do - it 'knife deps / reports an error' do - knife('deps --remote /').should_succeed("/\n") + context "invalid objects" do + when_the_chef_server "is empty" do + it "knife deps / reports an error" do + knife("deps --remote /").should_succeed("/\n") end - it 'knife deps /roles reports an error' do - knife('deps --remote /roles').should_succeed("/roles\n") + it "knife deps /roles reports an error" do + knife("deps --remote /roles").should_succeed("/roles\n") end end - when_the_chef_server 'has a data bag' do - 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") + when_the_chef_server "has a data bag" do + 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 + when_the_chef_server "has a cookbook" do before do - cookbook 'blah', '1.0.0', { 'metadata.rb' => 'name "blah"' } + 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( + 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" ) end @@ -700,7 +700,7 @@ EOM end end - it 'knife deps --no-recurse reports an error' do - knife('deps --no-recurse /').should_fail("ERROR: --no-recurse requires --tree\n") + it "knife deps --no-recurse reports an error" do + knife("deps --no-recurse /").should_fail("ERROR: --no-recurse requires --tree\n") end end diff --git a/spec/integration/knife/diff_spec.rb b/spec/integration/knife/diff_spec.rb index 465383437f..b3bd23f48e 100644 --- a/spec/integration/knife/diff_spec.rb +++ b/spec/integration/knife/diff_spec.rb @@ -1,6 +1,6 @@ # -# Author:: John Keiser (<jkeiser@opscode.com>) -# Copyright:: Copyright (c) 2013 Opscode, Inc. +# Author:: John Keiser (<jkeiser@chef.io>) +# Copyright:: Copyright 2013-2016, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,38 +15,38 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'support/shared/integration/integration_helper' -require 'chef/knife/diff' +require "support/shared/integration/integration_helper" +require "chef/knife/diff" -describe 'knife diff', :workstation do +describe "knife diff", :workstation do include IntegrationSupport include KnifeSupport - context 'without versioned cookbooks' do + context "without versioned cookbooks" do when_the_chef_server "has one of each thing" do before do - client 'x', '{}' - cookbook 'x', '1.0.0' - data_bag 'x', { 'y' => '{}' } - environment 'x', '{}' - node 'x', '{}' - role 'x', '{}' - user 'x', '{}' + 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 + when_the_repository "has only top-level directories" do before do - directory 'clients' - directory 'cookbooks' - directory 'data_bags' - directory 'environments' - directory 'nodes' - directory 'roles' - directory 'users' + 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 + it "knife diff reports everything as deleted" do + knife("diff --name-status /").should_succeed <<EOM D\t/clients/chef-validator.json D\t/clients/chef-webui.json D\t/clients/x.json @@ -59,68 +59,68 @@ D\t/roles/x.json D\t/users/admin.json D\t/users/x.json EOM + end end - end - when_the_repository 'has an identical copy of each thing' do + when_the_repository "has an identical copy of each thing" do 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 } + 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", { "normal" => { "tags" => [] } } + 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 '' + it "knife diff reports no differences" do + knife("diff /").should_succeed "" end - it 'knife diff /environments/nonexistent.json reports an error' do - knife('diff /environments/nonexistent.json').should_fail "ERROR: /environments/nonexistent.json: No such file or directory on remote or local\n" + it "knife diff /environments/nonexistent.json reports an error" do + knife("diff /environments/nonexistent.json").should_fail "ERROR: /environments/nonexistent.json: No such file or directory on remote or local\n" end - it 'knife diff /environments/*.txt reports an error' do - knife('diff /environments/*.txt').should_fail "ERROR: /environments/*.txt: No such file or directory on remote or local\n" + it "knife diff /environments/*.txt reports an error" do + knife("diff /environments/*.txt").should_fail "ERROR: /environments/*.txt: No such file or directory on remote or local\n" end - context 'except the role file' do + context "except the role file" do before do - file 'roles/x.json', <<EOM + 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 + it "knife diff reports the role as different" do + knife("diff --name-status /").should_succeed <<EOM M\t/roles/x.json EOM end end - context 'as well as one extra copy of each thing' do + context "as well as one extra copy of each thing" do 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 } + 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 + it "knife diff reports the new files as added" do + knife("diff --name-status /").should_succeed <<EOM A\t/clients/y.json A\t/cookbooks/x/blah.rb A\t/cookbooks/y @@ -133,16 +133,16 @@ A\t/users/y.json EOM end - context 'when cwd is the data_bags directory' do - before { cwd 'data_bags' } - it 'knife diff reports different data bags' do - knife('diff --name-status').should_succeed <<EOM + context "when cwd is the data_bags directory" do + before { cwd "data_bags" } + it "knife diff reports different data bags" do + knife("diff --name-status").should_succeed <<EOM A\tx/z.json A\ty EOM end - it 'knife diff * reports different data bags' do - knife('diff --name-status *').should_succeed <<EOM + it "knife diff * reports different data bags" do + knife("diff --name-status *").should_succeed <<EOM A\tx/z.json A\ty EOM @@ -151,9 +151,9 @@ EOM end end - when_the_repository 'is empty' do - it 'knife diff reports everything as deleted' do - knife('diff --name-status /').should_succeed <<EOM + when_the_repository "is empty" do + it "knife diff reports everything as deleted" do + knife("diff --name-status /").should_succeed <<EOM D\t/clients D\t/cookbooks D\t/data_bags @@ -166,51 +166,51 @@ EOM end end - when_the_repository 'has a cookbook' do + when_the_repository "has a cookbook" do before do - file 'cookbooks/x/metadata.rb', cb_metadata("x", "1.0.0") - file 'cookbooks/x/onlyin1.0.0.rb', '' + 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 + when_the_chef_server "has a later version for the cookbook" do before do - cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => ''} - cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => '' } + 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 + it "knife diff /cookbooks/x shows differences" do + knife("diff --name-status /cookbooks/x").should_succeed <<EOM M\t/cookbooks/x/metadata.rb D\t/cookbooks/x/onlyin1.0.1.rb A\t/cookbooks/x/onlyin1.0.0.rb EOM end - it 'knife diff --diff-filter=MAT does not show deleted files' do - knife('diff --diff-filter=MAT --name-status /cookbooks/x').should_succeed <<EOM + it "knife diff --diff-filter=MAT does not show deleted files" do + knife("diff --diff-filter=MAT --name-status /cookbooks/x").should_succeed <<EOM M\t/cookbooks/x/metadata.rb A\t/cookbooks/x/onlyin1.0.0.rb EOM end end - when_the_chef_server 'has an earlier version for the cookbook' do + when_the_chef_server "has an earlier version for the cookbook" do before do - cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => '' } - cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => '' } + 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 '' + 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 + when_the_chef_server "has a later version for the cookbook, and no current version" do before do - cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => '' } + 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 + it "knife diff /cookbooks/x shows the differences" do + knife("diff --name-status /cookbooks/x").should_succeed <<EOM M\t/cookbooks/x/metadata.rb D\t/cookbooks/x/onlyin1.0.1.rb A\t/cookbooks/x/onlyin1.0.0.rb @@ -218,13 +218,13 @@ EOM end end - when_the_chef_server 'has an earlier version for the cookbook, and no current version' do + when_the_chef_server "has an earlier version for the cookbook, and no current version" do before do - cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => '' } + 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 + it "knife diff /cookbooks/x shows the differences" do + knife("diff --name-status /cookbooks/x").should_succeed <<EOM M\t/cookbooks/x/metadata.rb D\t/cookbooks/x/onlyin0.9.9.rb A\t/cookbooks/x/onlyin1.0.0.rb @@ -233,22 +233,22 @@ EOM end end - context 'json diff tests' do - when_the_repository 'has an empty environment file' do + context "json diff tests" do + when_the_repository "has an empty environment file" do before do - file 'environments/x.json', {} + file "environments/x.json", {} end - when_the_chef_server 'has an empty environment' do - before { environment 'x', {} } - it 'knife diff returns no differences' do - knife('diff /environments/x.json').should_succeed '' + when_the_chef_server "has an empty environment" do + 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 - before { environment 'x', { 'description' => 'hi' } } - it 'knife diff reports the difference', :skip => (RUBY_VERSION < "1.9") do - knife('diff /environments/x.json').should_succeed(/ + when_the_chef_server "has an environment with a different value" do + before { environment "x", { "description" => "hi" } } + it "knife diff reports the difference", :skip => (RUBY_VERSION < "1.9") do + knife("diff /environments/x.json").should_succeed(/ { - "name": "x", - "description": "hi" @@ -259,26 +259,26 @@ EOM end end - when_the_repository 'has an environment file with a value in it' do + when_the_repository "has an environment file with a value in it" do before do - file 'environments/x.json', { 'description' => 'hi' } + file "environments/x.json", { "description" => "hi" } end - when_the_chef_server 'has an environment with the same value' do + when_the_chef_server "has an environment with the same value" do before do - environment 'x', { 'description' => 'hi' } + environment "x", { "description" => "hi" } end - it 'knife diff returns no differences' do - knife('diff /environments/x.json').should_succeed '' + 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 + when_the_chef_server "has an environment with no value" do before do - environment 'x', {} + environment "x", {} end - it 'knife diff reports the difference', :skip => (RUBY_VERSION < "1.9") do - knife('diff /environments/x.json').should_succeed(/ + it "knife diff reports the difference", :skip => (RUBY_VERSION < "1.9") do + knife("diff /environments/x.json").should_succeed(/ { - "name": "x" \+ "name": "x", @@ -287,12 +287,12 @@ EOM /) end end - when_the_chef_server 'has an environment with a different value' do + when_the_chef_server "has an environment with a different value" do before do - environment 'x', { 'description' => 'lo' } + environment "x", { "description" => "lo" } end - it 'knife diff reports the difference', :skip => (RUBY_VERSION < "1.9") do - knife('diff /environments/x.json').should_succeed(/ + it "knife diff reports the difference", :skip => (RUBY_VERSION < "1.9") do + knife("diff /environments/x.json").should_succeed(/ { "name": "x", - "description": "lo" @@ -304,14 +304,14 @@ EOM end end - when_the_chef_server 'has an environment' do - before { environment 'x', {} } - when_the_repository 'has an environment with bad JSON' do - before { file 'environments/x.json', '{' } - it 'knife diff reports an error and does a textual diff' do + when_the_chef_server "has an environment" do + before { environment "x", {} } + when_the_repository "has an environment with bad JSON" do + before { file "environments/x.json", "{" } + it "knife diff reports an error and does a textual diff" do error_text = "WARN: Parse error reading #{path_to('environments/x.json')} as JSON: parse error: premature EOF" error_match = Regexp.new(Regexp.escape(error_text)) - knife('diff /environments/x.json').should_succeed(/- "name": "x"/, :stderr => error_match) + knife("diff /environments/x.json").should_succeed(/- "name": "x"/, :stderr => error_match) end end end @@ -320,28 +320,28 @@ EOM with_versioned_cookbooks do when_the_chef_server "has one of each thing" do before do - client 'x', '{}' - cookbook 'x', '1.0.0' - data_bag 'x', { 'y' => '{}' } - environment 'x', '{}' - node 'x', '{}' - role 'x', '{}' - user 'x', '{}' + 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 + when_the_repository "has only top-level directories" do before do - directory 'clients' - directory 'cookbooks' - directory 'data_bags' - directory 'environments' - directory 'nodes' - directory 'roles' - directory 'users' + 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 + it "knife diff reports everything as deleted" do + knife("diff --name-status /").should_succeed <<EOM D\t/clients/chef-validator.json D\t/clients/chef-webui.json D\t/clients/x.json @@ -354,68 +354,68 @@ D\t/roles/x.json D\t/users/admin.json D\t/users/x.json EOM + end end - end - when_the_repository 'has an identical copy of each thing' do + when_the_repository "has an identical copy of each thing" do 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 } + 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", { "normal" => { "tags" => [] } } + 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 '' + it "knife diff reports no differences" do + knife("diff /").should_succeed "" end - it 'knife diff /environments/nonexistent.json reports an error' do - knife('diff /environments/nonexistent.json').should_fail "ERROR: /environments/nonexistent.json: No such file or directory on remote or local\n" + it "knife diff /environments/nonexistent.json reports an error" do + knife("diff /environments/nonexistent.json").should_fail "ERROR: /environments/nonexistent.json: No such file or directory on remote or local\n" end - it 'knife diff /environments/*.txt reports an error' do - knife('diff /environments/*.txt').should_fail "ERROR: /environments/*.txt: No such file or directory on remote or local\n" + it "knife diff /environments/*.txt reports an error" do + knife("diff /environments/*.txt").should_fail "ERROR: /environments/*.txt: No such file or directory on remote or local\n" end - context 'except the role file' do + context "except the role file" do before do - file 'roles/x.json', <<EOM + 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 + it "knife diff reports the role as different" do + knife("diff --name-status /").should_succeed <<EOM M\t/roles/x.json EOM end end - context 'as well as one extra copy of each thing' do + context "as well as one extra copy of each thing" do 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', {} + 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 + it "knife diff reports the new files as added" do + knife("diff --name-status /").should_succeed <<EOM A\t/clients/y.json A\t/cookbooks/x-1.0.0/blah.rb A\t/cookbooks/x-2.0.0 @@ -429,16 +429,16 @@ A\t/users/y.json EOM end - context 'when cwd is the data_bags directory' do - before { cwd 'data_bags' } - it 'knife diff reports different data bags' do - knife('diff --name-status').should_succeed <<EOM + context "when cwd is the data_bags directory" do + before { cwd "data_bags" } + it "knife diff reports different data bags" do + knife("diff --name-status").should_succeed <<EOM A\tx/z.json A\ty EOM end - it 'knife diff * reports different data bags' do - knife('diff --name-status *').should_succeed <<EOM + it "knife diff * reports different data bags" do + knife("diff --name-status *").should_succeed <<EOM A\tx/z.json A\ty EOM @@ -447,9 +447,9 @@ EOM end end - when_the_repository 'is empty' do - it 'knife diff reports everything as deleted' do - knife('diff --name-status /').should_succeed <<EOM + when_the_repository "is empty" do + it "knife diff reports everything as deleted" do + knife("diff --name-status /").should_succeed <<EOM D\t/clients D\t/cookbooks D\t/data_bags @@ -462,59 +462,59 @@ EOM end end - when_the_repository 'has a cookbook' do + when_the_repository "has a cookbook" do 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', '' + 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 + when_the_chef_server "has a later version for the cookbook" do before do - cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => ''} - cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => '' } + 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 + it "knife diff /cookbooks shows differences" do + knife("diff --name-status /cookbooks").should_succeed <<EOM D\t/cookbooks/x-1.0.1 EOM end - it 'knife diff --diff-filter=MAT does not show deleted files' do - knife('diff --diff-filter=MAT --name-status /cookbooks').should_succeed '' + it "knife diff --diff-filter=MAT does not show deleted files" do + knife("diff --diff-filter=MAT --name-status /cookbooks").should_succeed "" end end - when_the_chef_server 'has an earlier version for the cookbook' do + when_the_chef_server "has an earlier version for the cookbook" do before do - cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => '' } - cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => '' } + 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" + 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 + when_the_chef_server "has a later version for the cookbook, and no current version" do before do - cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => '' } + 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 + it "knife diff /cookbooks shows the differences" do + knife("diff --name-status /cookbooks").should_succeed <<EOM D\t/cookbooks/x-1.0.1 A\t/cookbooks/x-1.0.0 EOM end end - when_the_chef_server 'has an earlier version for the cookbook, and no current version' do + when_the_chef_server "has an earlier version for the cookbook, and no current version" do before do - cookbook 'x', '0.9.9', { 'onlyin0.9.9.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 <<EOM + it "knife diff /cookbooks shows the differences" do + knife("diff --name-status /cookbooks").should_succeed <<EOM D\t/cookbooks/x-0.9.9 A\t/cookbooks/x-1.0.0 EOM @@ -522,19 +522,19 @@ EOM end end - context 'json diff tests' do - when_the_repository 'has an empty environment file' do - before { file 'environments/x.json', {} } - when_the_chef_server 'has an empty environment' do - before { environment 'x', {} } - it 'knife diff returns no differences' do - knife('diff /environments/x.json').should_succeed '' + context "json diff tests" do + when_the_repository "has an empty environment file" do + before { file "environments/x.json", {} } + when_the_chef_server "has an empty environment" do + 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 - before { environment 'x', { 'description' => 'hi' } } - it 'knife diff reports the difference', :skip => (RUBY_VERSION < "1.9") do - knife('diff /environments/x.json').should_succeed(/ + when_the_chef_server "has an environment with a different value" do + before { environment "x", { "description" => "hi" } } + it "knife diff reports the difference", :skip => (RUBY_VERSION < "1.9") do + knife("diff /environments/x.json").should_succeed(/ { - "name": "x", - "description": "hi" @@ -545,23 +545,23 @@ EOM end end - when_the_repository 'has an environment file with a value in it' do + when_the_repository "has an environment file with a value in it" do before do - file 'environments/x.json', { 'description' => 'hi' } + file "environments/x.json", { "description" => "hi" } end - when_the_chef_server 'has an environment with the same value' do + when_the_chef_server "has an environment with the same value" do before do - environment 'x', { 'description' => 'hi' } + environment "x", { "description" => "hi" } end - it 'knife diff returns no differences' do - knife('diff /environments/x.json').should_succeed '' + 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 - before { environment 'x', {} } - it 'knife diff reports the difference', :skip => (RUBY_VERSION < "1.9") do - knife('diff /environments/x.json').should_succeed(/ + when_the_chef_server "has an environment with no value" do + before { environment "x", {} } + it "knife diff reports the difference", :skip => (RUBY_VERSION < "1.9") do + knife("diff /environments/x.json").should_succeed(/ { - "name": "x" \+ "name": "x", @@ -570,12 +570,12 @@ EOM /) end end - when_the_chef_server 'has an environment with a different value' do + when_the_chef_server "has an environment with a different value" do before do - environment 'x', { 'description' => 'lo' } + environment "x", { "description" => "lo" } end - it 'knife diff reports the difference', :skip => (RUBY_VERSION < "1.9") do - knife('diff /environments/x.json').should_succeed(/ + it "knife diff reports the difference", :skip => (RUBY_VERSION < "1.9") do + knife("diff /environments/x.json").should_succeed(/ { "name": "x", - "description": "lo" @@ -587,14 +587,14 @@ EOM end end - when_the_chef_server 'has an environment' do - before { environment 'x', {} } - when_the_repository 'has an environment with bad JSON' do - before { file 'environments/x.json', '{' } - it 'knife diff reports an error and does a textual diff' do + when_the_chef_server "has an environment" do + before { environment "x", {} } + when_the_repository "has an environment with bad JSON" do + before { file "environments/x.json", "{" } + it "knife diff reports an error and does a textual diff" do error_text = "WARN: Parse error reading #{path_to('environments/x.json')} as JSON: parse error: premature EOF" error_match = Regexp.new(Regexp.escape(error_text)) - knife('diff /environments/x.json').should_succeed(/- "name": "x"/, :stderr => error_match) + knife("diff /environments/x.json").should_succeed(/- "name": "x"/, :stderr => error_match) end end end diff --git a/spec/integration/knife/download_spec.rb b/spec/integration/knife/download_spec.rb index b8a19061b7..be0fc9d708 100644 --- a/spec/integration/knife/download_spec.rb +++ b/spec/integration/knife/download_spec.rb @@ -1,6 +1,6 @@ # -# Author:: John Keiser (<jkeiser@opscode.com>) -# Copyright:: Copyright (c) 2013 Opscode, Inc. +# Author:: John Keiser (<jkeiser@chef.io>) +# Copyright:: Copyright 2013-2016, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,40 +15,40 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'support/shared/integration/integration_helper' -require 'chef/knife/download' -require 'chef/knife/diff' +require "support/shared/integration/integration_helper" +require "chef/knife/download" +require "chef/knife/diff" -describe 'knife download', :workstation do +describe "knife download", :workstation do include IntegrationSupport include KnifeSupport - context 'without versioned cookbooks' do + context "without versioned cookbooks" do when_the_chef_server "has one of each thing" do before do - client 'x', {} - cookbook 'x', '1.0.0' - data_bag 'x', { 'y' => {} } - environment 'x', {} - node 'x', {} - role 'x', {} - user 'x', {} + 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 + when_the_repository "has only top-level directories" do before do - directory 'clients' - directory 'cookbooks' - directory 'data_bags' - directory 'environments' - directory 'nodes' - directory 'roles' - directory 'users' + 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 + it "knife download downloads everything" do + knife("download /").should_succeed <<EOM Created /clients/chef-validator.json Created /clients/chef-webui.json Created /clients/x.json @@ -63,38 +63,38 @@ Created /roles/x.json Created /users/admin.json Created /users/x.json EOM - knife('diff --name-status /').should_succeed '' + knife("diff --name-status /").should_succeed "" end end - when_the_repository 'has an identical copy of each thing' do + when_the_repository "has an identical copy of each thing" do 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 } + 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", { "normal" => { "tags" => [] } } + 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 '' - knife('diff --name-status /').should_succeed '' + it "knife download makes no changes" do + knife("download /").should_succeed "" + knife("diff --name-status /").should_succeed "" end - it 'knife download --purge makes no changes' do - knife('download --purge /').should_succeed '' - knife('diff --name-status /').should_succeed '' + it "knife download --purge makes no changes" do + knife("download --purge /").should_succeed "" + knife("diff --name-status /").should_succeed "" end - context 'except the role file' do + context "except the role file" do before do - file 'roles/x.json', <<EOM + file "roles/x.json", <<EOM { "chef_type": "role", "default_attributes": { @@ -113,20 +113,20 @@ 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 '' + it "knife download changes the role" do + knife("download /").should_succeed "Updated /roles/x.json\n" + knife("diff --name-status /").should_succeed "" end - it 'knife download --no-diff does not change the role' do - knife('download --no-diff /').should_succeed '' - knife('diff --name-status /').should_succeed "M\t/roles/x.json\n" + it "knife download --no-diff does not change the role" do + knife("download --no-diff /").should_succeed "" + knife("diff --name-status /").should_succeed "M\t/roles/x.json\n" end end - context 'except the role file is textually different, but not ACTUALLY different' do + context "except the role file is textually different, but not ACTUALLY different" do before do - file 'roles/x.json', <<EOM + file "roles/x.json", <<EOM { "chef_type": "role", "default_attributes": { @@ -145,28 +145,28 @@ EOM EOM end - it 'knife download / does not change anything' do - knife('download /').should_succeed '' - knife('diff --name-status /').should_succeed '' + it "knife download / does not change anything" do + knife("download /").should_succeed "" + knife("diff --name-status /").should_succeed "" end end - context 'as well as one extra copy of each thing' do + context "as well as one extra copy of each thing" do 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 } + 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 '' - knife('diff --name-status /').should_succeed <<EOM + it "knife download does nothing" do + knife("download /").should_succeed "" + knife("diff --name-status /").should_succeed <<EOM A\t/clients/y.json A\t/cookbooks/x/blah.rb A\t/cookbooks/y @@ -179,8 +179,8 @@ A\t/users/y.json EOM end - it 'knife download --purge deletes the extra files' do - knife('download --purge /').should_succeed <<EOM + it "knife download --purge deletes the extra files" do + knife("download --purge /").should_succeed <<EOM Deleted extra entry /clients/y.json (purge is on) Deleted extra entry /cookbooks/x/blah.rb (purge is on) Deleted extra entry /cookbooks/y (purge is on) @@ -191,14 +191,14 @@ Deleted extra entry /nodes/y.json (purge is on) Deleted extra entry /roles/y.json (purge is on) Deleted extra entry /users/y.json (purge is on) EOM - knife('diff --name-status /').should_succeed '' + knife("diff --name-status /").should_succeed "" end end end - when_the_repository 'is empty' do - it 'knife download creates the extra files' do - knife('download /').should_succeed <<EOM + when_the_repository "is empty" do + it "knife download creates the extra files" do + knife("download /").should_succeed <<EOM Created /clients Created /clients/chef-validator.json Created /clients/chef-webui.json @@ -220,11 +220,11 @@ Created /users Created /users/admin.json Created /users/x.json EOM - knife('diff --name-status /').should_succeed '' + knife("diff --name-status /").should_succeed "" end - it 'knife download --no-diff creates the extra files' do - knife('download --no-diff /').should_succeed <<EOM + it "knife download --no-diff creates the extra files" do + knife("download --no-diff /").should_succeed <<EOM Created /clients Created /clients/chef-validator.json Created /clients/chef-webui.json @@ -246,41 +246,41 @@ Created /users Created /users/admin.json Created /users/x.json EOM - knife('diff --name-status /').should_succeed '' + knife("diff --name-status /").should_succeed "" end - context 'when current directory is top level' do + context "when current directory is top level" do before do - cwd '.' + 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/ + it "knife download with no parameters reports an error" do + knife("download").should_fail "FATAL: You must specify at least one argument. If you want to download everything in this directory, run \"knife download .\"\n", :stdout => /USAGE/ end end end end # Test download of an item when the other end doesn't even have the container - when_the_repository 'is empty' do - when_the_chef_server 'has two data bag items' do + when_the_repository "is empty" do + when_the_chef_server "has two data bag items" do before do - data_bag 'x', { 'y' => {}, 'z' => {} } + 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 + it "knife download of one data bag item itself succeeds" do + knife("download /data_bags/x/y.json").should_succeed <<EOM Created /data_bags Created /data_bags/x Created /data_bags/x/y.json EOM - knife('diff --name-status /data_bags').should_succeed <<EOM + knife("diff --name-status /data_bags").should_succeed <<EOM D\t/data_bags/x/z.json EOM end - it 'knife download /data_bags/x /data_bags/x/y.json downloads x once' do - knife('download /data_bags/x /data_bags/x/y.json').should_succeed <<EOM + it "knife download /data_bags/x /data_bags/x/y.json downloads x once" do + knife("download /data_bags/x /data_bags/x/y.json").should_succeed <<EOM Created /data_bags Created /data_bags/x Created /data_bags/x/y.json @@ -290,285 +290,304 @@ EOM end end - when_the_repository 'has three data bag items' do + when_the_repository "has three data bag items" do before do - file 'data_bags/x/deleted.json', <<EOM + 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 + when_the_chef_server "has a modified, unmodified, added and deleted data bag item" do before do - data_bag 'x', { - 'added' => {}, - 'modified' => { 'foo' => 'bar' }, - 'unmodified' => {} + 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 + it "knife download of the modified file succeeds" do + knife("download /data_bags/x/modified.json").should_succeed <<EOM Updated /data_bags/x/modified.json EOM - knife('diff --name-status /data_bags').should_succeed <<EOM + knife("diff --name-status /data_bags").should_succeed <<EOM D\t/data_bags/x/added.json A\t/data_bags/x/deleted.json EOM end - it 'knife download of the unmodified file does nothing' do - knife('download /data_bags/x/unmodified.json').should_succeed '' - knife('diff --name-status /data_bags').should_succeed <<EOM + it "knife download of the unmodified file does nothing" do + knife("download /data_bags/x/unmodified.json").should_succeed "" + knife("diff --name-status /data_bags").should_succeed <<EOM D\t/data_bags/x/added.json M\t/data_bags/x/modified.json A\t/data_bags/x/deleted.json EOM end - it 'knife download of the added file succeeds' do - knife('download /data_bags/x/added.json').should_succeed <<EOM + it "knife download of the added file succeeds" do + knife("download /data_bags/x/added.json").should_succeed <<EOM Created /data_bags/x/added.json EOM - knife('diff --name-status /data_bags').should_succeed <<EOM + knife("diff --name-status /data_bags").should_succeed <<EOM M\t/data_bags/x/modified.json A\t/data_bags/x/deleted.json EOM end - it 'knife download of the deleted file does nothing' do - knife('download /data_bags/x/deleted.json').should_succeed '' - knife('diff --name-status /data_bags').should_succeed <<EOM + it "knife download of the deleted file does nothing" do + knife("download /data_bags/x/deleted.json").should_succeed "" + knife("diff --name-status /data_bags").should_succeed <<EOM D\t/data_bags/x/added.json M\t/data_bags/x/modified.json A\t/data_bags/x/deleted.json EOM end - it 'knife download --purge of the deleted file deletes it' do - knife('download --purge /data_bags/x/deleted.json').should_succeed <<EOM + it "knife download --purge of the deleted file deletes it" do + knife("download --purge /data_bags/x/deleted.json").should_succeed <<EOM Deleted extra entry /data_bags/x/deleted.json (purge is on) EOM - knife('diff --name-status /data_bags').should_succeed <<EOM + knife("diff --name-status /data_bags").should_succeed <<EOM D\t/data_bags/x/added.json M\t/data_bags/x/modified.json EOM end - it 'knife download of the entire data bag downloads everything' do - knife('download /data_bags/x').should_succeed <<EOM + it "knife download of the entire data bag downloads everything" do + knife("download /data_bags/x").should_succeed <<EOM Created /data_bags/x/added.json Updated /data_bags/x/modified.json EOM - knife('diff --name-status /data_bags').should_succeed <<EOM + knife("diff --name-status /data_bags").should_succeed <<EOM A\t/data_bags/x/deleted.json EOM end - it 'knife download --purge of the entire data bag downloads everything' do - knife('download --purge /data_bags/x').should_succeed <<EOM + it "knife download --purge of the entire data bag downloads everything" do + knife("download --purge /data_bags/x").should_succeed <<EOM Created /data_bags/x/added.json Updated /data_bags/x/modified.json Deleted extra entry /data_bags/x/deleted.json (purge is on) EOM - knife('diff --name-status /data_bags').should_succeed '' + knife("diff --name-status /data_bags").should_succeed "" end - context 'when cwd is the /data_bags directory' do + context "when cwd is the /data_bags directory" do before do - cwd 'data_bags' + 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/ + it "knife download fails" do + knife("download").should_fail "FATAL: You must specify at least one argument. If you want to download everything in this directory, run \"knife download .\"\n", :stdout => /USAGE/ end - it 'knife download --purge . downloads everything' do - knife('download --purge .').should_succeed <<EOM + it "knife download --purge . downloads everything" do + knife("download --purge .").should_succeed <<EOM Created x/added.json Updated x/modified.json Deleted extra entry x/deleted.json (purge is on) EOM - knife('diff --name-status /data_bags').should_succeed '' + knife("diff --name-status /data_bags").should_succeed "" end - it 'knife download --purge * downloads everything' do - knife('download --purge *').should_succeed <<EOM + it "knife download --purge * downloads everything" do + knife("download --purge *").should_succeed <<EOM Created x/added.json Updated x/modified.json Deleted extra entry x/deleted.json (purge is on) EOM - knife('diff --name-status /data_bags').should_succeed '' + knife("diff --name-status /data_bags").should_succeed "" end end end end - when_the_repository 'has a cookbook' do + when_the_repository "has a cookbook" do before do - file 'cookbooks/x/metadata.rb', cb_metadata("x", "1.0.0") - file 'cookbooks/x/z.rb', '' + 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 + when_the_chef_server "has a modified, added and deleted file for the cookbook" do before do - cookbook 'x', '1.0.0', { 'metadata.rb' => cb_metadata("x", "1.0.0", "#extra content"), 'y.rb' => 'hi' } + 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" - knife('diff --name-status /cookbooks').should_succeed <<EOM + it "knife download of a modified file succeeds" do + knife("download /cookbooks/x/metadata.rb").should_succeed "Updated /cookbooks/x/metadata.rb\n" + knife("diff --name-status /cookbooks").should_succeed <<EOM D\t/cookbooks/x/y.rb A\t/cookbooks/x/z.rb EOM end - it 'knife download of a deleted file does nothing' do - knife('download /cookbooks/x/z.rb').should_succeed '' - knife('diff --name-status /cookbooks').should_succeed <<EOM + it "knife download of a deleted file does nothing" do + knife("download /cookbooks/x/z.rb").should_succeed "" + knife("diff --name-status /cookbooks").should_succeed <<EOM M\t/cookbooks/x/metadata.rb D\t/cookbooks/x/y.rb A\t/cookbooks/x/z.rb EOM end - it 'knife download --purge of a deleted file succeeds' do - knife('download --purge /cookbooks/x/z.rb').should_succeed "Deleted extra entry /cookbooks/x/z.rb (purge is on)\n" - knife('diff --name-status /cookbooks').should_succeed <<EOM + it "knife download --purge of a deleted file succeeds" do + knife("download --purge /cookbooks/x/z.rb").should_succeed "Deleted extra entry /cookbooks/x/z.rb (purge is on)\n" + knife("diff --name-status /cookbooks").should_succeed <<EOM M\t/cookbooks/x/metadata.rb D\t/cookbooks/x/y.rb EOM end - it 'knife download of an added file succeeds' do - knife('download /cookbooks/x/y.rb').should_succeed "Created /cookbooks/x/y.rb\n" - knife('diff --name-status /cookbooks').should_succeed <<EOM + it "knife download of an added file succeeds" do + knife("download /cookbooks/x/y.rb").should_succeed "Created /cookbooks/x/y.rb\n" + knife("diff --name-status /cookbooks").should_succeed <<EOM M\t/cookbooks/x/metadata.rb A\t/cookbooks/x/z.rb EOM end - it 'knife download of the cookbook itself succeeds' do - knife('download /cookbooks/x').should_succeed <<EOM + it "knife download of the cookbook itself succeeds" do + knife("download /cookbooks/x").should_succeed <<EOM Updated /cookbooks/x/metadata.rb Created /cookbooks/x/y.rb EOM - knife('diff --name-status /cookbooks').should_succeed <<EOM + knife("diff --name-status /cookbooks").should_succeed <<EOM A\t/cookbooks/x/z.rb EOM end - it 'knife download --purge of the cookbook itself succeeds' do - knife('download --purge /cookbooks/x').should_succeed <<EOM + it "knife download --purge of the cookbook itself succeeds" do + knife("download --purge /cookbooks/x").should_succeed <<EOM Updated /cookbooks/x/metadata.rb Created /cookbooks/x/y.rb Deleted extra entry /cookbooks/x/z.rb (purge is on) EOM - knife('diff --name-status /cookbooks').should_succeed '' + knife("diff --name-status /cookbooks").should_succeed "" end end end - when_the_repository 'has a cookbook' do + when_the_repository "has a cookbook" do before do - file 'cookbooks/x/metadata.rb', cb_metadata("x", "1.0.0") - file 'cookbooks/x/onlyin1.0.0.rb', 'old_text' + 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 + when_the_chef_server "has a later version for the cookbook" do before do - cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => '' } - cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => 'hi' } + 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 + it "knife download /cookbooks/x downloads the latest version" do + knife("download --purge /cookbooks/x").should_succeed <<EOM Updated /cookbooks/x/metadata.rb Created /cookbooks/x/onlyin1.0.1.rb Deleted extra entry /cookbooks/x/onlyin1.0.0.rb (purge is on) EOM - knife('diff --name-status /cookbooks').should_succeed '' + knife("diff --name-status /cookbooks").should_succeed "" end end - when_the_chef_server 'has an earlier version for the cookbook' do + when_the_chef_server "has an earlier version for the cookbook" do before do - cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => ''} - cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => 'hi' } + 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 + 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 EOM - knife('diff --name-status /cookbooks').should_succeed '' + knife("diff --name-status /cookbooks").should_succeed "" end end - when_the_chef_server 'has a later version for the cookbook, and no current version' do + when_the_chef_server "has a later version for the cookbook, and no current version" do before do - cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => 'hi' } + 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 + it "knife download /cookbooks/x downloads the latest version" do + knife("download --purge /cookbooks/x").should_succeed <<EOM Updated /cookbooks/x/metadata.rb Created /cookbooks/x/onlyin1.0.1.rb Deleted extra entry /cookbooks/x/onlyin1.0.0.rb (purge is on) EOM - knife('diff --name-status /cookbooks').should_succeed '' + knife("diff --name-status /cookbooks").should_succeed "" end end - when_the_chef_server 'has an earlier version for the cookbook, and no current version' do + when_the_chef_server "has an earlier version for the cookbook, and no current version" do before do - cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => 'hi' } + 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 + it "knife download /cookbooks/x downloads the old version" do + knife("download --purge /cookbooks/x").should_succeed <<EOM Updated /cookbooks/x/metadata.rb Created /cookbooks/x/onlyin0.9.9.rb Deleted extra entry /cookbooks/x/onlyin1.0.0.rb (purge is on) EOM - knife('diff --name-status /cookbooks').should_succeed '' + knife("diff --name-status /cookbooks").should_succeed "" end end end - when_the_chef_server 'has an environment' do + when_the_chef_server "has a role" do before do - environment 'x', {} + role "x", {} end - when_the_repository 'has an environment with bad JSON' do + when_the_repository "has the role in ruby" do before do - file 'environments/x.json', '{' + file "roles/x.rb", <<EOM +name "x" +description "x" +EOM + end + + it "knife download refuses to change the role" do + knife("download /roles/x.json").should_succeed "", :stderr => "WARNING: /roles/x.rb cannot be updated (can't safely update ruby files).\n" + knife("diff --name-status /roles/x.json").should_succeed "M\t/roles/x.rb\n" end - it 'knife download succeeds' do + end + end + + when_the_chef_server "has an environment" do + before do + environment "x", {} + end + when_the_repository "has an environment with bad JSON" do + before do + file "environments/x.json", "{" + end + it "knife download succeeds" do warning = <<-EOH WARN: Parse error reading #{path_to('environments/x.json')} as JSON: parse error: premature EOF { (right here) ------^ EOH - knife('download /environments/x.json').should_succeed "Updated /environments/x.json\n", :stderr => warning - knife('diff --name-status /environments/x.json').should_succeed '' + knife("download /environments/x.json").should_succeed "Updated /environments/x.json\n", :stderr => warning + knife("diff --name-status /environments/x.json").should_succeed "" end end - when_the_repository 'has the same environment with the wrong name in the file' do + when_the_repository "has the same environment with the wrong name in the file" do before do - file 'environments/x.json', { 'name' => 'y' } + 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 '' + it "knife download succeeds" do + knife("download /environments/x.json").should_succeed "Updated /environments/x.json\n" + knife("diff --name-status /environments/x.json").should_succeed "" end end - when_the_repository 'has the same environment with no name in the file' do + when_the_repository "has the same environment with no name in the file" do before do - file 'environments/x.json', { 'description' => 'hi' } + 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 '' + it "knife download succeeds" do + knife("download /environments/x.json").should_succeed "Updated /environments/x.json\n" + knife("diff --name-status /environments/x.json").should_succeed "" end end end @@ -577,28 +596,28 @@ EOH with_versioned_cookbooks do when_the_chef_server "has one of each thing" do before do - client 'x', {} - cookbook 'x', '1.0.0' - data_bag 'x', { 'y' => {} } - environment 'x', {} - node 'x', {} - role 'x', {} - user 'x', {} + 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 + when_the_repository "has only top-level directories" do before do - directory 'clients' - directory 'cookbooks' - directory 'data_bags' - directory 'environments' - directory 'nodes' - directory 'roles' - directory 'users' + 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 + it "knife download downloads everything" do + knife("download /").should_succeed <<EOM Created /clients/chef-validator.json Created /clients/chef-webui.json Created /clients/x.json @@ -613,49 +632,49 @@ Created /roles/x.json Created /users/admin.json Created /users/x.json EOM - knife('diff --name-status /').should_succeed '' + knife("diff --name-status /").should_succeed "" end end - when_the_repository 'has an identical copy of each thing' do + when_the_repository "has an identical copy of each thing" do 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 } + 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", { "normal" => { "tags" => [] } } + 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 '' - knife('diff --name-status /').should_succeed '' + it "knife download makes no changes" do + knife("download /").should_succeed "" + knife("diff --name-status /").should_succeed "" end - it 'knife download --purge makes no changes' do - knife('download --purge /').should_succeed '' - knife('diff --name-status /').should_succeed '' + it "knife download --purge makes no changes" do + knife("download --purge /").should_succeed "" + knife("diff --name-status /").should_succeed "" end - context 'except the role file' do + context "except the role file" do before do - file 'roles/x.json', { "description" => "blarghle" } + file "roles/x.json", { "description" => "blarghle" } end - it 'knife download changes the role' do - knife('download /').should_succeed "Updated /roles/x.json\n" - knife('diff --name-status /').should_succeed '' + it "knife download changes the role" do + knife("download /").should_succeed "Updated /roles/x.json\n" + knife("diff --name-status /").should_succeed "" end end - context 'except the role file is textually different, but not ACTUALLY different' do + context "except the role file is textually different, but not ACTUALLY different" do before do - file 'roles/x.json', <<EOM + file "roles/x.json", <<EOM { "chef_type": "role" , "default_attributes": { @@ -674,29 +693,29 @@ EOM EOM end - it 'knife download / does not change anything' do - knife('download /').should_succeed '' - knife('diff --name-status /').should_succeed '' + it "knife download / does not change anything" do + knife("download /").should_succeed "" + knife("diff --name-status /").should_succeed "" end end - context 'as well as one extra copy of each thing' do + context "as well as one extra copy of each thing" do 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 } + 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 '' - knife('diff --name-status /').should_succeed <<EOM + it "knife download does nothing" do + knife("download /").should_succeed "" + knife("diff --name-status /").should_succeed <<EOM A\t/clients/y.json A\t/cookbooks/x-1.0.0/blah.rb A\t/cookbooks/x-2.0.0 @@ -710,8 +729,8 @@ A\t/users/y.json EOM end - it 'knife download --purge deletes the extra files' do - knife('download --purge /').should_succeed <<EOM + it "knife download --purge deletes the extra files" do + knife("download --purge /").should_succeed <<EOM Deleted extra entry /clients/y.json (purge is on) Deleted extra entry /cookbooks/x-1.0.0/blah.rb (purge is on) Deleted extra entry /cookbooks/x-2.0.0 (purge is on) @@ -723,14 +742,14 @@ Deleted extra entry /nodes/y.json (purge is on) Deleted extra entry /roles/y.json (purge is on) Deleted extra entry /users/y.json (purge is on) EOM - knife('diff --name-status /').should_succeed '' + knife("diff --name-status /").should_succeed "" end end end - when_the_repository 'is empty' do - it 'knife download creates the extra files' do - knife('download /').should_succeed <<EOM + when_the_repository "is empty" do + it "knife download creates the extra files" do + knife("download /").should_succeed <<EOM Created /clients Created /clients/chef-validator.json Created /clients/chef-webui.json @@ -752,324 +771,324 @@ Created /users Created /users/admin.json Created /users/x.json EOM - knife('diff --name-status /').should_succeed '' + knife("diff --name-status /").should_succeed "" end - context 'when current directory is top level' do + context "when current directory is top level" do before do - cwd '.' + 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/ + it "knife download with no parameters reports an error" do + knife("download").should_fail "FATAL: You must specify at least one argument. If you want to download everything in this directory, run \"knife download .\"\n", :stdout => /USAGE/ end end end end # Test download of an item when the other end doesn't even have the container - when_the_repository 'is empty' do - when_the_chef_server 'has two data bag items' do + when_the_repository "is empty" do + when_the_chef_server "has two data bag items" do before do - data_bag 'x', { 'y' => {}, 'z' => {} } + 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 + it "knife download of one data bag item itself succeeds" do + knife("download /data_bags/x/y.json").should_succeed <<EOM Created /data_bags Created /data_bags/x Created /data_bags/x/y.json EOM - knife('diff --name-status /data_bags').should_succeed <<EOM + knife("diff --name-status /data_bags").should_succeed <<EOM D\t/data_bags/x/z.json EOM end end end - when_the_repository 'has three data bag items' do + when_the_repository "has three data bag items" do before do - file 'data_bags/x/deleted.json', <<EOM + 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 + when_the_chef_server "has a modified, unmodified, added and deleted data bag item" do before do - data_bag 'x', { - 'added' => {}, - 'modified' => { 'foo' => 'bar' }, - 'unmodified' => {} + 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 + it "knife download of the modified file succeeds" do + knife("download /data_bags/x/modified.json").should_succeed <<EOM Updated /data_bags/x/modified.json EOM - knife('diff --name-status /data_bags').should_succeed <<EOM + knife("diff --name-status /data_bags").should_succeed <<EOM D\t/data_bags/x/added.json A\t/data_bags/x/deleted.json EOM end - it 'knife download of the unmodified file does nothing' do - knife('download /data_bags/x/unmodified.json').should_succeed '' - knife('diff --name-status /data_bags').should_succeed <<EOM + it "knife download of the unmodified file does nothing" do + knife("download /data_bags/x/unmodified.json").should_succeed "" + knife("diff --name-status /data_bags").should_succeed <<EOM D\t/data_bags/x/added.json M\t/data_bags/x/modified.json A\t/data_bags/x/deleted.json EOM end - it 'knife download of the added file succeeds' do - knife('download /data_bags/x/added.json').should_succeed <<EOM + it "knife download of the added file succeeds" do + knife("download /data_bags/x/added.json").should_succeed <<EOM Created /data_bags/x/added.json EOM - knife('diff --name-status /data_bags').should_succeed <<EOM + knife("diff --name-status /data_bags").should_succeed <<EOM M\t/data_bags/x/modified.json A\t/data_bags/x/deleted.json EOM end - it 'knife download of the deleted file does nothing' do - knife('download /data_bags/x/deleted.json').should_succeed '' - knife('diff --name-status /data_bags').should_succeed <<EOM + it "knife download of the deleted file does nothing" do + knife("download /data_bags/x/deleted.json").should_succeed "" + knife("diff --name-status /data_bags").should_succeed <<EOM D\t/data_bags/x/added.json M\t/data_bags/x/modified.json A\t/data_bags/x/deleted.json EOM end - it 'knife download --purge of the deleted file deletes it' do - knife('download --purge /data_bags/x/deleted.json').should_succeed <<EOM + it "knife download --purge of the deleted file deletes it" do + knife("download --purge /data_bags/x/deleted.json").should_succeed <<EOM Deleted extra entry /data_bags/x/deleted.json (purge is on) EOM - knife('diff --name-status /data_bags').should_succeed <<EOM + knife("diff --name-status /data_bags").should_succeed <<EOM D\t/data_bags/x/added.json M\t/data_bags/x/modified.json EOM end - it 'knife download of the entire data bag downloads everything' do - knife('download /data_bags/x').should_succeed <<EOM + it "knife download of the entire data bag downloads everything" do + knife("download /data_bags/x").should_succeed <<EOM Created /data_bags/x/added.json Updated /data_bags/x/modified.json EOM - knife('diff --name-status /data_bags').should_succeed <<EOM + knife("diff --name-status /data_bags").should_succeed <<EOM A\t/data_bags/x/deleted.json EOM end - it 'knife download --purge of the entire data bag downloads everything' do - knife('download --purge /data_bags/x').should_succeed <<EOM + it "knife download --purge of the entire data bag downloads everything" do + knife("download --purge /data_bags/x").should_succeed <<EOM Created /data_bags/x/added.json Updated /data_bags/x/modified.json Deleted extra entry /data_bags/x/deleted.json (purge is on) EOM - knife('diff --name-status /data_bags').should_succeed '' + knife("diff --name-status /data_bags").should_succeed "" end - context 'when cwd is the /data_bags directory' do + context "when cwd is the /data_bags directory" do before do - cwd 'data_bags' + 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/ + it "knife download fails" do + knife("download").should_fail "FATAL: You must specify at least one argument. If you want to download everything in this directory, run \"knife download .\"\n", :stdout => /USAGE/ end - it 'knife download --purge . downloads everything' do - knife('download --purge .').should_succeed <<EOM + it "knife download --purge . downloads everything" do + knife("download --purge .").should_succeed <<EOM Created x/added.json Updated x/modified.json Deleted extra entry x/deleted.json (purge is on) EOM - knife('diff --name-status /data_bags').should_succeed '' + knife("diff --name-status /data_bags").should_succeed "" end - it 'knife download --purge * downloads everything' do - knife('download --purge *').should_succeed <<EOM + it "knife download --purge * downloads everything" do + knife("download --purge *").should_succeed <<EOM Created x/added.json Updated x/modified.json Deleted extra entry x/deleted.json (purge is on) EOM - knife('diff --name-status /data_bags').should_succeed '' + knife("diff --name-status /data_bags").should_succeed "" end end end end - when_the_repository 'has a cookbook' do + when_the_repository "has a cookbook" do before do - file 'cookbooks/x-1.0.0/metadata.rb', 'name "x"; version "1.0.0"#unmodified' - file 'cookbooks/x-1.0.0/z.rb', '' + file "cookbooks/x-1.0.0/metadata.rb", 'name "x"; version "1.0.0"#unmodified' + file "cookbooks/x-1.0.0/z.rb", "" end - when_the_chef_server 'has a modified, added and deleted file for the cookbook' do + when_the_chef_server "has a modified, added and deleted file for the cookbook" do before do - cookbook 'x', '1.0.0', { 'y.rb' => 'hi' } + 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" - knife('diff --name-status /cookbooks').should_succeed <<EOM + it "knife download of a modified file succeeds" do + knife("download /cookbooks/x-1.0.0/metadata.rb").should_succeed "Updated /cookbooks/x-1.0.0/metadata.rb\n" + knife("diff --name-status /cookbooks").should_succeed <<EOM D\t/cookbooks/x-1.0.0/y.rb A\t/cookbooks/x-1.0.0/z.rb EOM end - it 'knife download of a deleted file does nothing' do - knife('download /cookbooks/x-1.0.0/z.rb').should_succeed '' - knife('diff --name-status /cookbooks').should_succeed <<EOM + it "knife download of a deleted file does nothing" do + knife("download /cookbooks/x-1.0.0/z.rb").should_succeed "" + knife("diff --name-status /cookbooks").should_succeed <<EOM M\t/cookbooks/x-1.0.0/metadata.rb D\t/cookbooks/x-1.0.0/y.rb A\t/cookbooks/x-1.0.0/z.rb EOM end - it 'knife download --purge of a deleted file succeeds' do - knife('download --purge /cookbooks/x-1.0.0/z.rb').should_succeed "Deleted extra entry /cookbooks/x-1.0.0/z.rb (purge is on)\n" - knife('diff --name-status /cookbooks').should_succeed <<EOM + it "knife download --purge of a deleted file succeeds" do + knife("download --purge /cookbooks/x-1.0.0/z.rb").should_succeed "Deleted extra entry /cookbooks/x-1.0.0/z.rb (purge is on)\n" + knife("diff --name-status /cookbooks").should_succeed <<EOM M\t/cookbooks/x-1.0.0/metadata.rb D\t/cookbooks/x-1.0.0/y.rb EOM end - it 'knife download of an added file succeeds' do - knife('download /cookbooks/x-1.0.0/y.rb').should_succeed "Created /cookbooks/x-1.0.0/y.rb\n" - knife('diff --name-status /cookbooks').should_succeed <<EOM + it "knife download of an added file succeeds" do + knife("download /cookbooks/x-1.0.0/y.rb").should_succeed "Created /cookbooks/x-1.0.0/y.rb\n" + knife("diff --name-status /cookbooks").should_succeed <<EOM M\t/cookbooks/x-1.0.0/metadata.rb A\t/cookbooks/x-1.0.0/z.rb EOM end - it 'knife download of the cookbook itself succeeds' do - knife('download /cookbooks/x-1.0.0').should_succeed <<EOM + it "knife download of the cookbook itself succeeds" do + knife("download /cookbooks/x-1.0.0").should_succeed <<EOM Updated /cookbooks/x-1.0.0/metadata.rb Created /cookbooks/x-1.0.0/y.rb EOM - knife('diff --name-status /cookbooks').should_succeed <<EOM + knife("diff --name-status /cookbooks").should_succeed <<EOM A\t/cookbooks/x-1.0.0/z.rb EOM end - it 'knife download --purge of the cookbook itself succeeds' do - knife('download --purge /cookbooks/x-1.0.0').should_succeed <<EOM + it "knife download --purge of the cookbook itself succeeds" do + knife("download --purge /cookbooks/x-1.0.0").should_succeed <<EOM Updated /cookbooks/x-1.0.0/metadata.rb Created /cookbooks/x-1.0.0/y.rb Deleted extra entry /cookbooks/x-1.0.0/z.rb (purge is on) EOM - knife('diff --name-status /cookbooks').should_succeed '' + knife("diff --name-status /cookbooks").should_succeed "" end end end - when_the_repository 'has a cookbook' do + when_the_repository "has a cookbook" do 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' + 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 + when_the_chef_server "has a later version for the cookbook" do before do - cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => '' } - cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => 'hi' } + 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 + it "knife download /cookbooks/x downloads the latest version" do + knife("download --purge /cookbooks").should_succeed <<EOM Updated /cookbooks/x-1.0.0/onlyin1.0.0.rb Created /cookbooks/x-1.0.1 Created /cookbooks/x-1.0.1/metadata.rb Created /cookbooks/x-1.0.1/onlyin1.0.1.rb EOM - knife('diff --name-status /cookbooks').should_succeed '' + knife("diff --name-status /cookbooks").should_succeed "" end end - when_the_chef_server 'has an earlier version for the cookbook' do + when_the_chef_server "has an earlier version for the cookbook" do before do - cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => ''} - cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => 'hi' } + 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 + it "knife download /cookbooks downloads the updated file" do + knife("download --purge /cookbooks").should_succeed <<EOM Created /cookbooks/x-0.9.9 Created /cookbooks/x-0.9.9/metadata.rb Created /cookbooks/x-0.9.9/onlyin0.9.9.rb Updated /cookbooks/x-1.0.0/onlyin1.0.0.rb EOM - knife('diff --name-status /cookbooks').should_succeed '' + knife("diff --name-status /cookbooks").should_succeed "" end end - when_the_chef_server 'has a later version for the cookbook, and no current version' do + when_the_chef_server "has a later version for the cookbook, and no current version" do before do - cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => 'hi' } + 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 + it "knife download /cookbooks/x downloads the latest version" do + knife("download --purge /cookbooks").should_succeed <<EOM Created /cookbooks/x-1.0.1 Created /cookbooks/x-1.0.1/metadata.rb Created /cookbooks/x-1.0.1/onlyin1.0.1.rb Deleted extra entry /cookbooks/x-1.0.0 (purge is on) EOM - knife('diff --name-status /cookbooks').should_succeed '' + knife("diff --name-status /cookbooks").should_succeed "" end end - when_the_chef_server 'has an earlier version for the cookbook, and no current version' do + when_the_chef_server "has an earlier version for the cookbook, and no current version" do before do - cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => 'hi' } + 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 + it "knife download --purge /cookbooks downloads the old version and deletes the new version" do + knife("download --purge /cookbooks").should_succeed <<EOM Created /cookbooks/x-0.9.9 Created /cookbooks/x-0.9.9/metadata.rb Created /cookbooks/x-0.9.9/onlyin0.9.9.rb Deleted extra entry /cookbooks/x-1.0.0 (purge is on) EOM - knife('diff --name-status /cookbooks').should_succeed '' + knife("diff --name-status /cookbooks").should_succeed "" end end end - when_the_chef_server 'has an environment' do + when_the_chef_server "has an environment" do before do - environment 'x', {} + environment "x", {} end - when_the_repository 'has the same environment with the wrong name in the file' do + when_the_repository "has the same environment with the wrong name in the file" do before do - file 'environments/x.json', { 'name' => 'y' } + 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 '' + it "knife download succeeds" do + knife("download /environments/x.json").should_succeed "Updated /environments/x.json\n" + knife("diff --name-status /environments/x.json").should_succeed "" end end - when_the_repository 'has the same environment with no name in the file' do + when_the_repository "has the same environment with no name in the file" do before do - file 'environments/x.json', { 'description' => 'hi' } + 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 '' + it "knife download succeeds" do + knife("download /environments/x.json").should_succeed "Updated /environments/x.json\n" + knife("diff --name-status /environments/x.json").should_succeed "" end end end end # with versioned cookbooks - when_the_chef_server 'has a cookbook' do + when_the_chef_server "has a cookbook" do before do - cookbook 'x', '1.0.0' + cookbook "x", "1.0.0" end - when_the_repository 'is empty' do - it 'knife download /cookbooks/x signs all requests' do + when_the_repository "is empty" do + it "knife download /cookbooks/x signs all requests" do # Check that BasicClient.request() always gets called with X-OPS-USERID original_new = Chef::HTTP::BasicClient.method(:new) @@ -1077,13 +1096,13 @@ EOM new_result = original_new.call(*args) original_request = new_result.method(:request) expect(new_result).to receive(:request) { |method, url, body, headers, &response_handler| - expect(headers['X-OPS-USERID']).not_to be_nil + expect(headers["X-OPS-USERID"]).not_to be_nil original_request.call(method, url, body, headers, &response_handler) }.at_least(:once) new_result }.at_least(:once) - knife('download /cookbooks/x').should_succeed <<EOM + knife("download /cookbooks/x").should_succeed <<EOM Created /cookbooks Created /cookbooks/x Created /cookbooks/x/metadata.rb @@ -1094,28 +1113,19 @@ EOM when_the_chef_server "is in Enterprise mode", :osc_compat => false, :single_org => false do before do - organization 'foo' do - container 'x', {} - group 'x', {} - end + user "foo", {} + user "bar", {} + user "foobar", {} + organization "foo", { "full_name" => "Something" } end before :each do - Chef::Config.chef_server_url = URI.join(Chef::Config.chef_server_url, '/organizations/foo') + Chef::Config.chef_server_url = URI.join(Chef::Config.chef_server_url, "/organizations/foo") end - when_the_repository 'has existing top level files' do - before do - file 'invitations.json', {} - end - it "can still download top level files" do - knife('download /invitations.json').should_succeed - end - end - - when_the_repository 'is empty' do - it 'knife download / downloads everything' do - knife('download /').should_succeed <<EOM + when_the_repository "has all the default stuff" do + before do + knife("download /").should_succeed <<EOM Created /acls Created /acls/clients Created /acls/clients/foo-validator.json @@ -1129,9 +1139,10 @@ Created /acls/containers/environments.json Created /acls/containers/groups.json Created /acls/containers/nodes.json Created /acls/containers/policies.json +Created /acls/containers/policy_groups.json Created /acls/containers/roles.json Created /acls/containers/sandboxes.json -Created /acls/containers/x.json +Created /acls/cookbook_artifacts Created /acls/cookbooks Created /acls/data_bags Created /acls/environments @@ -1141,8 +1152,9 @@ Created /acls/groups/admins.json Created /acls/groups/billing-admins.json Created /acls/groups/clients.json Created /acls/groups/users.json -Created /acls/groups/x.json Created /acls/nodes +Created /acls/policies +Created /acls/policy_groups Created /acls/roles Created /acls/organization.json Created /clients @@ -1157,9 +1169,10 @@ Created /containers/environments.json Created /containers/groups.json Created /containers/nodes.json Created /containers/policies.json +Created /containers/policy_groups.json Created /containers/roles.json Created /containers/sandboxes.json -Created /containers/x.json +Created /cookbook_artifacts Created /cookbooks Created /data_bags Created /environments @@ -1169,14 +1182,151 @@ Created /groups/admins.json Created /groups/billing-admins.json Created /groups/clients.json Created /groups/users.json -Created /groups/x.json Created /invitations.json Created /members.json Created /nodes Created /org.json +Created /policies +Created /policy_groups Created /roles EOM - knife('diff --name-status /').should_succeed '' + end + + context "and the server has one of each thing" do + before do + # acl_for %w(organizations foo groups blah) + client "x", {} + cookbook "x", "1.0.0" + cookbook_artifact "x", "1x1", { "metadata.rb" => cb_metadata("x", "1.0.0") } + container "x", {} + data_bag "x", { "y" => {} } + environment "x", {} + group "x", {} + org_invite "foo" + org_member "bar" + node "x", {} + policy "x", "1.0.0", {} + policy "blah", "1.0.0", {} + policy_group "x", { + "policies" => { + "x" => { "revision_id" => "1.0.0" }, + "blah" => { "revision_id" => "1.0.0" }, + }, + } + role "x", {} + end + + before do + knife("download /acls /groups/clients.json /groups/users.json").should_succeed <<-EOM +Created /acls/clients/x.json +Created /acls/containers/x.json +Created /acls/cookbook_artifacts/x.json +Created /acls/cookbooks/x.json +Created /acls/data_bags/x.json +Created /acls/environments/x.json +Created /acls/groups/x.json +Created /acls/nodes/x.json +Created /acls/policies/blah.json +Created /acls/policies/x.json +Created /acls/policy_groups/x.json +Created /acls/roles/x.json +Updated /groups/clients.json +Updated /groups/users.json +EOM + end + + it "knife download / downloads everything" do + knife("download /").should_succeed <<EOM +Created /clients/x.json +Created /containers/x.json +Created /cookbook_artifacts/x-1x1 +Created /cookbook_artifacts/x-1x1/metadata.rb +Created /cookbooks/x +Created /cookbooks/x/metadata.rb +Created /data_bags/x +Created /data_bags/x/y.json +Created /environments/x.json +Created /groups/x.json +Updated /invitations.json +Updated /members.json +Created /nodes/x.json +Created /policies/blah-1.0.0.json +Created /policies/x-1.0.0.json +Created /policy_groups/x.json +Created /roles/x.json +EOM + knife("diff --name-status /").should_succeed "" + end + + context "and the repository has an identical copy of each thing" do + before do + # TODO We have to upload acls for an existing group due to a lack of + # dependency detection during upload. Fix that! + file "clients/x.json", { "public_key" => ChefZero::PUBLIC_KEY } + file "containers/x.json", {} + file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0") + file "cookbook_artifacts/x-1x1/metadata.rb", cb_metadata("x", "1.0.0") + file "data_bags/x/y.json", {} + file "environments/x.json", {} + file "groups/x.json", {} + file "invitations.json", [ "foo" ] + file "members.json", [ "bar" ] + file "nodes/x.json", { "normal" => { "tags" => [] } } + file "org.json", { "full_name" => "Something" } + file "policies/x-1.0.0.json", {} + file "policies/blah-1.0.0.json", {} + file "policy_groups/x.json", { "policies" => { "x" => { "revision_id" => "1.0.0" }, "blah" => { "revision_id" => "1.0.0" } } } + file "roles/x.json", {} + end + + it "knife download makes no changes" do + knife("download /").should_succeed "" + end + end + + context "and the repository has a slightly different copy of each thing" do + before do + # acl_for %w(organizations foo groups blah) + file "clients/x.json", { "validator" => true } + file "containers/x.json", {} + file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.1") + file "cookbook_artifacts/x-1x1/metadata.rb", cb_metadata("x", "1.0.1") + file "data_bags/x/y.json", { "a" => "b" } + file "environments/x.json", { "description" => "foo" } + file "groups/x.json", { "description" => "foo" } + file "groups/x.json", { "groups" => [ "admin" ] } + file "nodes/x.json", { "normal" => { "tags" => [] }, "run_list" => [ "blah" ] } + file "org.json", { "full_name" => "Something Else " } + file "policies/x-1.0.0.json", { "run_list" => [ "blah" ] } + file "policy_groups/x.json", { + "policies" => { + "x" => { "revision_id" => "1.0.1" }, + "y" => { "revision_id" => "1.0.0" }, + }, + } + file "roles/x.json", { "run_list" => [ "blah" ] } + end + + it "knife download updates everything" do + knife("download /").should_succeed <<EOM +Updated /clients/x.json +Updated /cookbook_artifacts/x-1x1/metadata.rb +Updated /cookbooks/x/metadata.rb +Updated /data_bags/x/y.json +Updated /environments/x.json +Updated /groups/x.json +Updated /invitations.json +Updated /members.json +Updated /nodes/x.json +Updated /org.json +Created /policies/blah-1.0.0.json +Updated /policies/x-1.0.0.json +Updated /policy_groups/x.json +Updated /roles/x.json +EOM + knife("diff --name-status /").should_succeed "" + end + end end end end diff --git a/spec/integration/knife/environment_compare_spec.rb b/spec/integration/knife/environment_compare_spec.rb new file mode 100644 index 0000000000..3259b27d1b --- /dev/null +++ b/spec/integration/knife/environment_compare_spec.rb @@ -0,0 +1,74 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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" + +describe "knife environment compare", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + when_the_chef_server "has some environments" do + before do + cookbook "blah", "1.0.1" + cookbook "blah", "1.1.1" + cookbook "krad", "1.1.1" + environment "x", { + "cookbook_versions" => { + "blah" => "= 1.0.0", + "krad" => ">= 1.0.0", + }, + } + environment "y", { + "cookbook_versions" => { + "blah" => "= 1.1.0", + "krad" => ">= 1.0.0", + }, + } + end + + # rubocop:disable Style/TrailingWhitespace + it "displays the cookbooks for a single environment" do + knife("environment compare x").should_succeed <<EOM + x +blah = 1.0.0 +krad >= 1.0.0 + +EOM + end + + it "compares the cookbooks for two environments" do + knife("environment compare x y").should_succeed <<EOM + x y +blah = 1.0.0 = 1.1.0 +krad >= 1.0.0 >= 1.0.0 + +EOM + end + + it "compares the cookbooks for all environments" do + knife("environment compare --all").should_succeed <<EOM + x y +blah = 1.0.0 = 1.1.0 +krad >= 1.0.0 >= 1.0.0 + +EOM + end + # rubocop:enable Style/TrailingWhitespace + end +end diff --git a/spec/integration/knife/environment_create_spec.rb b/spec/integration/knife/environment_create_spec.rb new file mode 100644 index 0000000000..03fd4e63f7 --- /dev/null +++ b/spec/integration/knife/environment_create_spec.rb @@ -0,0 +1,40 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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" + +describe "knife environment create", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + let(:out) { "Created bah\n" } + + when_the_chef_server "is empty" do + it "creates a new environment" do + knife("environment create bah").should_succeed out + end + + it "refuses to add an existing environment" do + pending "Knife environment create must not blindly overwrite an existing environment" + knife("environment create bah").should_succeed out + expect { knife("environment create bah") }.to raise_error(Net::HTTPServerException) + end + + end +end diff --git a/spec/integration/knife/environment_delete_spec.rb b/spec/integration/knife/environment_delete_spec.rb new file mode 100644 index 0000000000..0f1fe5c4a8 --- /dev/null +++ b/spec/integration/knife/environment_delete_spec.rb @@ -0,0 +1,36 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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" + +describe "knife environment delete", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + when_the_chef_server "has an environment" do + before do + environment "y", {} + end + + it "deletes an environment" do + knife("environment delete y", input: "y").should_succeed "Do you really want to delete y? (Y/N) Deleted y\n" + end + + end +end diff --git a/spec/integration/knife/environment_from_file_spec.rb b/spec/integration/knife/environment_from_file_spec.rb new file mode 100644 index 0000000000..67d4373939 --- /dev/null +++ b/spec/integration/knife/environment_from_file_spec.rb @@ -0,0 +1,115 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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" + +describe "knife environment from file", :workstation do + include IntegrationSupport + include KnifeSupport + + # include_context "default config options" + + let (:env_dir) { "#{@repository_dir}/environments" } + + when_the_chef_server "is empty" do + when_the_repository "has some environments" do + before do + + file "environments/cons.json", <<EOM +{ + "name": "cons", + "description": "An environment", + "cookbook_versions": { + + }, + "json_class": "Chef::Environment", + "chef_type": "environment", + "default_attributes": { + "hola": "Amigos!" + }, + "override_attributes": { + + } +} +EOM + + file "environments/car.json", <<EOM +{ + "name": "car", + "description": "An environment for list nodes", + "cookbook_versions": { + + }, + "json_class": "Chef::Environment", + "chef_type": "environment", + "default_attributes": { + "hola": "Amigos!" + }, + "override_attributes": { + + } +} +EOM + + file "environments/cdr.json", <<EOM +{ + "name": "cdr", + "description": "An environment for last nodes", + "cookbook_versions": { + + }, + "json_class": "Chef::Environment", + "chef_type": "environment", + "default_attributes": { + "hola": "Amigos!" + }, + "override_attributes": { + + } +} +EOM + + end + + it "uploads a single file" do + knife("environment from file #{env_dir}/cons.json").should_succeed stderr: <<EOM +Updated Environment cons +EOM + end + + it "uploads many files" do + knife("environment from file #{env_dir}/cons.json #{env_dir}/car.json #{env_dir}/cdr.json").should_succeed stderr: <<EOM +Updated Environment cons +Updated Environment car +Updated Environment cdr +EOM + end + + it "uploads all environments in the repository" do + cwd(".") + knife("environment from file --all") + knife("environment list").should_succeed <<EOM +_default +car +cdr +cons +EOM + end + + end + end +end diff --git a/spec/integration/knife/environment_list_spec.rb b/spec/integration/knife/environment_list_spec.rb new file mode 100644 index 0000000000..5e74453d1f --- /dev/null +++ b/spec/integration/knife/environment_list_spec.rb @@ -0,0 +1,41 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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" + +describe "knife environment list", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + when_the_chef_server "has some environments" do + before do + environment "b", {} + environment "y", {} + end + + it "lists all the environments" do + knife("environment list").should_succeed <<EOM +_default +b +y +EOM + end + + end +end diff --git a/spec/integration/knife/environment_show_spec.rb b/spec/integration/knife/environment_show_spec.rb new file mode 100644 index 0000000000..56422dc1a5 --- /dev/null +++ b/spec/integration/knife/environment_show_spec.rb @@ -0,0 +1,76 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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" + +describe "knife environment show", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + when_the_chef_server "has some environments" do + before do + environment "b", { + "default_attributes" => { "foo" => "bar", "baz" => { "raz.my" => "mataz" } }, + } + end + + # rubocop:disable Style/TrailingWhitespace + it "shows an environment" do + knife("environment show b").should_succeed <<EOM +chef_type: environment +cookbook_versions: +default_attributes: + baz: + raz.my: mataz + foo: bar +description: +json_class: Chef::Environment +name: b +override_attributes: +EOM + end + # rubocop:enable Style/TrailingWhitespace + + it "shows the requested attribute of an environment" do + knife("environment show b -a default_attributes").should_succeed <<EOM +b: + default_attributes: + baz: + raz.my: mataz + foo: bar +EOM + end + + it "shows the requested nested attribute of an environment" do + knife("environment show b -a default_attributes.baz").should_succeed <<EON +b: + default_attributes.baz: + raz.my: mataz +EON + end + + it "shows the requested attribute of an environment with custom field separator" do + knife("environment show b -S: -a default_attributes:baz").should_succeed <<EOT +b: + default_attributes:baz: + raz.my: mataz +EOT + end + end +end diff --git a/spec/integration/knife/list_spec.rb b/spec/integration/knife/list_spec.rb index b289642c7d..4aa74f3f0e 100644 --- a/spec/integration/knife/list_spec.rb +++ b/spec/integration/knife/list_spec.rb @@ -1,6 +1,6 @@ # -# Author:: John Keiser (<jkeiser@opscode.com>) -# Copyright:: Copyright (c) 2013 Opscode, Inc. +# Author:: John Keiser (<jkeiser@chef.io>) +# Copyright:: Copyright 2013-2016, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,11 +15,11 @@ # 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 "support/shared/integration/integration_helper" +require "support/shared/context/config" +require "chef/knife/list" -describe 'knife list', :workstation do +describe "knife list", :workstation do include IntegrationSupport include KnifeSupport @@ -27,7 +27,7 @@ describe 'knife list', :workstation do when_the_chef_server "is empty" do it "knife list / returns all top level directories" do - knife('list /').should_succeed <<EOM + knife("list /").should_succeed <<-EOM /clients /cookbooks /data_bags @@ -39,7 +39,7 @@ EOM end it "knife list -R / returns everything" do - knife('list -R /').should_succeed <<EOM + knife("list -R /").should_succeed <<-EOM /: clients cookbooks @@ -72,24 +72,27 @@ EOM when_the_chef_server "has plenty of stuff in it" do 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', {} + 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", {} + policy "policy1", "1.2.3", {} + policy "policy2", "1.2.3", {} + policy "policy2", "1.3.5", {} + role "role1", {} + role "role2", {} + user "user1", {} + user "user2", {} end it "knife list / returns all top level directories" do - knife('list /').should_succeed <<EOM + knife("list /").should_succeed <<-EOM /clients /cookbooks /data_bags @@ -101,7 +104,7 @@ EOM end it "knife list -R / returns everything" do - knife('list -R /').should_succeed <<EOM + knife("list -R /").should_succeed <<-EOM /: clients cookbooks @@ -164,7 +167,7 @@ EOM end it "knife list -R --flat / returns everything" do - knife('list -R --flat /').should_succeed <<EOM + knife("list -R --flat /").should_succeed <<-EOM /clients /clients/chef-validator.json /clients/chef-webui.json @@ -202,7 +205,7 @@ EOM end it "knife list -Rfp / returns everything" do - knife('list -Rfp /').should_succeed <<EOM + knife("list -Rfp /").should_succeed <<-EOM /clients/ /clients/chef-validator.json /clients/chef-webui.json @@ -240,18 +243,18 @@ EOM end it "knife list /cookbooks returns the list of cookbooks" do - knife('list /cookbooks').should_succeed <<EOM + knife("list /cookbooks").should_succeed <<-EOM /cookbooks/cookbook1 /cookbooks/cookbook2 EOM end it "knife list /cookbooks/*2/*/*.rb returns the one file" do - knife('list /cookbooks/*2/*/*.rb').should_succeed "/cookbooks/cookbook2/recipes/default.rb\n" + knife("list /cookbooks/*2/*/*.rb").should_succeed "/cookbooks/cookbook2/recipes/default.rb\n" end it "knife list /**.rb returns all ruby files" do - knife('list /**.rb').should_succeed <<EOM + knife("list /**.rb").should_succeed <<-EOM /cookbooks/cookbook1/metadata.rb /cookbooks/cookbook2/metadata.rb /cookbooks/cookbook2/recipes/default.rb @@ -259,7 +262,7 @@ EOM end it "knife list /cookbooks/**.rb returns all ruby files" do - knife('list /cookbooks/**.rb').should_succeed <<EOM + knife("list /cookbooks/**.rb").should_succeed <<-EOM /cookbooks/cookbook1/metadata.rb /cookbooks/cookbook2/metadata.rb /cookbooks/cookbook2/recipes/default.rb @@ -267,7 +270,7 @@ EOM end it "knife list /**.json returns all json files" do - knife('list /**.json').should_succeed <<EOM + knife("list /**.json").should_succeed <<-EOM /clients/chef-validator.json /clients/chef-webui.json /clients/client1.json @@ -290,7 +293,7 @@ EOM end it "knife list /data**.json returns all data bag json files" do - knife('list /data**.json').should_succeed <<EOM + knife("list /data**.json").should_succeed <<-EOM /data_bags/bag1/item1.json /data_bags/bag1/item2.json /data_bags/bag2/item1.json @@ -299,30 +302,22 @@ EOM end it "knife list /environments/missing_file.json reports missing file" do - knife('list /environments/missing_file.json').should_fail "ERROR: /environments/missing_file.json: No such file or directory\n" + knife("list /environments/missing_file.json").should_fail "ERROR: /environments/missing_file.json: No such file or directory\n" end context "missing file/directory exact match tests" do it "knife list /blarghle reports missing directory" do - knife('list /blarghle').should_fail "ERROR: /blarghle: No such file or directory\n" - end - - it "knife list /roles/blarghle reports missing directory" do - knife('list /roles/blarghle').should_fail "ERROR: /roles/blarghle: No such file or directory\n" - end - - it "knife list /roles/blarghle/blorghle reports missing directory" do - knife('list /roles/blarghle/blorghle').should_fail "ERROR: /roles/blarghle/blorghle: No such file or directory\n" + knife("list /blarghle").should_fail "ERROR: /blarghle: No such file or directory\n" end end - context 'symlink tests' do - when_the_repository 'is empty' do - context 'when cwd is at the top of the repository' do - before { cwd '.' } + context "symlink tests" do + when_the_repository "is empty" do + context "when cwd is at the top of the repository" do + before { cwd "." } it "knife list -Rfp returns everything" do - knife('list -Rfp').should_succeed <<EOM + knife("list -Rfp").should_succeed <<-EOM clients/ clients/chef-validator.json clients/chef-webui.json @@ -361,13 +356,13 @@ EOM end end - when_the_repository 'has a cookbooks directory' do - before { directory 'cookbooks' } - context 'when cwd is in cookbooks/' do - before { cwd 'cookbooks' } + when_the_repository "has a cookbooks directory" do + before { directory "cookbooks" } + context "when cwd is in cookbooks/" do + before { cwd "cookbooks" } it "knife list -Rfp / returns everything" do - knife('list -Rfp /').should_succeed <<EOM + knife("list -Rfp /").should_succeed <<-EOM /clients/ /clients/chef-validator.json /clients/chef-webui.json @@ -405,7 +400,7 @@ EOM end it "knife list -Rfp .. returns everything" do - knife('list -Rfp ..').should_succeed <<EOM + knife("list -Rfp ..").should_succeed <<-EOM /clients/ /clients/chef-validator.json /clients/chef-webui.json @@ -443,7 +438,7 @@ EOM end it "knife list -Rfp returns cookbooks" do - knife('list -Rfp').should_succeed <<EOM + knife("list -Rfp").should_succeed <<-EOM cookbook1/ cookbook1/metadata.rb cookbook2/ @@ -455,14 +450,14 @@ EOM end end - when_the_repository 'has a cookbooks/cookbook2 directory' do - before { directory 'cookbooks/cookbook2' } + when_the_repository "has a cookbooks/cookbook2 directory" do + before { directory "cookbooks/cookbook2" } - context 'when cwd is in cookbooks/cookbook2' do - before { cwd 'cookbooks/cookbook2' } + context "when cwd is in cookbooks/cookbook2" do + before { cwd "cookbooks/cookbook2" } it "knife list -Rfp returns cookbooks" do - knife('list -Rfp').should_succeed <<EOM + knife("list -Rfp").should_succeed <<-EOM metadata.rb recipes/ recipes/default.rb @@ -471,17 +466,17 @@ EOM end end - when_the_repository 'has a cookbooks directory and a symlinked cookbooks directory', :skip => (Chef::Platform.windows?) do + when_the_repository "has a cookbooks directory and a symlinked cookbooks directory", :skip => (Chef::Platform.windows?) do before do - directory 'cookbooks' - symlink 'symlinked', 'cookbooks' + directory "cookbooks" + symlink "symlinked", "cookbooks" end - context 'when cwd is in cookbooks/' do - before { cwd 'cookbooks' } + context "when cwd is in cookbooks/" do + before { cwd "cookbooks" } it "knife list -Rfp returns cookbooks" do - knife('list -Rfp').should_succeed <<EOM + knife("list -Rfp").should_succeed <<-EOM cookbook1/ cookbook1/metadata.rb cookbook2/ @@ -492,11 +487,11 @@ EOM end end - context 'when cwd is in symlinked/' do - before { cwd 'symlinked' } + context "when cwd is in symlinked/" do + before { cwd "symlinked" } it "knife list -Rfp returns cookbooks" do - knife('list -Rfp').should_succeed <<EOM + knife("list -Rfp").should_succeed <<-EOM cookbook1/ cookbook1/metadata.rb cookbook2/ @@ -508,17 +503,17 @@ EOM end end - when_the_repository 'has a real_cookbooks directory and a cookbooks symlink to it', :skip => (Chef::Platform.windows?) do + when_the_repository "has a real_cookbooks directory and a cookbooks symlink to it", :skip => (Chef::Platform.windows?) do before do - directory 'real_cookbooks' - symlink 'cookbooks', 'real_cookbooks' + directory "real_cookbooks" + symlink "cookbooks", "real_cookbooks" end - context 'when cwd is in real_cookbooks/' do - before { cwd 'real_cookbooks' } + context "when cwd is in real_cookbooks/" do + before { cwd "real_cookbooks" } it "knife list -Rfp returns cookbooks" do - knife('list -Rfp').should_succeed <<EOM + knife("list -Rfp").should_succeed <<-EOM cookbook1/ cookbook1/metadata.rb cookbook2/ @@ -529,11 +524,11 @@ EOM end end - context 'when cwd is in cookbooks/' do - before { cwd 'cookbooks' } + context "when cwd is in cookbooks/" do + before { cwd "cookbooks" } it "knife list -Rfp returns cookbooks" do - knife('list -Rfp').should_succeed <<EOM + knife("list -Rfp").should_succeed <<-EOM cookbook1/ cookbook1/metadata.rb cookbook2/ @@ -550,50 +545,51 @@ EOM context "--local" do when_the_repository "is empty" do it "knife list --local / returns nothing" do - knife('list --local /').should_succeed "" + knife("list --local /").should_succeed "" end it "knife list /roles returns nothing" do - knife('list --local /roles').should_fail "ERROR: /roles: No such file or directory\n" + knife("list --local /roles").should_fail "ERROR: /roles: No such file or directory\n" end end when_the_repository "has a bunch of stuff" do before do - file 'clients/client1.json', {} - file 'clients/client2.json', {} + file "clients/client1.json", {} + file "clients/client2.json", {} - directory 'cookbooks/cookbook1' do - file 'metadata.rb', cb_metadata("cookbook1", "1.0.0") + directory "cookbooks/cookbook1" do + file "metadata.rb", cb_metadata("cookbook1", "1.0.0") end - directory 'cookbooks/cookbook2' do - file 'metadata.rb', cb_metadata("cookbook2", "2.0.0") - file 'recipes/default.rb', '' + 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', {} + directory "data_bags" do + directory "bag1" do + file "item1.json", {} + file "item2.json", {} end - directory 'bag2' do - file 'item1.json', {} - file 'item2.json', {} + directory "bag2" do + file "item1.json", {} + file "item2.json", {} 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 + knife("list -Rp --local --flat /").should_succeed <<-EOM /clients/ /clients/client1.json /clients/client2.json @@ -628,15 +624,15 @@ EOM context "missing file/directory tests" do it "knife list --local /blarghle reports missing directory" do - knife('list --local /blarghle').should_fail "ERROR: /blarghle: No such file or directory\n" + knife("list --local /blarghle").should_fail "ERROR: /blarghle: No such file or directory\n" end it "knife list /roles/blarghle reports missing directory" do - knife('list --local /roles/blarghle').should_fail "ERROR: /roles/blarghle: No such file or directory\n" + knife("list --local /roles/blarghle").should_fail "ERROR: /roles/blarghle: No such file or directory\n" end it "knife list /roles/blarghle/blorghle reports missing directory" do - knife('list --local /roles/blarghle/blorghle').should_fail "ERROR: /roles/blarghle/blorghle: No such file or directory\n" + knife("list --local /roles/blarghle/blorghle").should_fail "ERROR: /roles/blarghle/blorghle: No such file or directory\n" end end end @@ -644,19 +640,20 @@ EOM when_the_chef_server "is in Enterprise mode", :osc_compat => false, :single_org => false do before do - organization 'foo' + organization "foo" end before :each do - Chef::Config.chef_server_url = URI.join(Chef::Config.chef_server_url, '/organizations/foo') + Chef::Config.chef_server_url = URI.join(Chef::Config.chef_server_url, "/organizations/foo") end - context 'and is empty' do + context "and is empty" do it "knife list / returns all top level directories" do - knife('list /').should_succeed <<EOM + knife("list /").should_succeed <<-EOM /acls /clients /containers +/cookbook_artifacts /cookbooks /data_bags /environments @@ -665,16 +662,19 @@ EOM /members.json /nodes /org.json +/policies +/policy_groups /roles EOM end it "knife list -R / returns everything" do - knife('list -R /').should_succeed <<EOM + knife("list -R /").should_succeed <<-EOM /: acls clients containers +cookbook_artifacts cookbooks data_bags environments @@ -683,17 +683,22 @@ invitations.json members.json nodes org.json +policies +policy_groups roles /acls: clients containers +cookbook_artifacts cookbooks data_bags environments groups nodes organization.json +policies +policy_groups roles /acls/clients: @@ -709,9 +714,12 @@ environments.json groups.json nodes.json policies.json +policy_groups.json roles.json sandboxes.json +/acls/cookbook_artifacts: + /acls/cookbooks: /acls/data_bags: @@ -727,6 +735,10 @@ users.json /acls/nodes: +/acls/policies: + +/acls/policy_groups: + /acls/roles: /clients: @@ -742,9 +754,12 @@ environments.json groups.json nodes.json policies.json +policy_groups.json roles.json sandboxes.json +/cookbook_artifacts: + /cookbooks: /data_bags: @@ -760,27 +775,22 @@ users.json /nodes: +/policies: + +/policy_groups: + /roles: EOM end end - end - - when_the_chef_server "is in Enterprise mode", :osc_compat => false, :single_org => false do - before do - organization 'foo' - end - before :each do - Chef::Config.chef_server_url = URI.join(Chef::Config.chef_server_url, '/organizations/foo') - end - - it 'knife list -R / returns everything' do - knife('list -R /').should_succeed <<EOM + it "knife list -R / returns everything" do + knife("list -R /").should_succeed <<-EOM /: acls clients containers +cookbook_artifacts cookbooks data_bags environments @@ -789,17 +799,22 @@ invitations.json members.json nodes org.json +policies +policy_groups roles /acls: clients containers +cookbook_artifacts cookbooks data_bags environments groups nodes organization.json +policies +policy_groups roles /acls/clients: @@ -815,9 +830,12 @@ environments.json groups.json nodes.json policies.json +policy_groups.json roles.json sandboxes.json +/acls/cookbook_artifacts: + /acls/cookbooks: /acls/data_bags: @@ -833,6 +851,10 @@ users.json /acls/nodes: +/acls/policies: + +/acls/policy_groups: + /acls/roles: /clients: @@ -848,9 +870,12 @@ environments.json groups.json nodes.json policies.json +policy_groups.json roles.json sandboxes.json +/cookbook_artifacts: + /cookbooks: /data_bags: @@ -866,8 +891,169 @@ users.json /nodes: +/policies: + +/policy_groups: + /roles: EOM end + + context "has plenty of stuff in it" do + before do + client "client1", {} + client "client2", {} + container "container1", {} + container "container2", {} + cookbook "cookbook1", "1.0.0" + cookbook "cookbook2", "1.0.1", { "recipes" => { "default.rb" => "" } } + cookbook_artifact "cookbook_artifact1", "1x1" + cookbook_artifact "cookbook_artifact2", "2x2", { "recipes" => { "default.rb" => "" } } + data_bag "bag1", { "item1" => {}, "item2" => {} } + data_bag "bag2", { "item1" => {}, "item2" => {} } + environment "environment1", {} + environment "environment2", {} + group "group1", {} + group "group2", {} + node "node1", {} + node "node2", {} + org_invite "user1" + org_member "user2" + policy "policy1", "1.2.3", {} + policy "policy2", "1.2.3", {} + policy "policy2", "1.3.5", {} + policy_group "policy_group1", { "policies" => { "policy1" => { "revision_id" => "1.2.3" } } } + policy_group "policy_group2", { "policies" => { "policy2" => { "revision_id" => "1.3.5" } } } + role "role1", {} + role "role2", {} + user "user1", {} + user "user2", {} + end + + it "knife list -Rfp / returns everything" do + knife("list -Rfp /").should_succeed <<-EOM +/acls/ +/acls/clients/ +/acls/clients/client1.json +/acls/clients/client2.json +/acls/clients/foo-validator.json +/acls/containers/ +/acls/containers/clients.json +/acls/containers/container1.json +/acls/containers/container2.json +/acls/containers/containers.json +/acls/containers/cookbook_artifacts.json +/acls/containers/cookbooks.json +/acls/containers/data.json +/acls/containers/environments.json +/acls/containers/groups.json +/acls/containers/nodes.json +/acls/containers/policies.json +/acls/containers/policy_groups.json +/acls/containers/roles.json +/acls/containers/sandboxes.json +/acls/cookbook_artifacts/ +/acls/cookbook_artifacts/cookbook_artifact1.json +/acls/cookbook_artifacts/cookbook_artifact2.json +/acls/cookbooks/ +/acls/cookbooks/cookbook1.json +/acls/cookbooks/cookbook2.json +/acls/data_bags/ +/acls/data_bags/bag1.json +/acls/data_bags/bag2.json +/acls/environments/ +/acls/environments/_default.json +/acls/environments/environment1.json +/acls/environments/environment2.json +/acls/groups/ +/acls/groups/admins.json +/acls/groups/billing-admins.json +/acls/groups/clients.json +/acls/groups/group1.json +/acls/groups/group2.json +/acls/groups/users.json +/acls/nodes/ +/acls/nodes/node1.json +/acls/nodes/node2.json +/acls/organization.json +/acls/policies/ +/acls/policies/policy1.json +/acls/policies/policy2.json +/acls/policy_groups/ +/acls/policy_groups/policy_group1.json +/acls/policy_groups/policy_group2.json +/acls/roles/ +/acls/roles/role1.json +/acls/roles/role2.json +/clients/ +/clients/client1.json +/clients/client2.json +/clients/foo-validator.json +/containers/ +/containers/clients.json +/containers/container1.json +/containers/container2.json +/containers/containers.json +/containers/cookbook_artifacts.json +/containers/cookbooks.json +/containers/data.json +/containers/environments.json +/containers/groups.json +/containers/nodes.json +/containers/policies.json +/containers/policy_groups.json +/containers/roles.json +/containers/sandboxes.json +/cookbook_artifacts/ +/cookbook_artifacts/cookbook_artifact1-1x1/ +/cookbook_artifacts/cookbook_artifact1-1x1/metadata.rb +/cookbook_artifacts/cookbook_artifact2-2x2/ +/cookbook_artifacts/cookbook_artifact2-2x2/metadata.rb +/cookbook_artifacts/cookbook_artifact2-2x2/recipes/ +/cookbook_artifacts/cookbook_artifact2-2x2/recipes/default.rb +/cookbooks/ +/cookbooks/cookbook1/ +/cookbooks/cookbook1/metadata.rb +/cookbooks/cookbook2/ +/cookbooks/cookbook2/metadata.rb +/cookbooks/cookbook2/recipes/ +/cookbooks/cookbook2/recipes/default.rb +/data_bags/ +/data_bags/bag1/ +/data_bags/bag1/item1.json +/data_bags/bag1/item2.json +/data_bags/bag2/ +/data_bags/bag2/item1.json +/data_bags/bag2/item2.json +/environments/ +/environments/_default.json +/environments/environment1.json +/environments/environment2.json +/groups/ +/groups/admins.json +/groups/billing-admins.json +/groups/clients.json +/groups/group1.json +/groups/group2.json +/groups/users.json +/invitations.json +/members.json +/nodes/ +/nodes/node1.json +/nodes/node2.json +/org.json +/policies/ +/policies/policy1-1.2.3.json +/policies/policy2-1.2.3.json +/policies/policy2-1.3.5.json +/policy_groups/ +/policy_groups/policy_group1.json +/policy_groups/policy_group2.json +/roles/ +/roles/role1.json +/roles/role2.json +EOM + end + end end end diff --git a/spec/integration/knife/node_bulk_delete_spec.rb b/spec/integration/knife/node_bulk_delete_spec.rb new file mode 100644 index 0000000000..fa706cbd2b --- /dev/null +++ b/spec/integration/knife/node_bulk_delete_spec.rb @@ -0,0 +1,51 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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" + +describe "knife node bulk delete", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + when_the_chef_server "has some nodes" do + before do + node "cons", {} + node "car", {} + node "cdr", {} + node "cat", {} + end + + it "deletes all matching nodes" do + knife("node bulk delete ^ca.*", input: "Y").should_succeed <<EOM +The following nodes will be deleted: + +car cat + +Are you sure you want to delete these nodes? (Y/N) Deleted node car +Deleted node cat +EOM + + knife("node list").should_succeed <<EOM +cdr +cons +EOM + end + end + +end diff --git a/spec/integration/knife/node_create_spec.rb b/spec/integration/knife/node_create_spec.rb new file mode 100644 index 0000000000..93a2f9ce6f --- /dev/null +++ b/spec/integration/knife/node_create_spec.rb @@ -0,0 +1,46 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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 "openssl" + +describe "knife node create", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + let(:out) { "Created node[bah]\n" } + + when_the_chef_server "is empty" do + it "creates a new node" do + knife("node create bah").should_succeed out + end + + it "creates a new validator node" do + knife("node create bah").should_succeed out + knife("node show bah").should_succeed /Node Name: bah/ + end + + it "refuses to add an existing node" do + pending "Knife node create must not blindly overwrite an existing node" + knife("node create bah").should_succeed out + expect { knife("node create bah") }.to raise_error(Net::HTTPServerException) + end + + end +end diff --git a/spec/integration/knife/node_delete_spec.rb b/spec/integration/knife/node_delete_spec.rb new file mode 100644 index 0000000000..5d88af6d4f --- /dev/null +++ b/spec/integration/knife/node_delete_spec.rb @@ -0,0 +1,47 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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" + +describe "knife node delete", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + when_the_chef_server "has some nodes" do + before do + node "cons", {} + node "car", {} + node "cdr", {} + node "cat", {} + end + + it "deletes a node" do + knife("node delete car", input: "Y").should_succeed <<EOM +Do you really want to delete car? (Y/N) Deleted node[car] +EOM + + knife("node list").should_succeed <<EOM +cat +cdr +cons +EOM + end + + end +end diff --git a/spec/integration/knife/node_environment_set_spec.rb b/spec/integration/knife/node_environment_set_spec.rb new file mode 100644 index 0000000000..10fec5723f --- /dev/null +++ b/spec/integration/knife/node_environment_set_spec.rb @@ -0,0 +1,45 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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" + +describe "knife node environment set", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + when_the_chef_server "has a node and an environment" do + before do + node "cons", {} + environment "lisp", {} + end + + it "sets an environment on a node" do + knife("node environment set cons lisp").should_succeed /chef_environment:.*lisp/ + knife("node show cons -a chef_environment").should_succeed <<EOM +cons: + chef_environment: lisp +EOM + end + + it "with no environment" do + knife("node environment set adam").should_fail stderr: "FATAL: You must specify a node name and an environment.\n", + stdout: /^USAGE: knife node environment set NODE ENVIRONMENT\n/ + end + end +end diff --git a/spec/integration/knife/node_from_file_spec.rb b/spec/integration/knife/node_from_file_spec.rb new file mode 100644 index 0000000000..3430967a21 --- /dev/null +++ b/spec/integration/knife/node_from_file_spec.rb @@ -0,0 +1,58 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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" + +describe "knife node from file", :workstation do + include IntegrationSupport + include KnifeSupport + + # include_context "default config options" + + let (:node_dir) { "#{@repository_dir}/nodes" } + + when_the_chef_server "is empty" do + when_the_repository "has some nodes" do + before do + + file "nodes/cons.json", <<EOM +{ + "name": "cons", + "chef_environment": "_default", + "run_list": [ + "recipe[cons]" +] +, + "normal": { + "tags": [ + + ] + } +} +EOM + + end + + it "uploads a single file" do + knife("node from file #{node_dir}/cons.json").should_succeed stderr: <<EOM +Updated Node cons +EOM + end + + end + end +end diff --git a/spec/integration/knife/node_list_spec.rb b/spec/integration/knife/node_list_spec.rb new file mode 100644 index 0000000000..76f5861e03 --- /dev/null +++ b/spec/integration/knife/node_list_spec.rb @@ -0,0 +1,44 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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" + +describe "knife node list", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + when_the_chef_server "has some nodes" do + before do + node "cons", {} + node "car", {} + node "cdr", {} + node "cat", {} + end + + it "lists all cookbooks" do + knife("node list").should_succeed <<EOM +car +cat +cdr +cons +EOM + end + + end +end diff --git a/spec/integration/knife/node_run_list_add_spec.rb b/spec/integration/knife/node_run_list_add_spec.rb new file mode 100644 index 0000000000..87d08e1975 --- /dev/null +++ b/spec/integration/knife/node_run_list_add_spec.rb @@ -0,0 +1,53 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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" + +describe "knife node run list add", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + when_the_chef_server "has a node with no run_list" do + before do + node "cons", {} + end + + it "sets the run list" do + knife("node run list add cons recipe[foo]").should_succeed /run_list:\s*recipe\[foo\]\n/ + end + end + + when_the_chef_server "has a node with a run_list" do + before do + node "cons", { run_list: ["recipe[bar]"] } + end + + it "appends to the run list" do + knife("node run list add cons recipe[foo]").should_succeed /run_list:\n\s*recipe\[bar\]\n\s*recipe\[foo\]\n/m + end + + it "adds to the run list before the specified item" do + knife("node run list add cons -b recipe[bar] recipe[foo]").should_succeed /run_list:\n\s*recipe\[foo\]\n\s*recipe\[bar\]\n/m + end + + it "adds to the run list after the specified item" do + knife("node run list add cons -a recipe[bar] recipe[foo]").should_succeed /run_list:\n\s*recipe\[bar\]\n\s*recipe\[foo\]\n/m + end + end +end diff --git a/spec/integration/knife/node_run_list_remove_spec.rb b/spec/integration/knife/node_run_list_remove_spec.rb new file mode 100644 index 0000000000..e85e3ed8e8 --- /dev/null +++ b/spec/integration/knife/node_run_list_remove_spec.rb @@ -0,0 +1,35 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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" + +describe "knife node run list remove", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + when_the_chef_server "has a node with a run_list" do + before do + node "cons", { run_list: ["recipe[bar]", "recipe[foo]"] } + end + + it "removes the item from the run list" do + knife("node run list remove cons recipe[bar]").should_succeed /run_list:\s*recipe\[foo\]\n/m + end + end +end diff --git a/spec/integration/knife/node_run_list_set_spec.rb b/spec/integration/knife/node_run_list_set_spec.rb new file mode 100644 index 0000000000..ec6b08fb97 --- /dev/null +++ b/spec/integration/knife/node_run_list_set_spec.rb @@ -0,0 +1,40 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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" + +describe "knife node run list set", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + when_the_chef_server "has a node with a run_list" do + before do + node "cons", { run_list: ["recipe[bar]", "recipe[foo]"] } + end + + it "sets the run list" do + knife("node run list set cons recipe[bar]").should_succeed /run_list:\s*recipe\[bar\]\n/m + end + + it "with no role or recipe" do + knife("node run list set cons").should_fail stderr: "FATAL: You must supply both a node name and a run list.\n", + stdout: /^USAGE: knife node run_list set NODE ENTRIES \(options\)/m + end + end +end diff --git a/spec/integration/knife/node_show_spec.rb b/spec/integration/knife/node_show_spec.rb new file mode 100644 index 0000000000..dd890aed59 --- /dev/null +++ b/spec/integration/knife/node_show_spec.rb @@ -0,0 +1,35 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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" + +describe "knife node show", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + when_the_chef_server "has a node with a run_list" do + before do + node "cons", { run_list: ["recipe[bar]", "recipe[foo]"] } + end + + it "shows the node" do + knife("node show cons").should_succeed /Run List:\s*recipe\[bar\], recipe\[foo\]\n/m + end + end +end diff --git a/spec/integration/knife/raw_spec.rb b/spec/integration/knife/raw_spec.rb index 75fc8fa55e..5e0d3a3d11 100644 --- a/spec/integration/knife/raw_spec.rb +++ b/spec/integration/knife/raw_spec.rb @@ -1,6 +1,6 @@ # -# Author:: John Keiser (<jkeiser@opscode.com>) -# Copyright:: Copyright (c) 2013 Opscode, Inc. +# Author:: John Keiser (<jkeiser@chef.io>) +# Copyright:: Copyright 2013-2016, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,12 +15,12 @@ # 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/raw' -require 'chef/knife/show' +require "support/shared/integration/integration_helper" +require "support/shared/context/config" +require "chef/knife/raw" +require "chef/knife/show" -describe 'knife raw', :workstation do +describe "knife raw", :workstation do include IntegrationSupport include KnifeSupport include AppServerSupport @@ -29,17 +29,17 @@ describe 'knife raw', :workstation do when_the_chef_server "has one of each thing" do before do - client 'x', '{}' - cookbook 'x', '1.0.0' - data_bag 'x', { 'y' => '{}' } - environment 'x', '{}' - node 'x', '{}' - role 'x', '{}' - user 'x', '{}' + 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', :skip => (RUBY_VERSION < "1.9") do - knife('raw /nodes/x').should_succeed <<EOM + it "knife raw /nodes/x returns the node", :skip => (RUBY_VERSION < "1.9") do + knife("raw /nodes/x").should_succeed <<EOM { "name": "x", "json_class": "Chef::Node", @@ -49,7 +49,9 @@ describe 'knife raw', :workstation do }, "normal": { + "tags": [ + ] }, "default": { @@ -64,12 +66,12 @@ describe 'knife raw', :workstation do EOM end - it 'knife raw /blarghle returns 404' do - knife('raw /blarghle').should_fail(/ERROR: Server responded with error 404 "Not Found\s*"/) + it "knife raw /blarghle returns 404" do + knife("raw /blarghle").should_fail(/ERROR: Server responded with error 404 "Not Found\s*"/) end - it 'knife raw -m DELETE /roles/x succeeds', :skip => (RUBY_VERSION < "1.9") do - knife('raw -m DELETE /roles/x').should_succeed <<EOM + it "knife raw -m DELETE /roles/x succeeds", :skip => (RUBY_VERSION < "1.9") do + knife("raw -m DELETE /roles/x").should_succeed <<EOM { "name": "x", "description": "", @@ -89,11 +91,11 @@ EOM } } EOM - knife('show /roles/x.json').should_fail "ERROR: /roles/x.json: No such file or directory\n" + knife("show /roles/x.json").should_fail "ERROR: /roles/x.json: No such file or directory\n" end - it 'knife raw -m PUT -i blah.txt /roles/x succeeds', :skip => (RUBY_VERSION < "1.9") do - Tempfile.open('raw_put_input') do |file| + it "knife raw -m PUT -i blah.txt /roles/x succeeds", :skip => (RUBY_VERSION < "1.9") do + Tempfile.open("raw_put_input") do |file| file.write <<EOM { "name": "x", @@ -136,7 +138,7 @@ EOM } } EOM - knife('show /roles/x.json').should_succeed <<EOM + knife("show /roles/x.json").should_succeed <<EOM /roles/x.json: { "name": "x", @@ -146,8 +148,8 @@ EOM end end - it 'knife raw -m POST -i blah.txt /roles succeeds', :skip => (RUBY_VERSION < "1.9") do - Tempfile.open('raw_put_input') do |file| + it "knife raw -m POST -i blah.txt /roles succeeds", :skip => (RUBY_VERSION < "1.9") do + Tempfile.open("raw_put_input") do |file| file.write <<EOM { "name": "y", @@ -172,7 +174,7 @@ EOM "uri": "#{Chef::Config.chef_server_url}/roles/y" } EOM - knife('show /roles/y.json').should_succeed <<EOM + knife("show /roles/y.json").should_succeed <<EOM /roles/y.json: { "name": "y", @@ -182,11 +184,11 @@ EOM end end - context 'When a server returns raw json' do + context "When a server returns raw json" do before :each do Chef::Config.chef_server_url = "http://localhost:9018" app = lambda do |env| - [200, {'Content-Type' => 'application/json' }, ['{ "x": "y", "a": "b" }'] ] + [200, { "Content-Type" => "application/json" }, ['{ "x": "y", "a": "b" }'] ] end @raw_server, @raw_server_thread = start_app_server(app, 9018) end @@ -196,8 +198,8 @@ EOM @raw_server_thread.kill if @raw_server_thread end - it 'knife raw /blah returns the prettified json', :skip => (RUBY_VERSION < "1.9") do - knife('raw /blah').should_succeed <<EOM + it "knife raw /blah returns the prettified json", :skip => (RUBY_VERSION < "1.9") do + knife("raw /blah").should_succeed <<EOM { "x": "y", "a": "b" @@ -205,18 +207,18 @@ EOM EOM end - it 'knife raw --no-pretty /blah returns the raw json' do - knife('raw --no-pretty /blah').should_succeed <<EOM + it "knife raw --no-pretty /blah returns the raw json" do + knife("raw --no-pretty /blah").should_succeed <<EOM { "x": "y", "a": "b" } EOM end end - context 'When a server returns text' do + context "When a server returns text" do before :each do Chef::Config.chef_server_url = "http://localhost:9018" app = lambda do |env| - [200, {'Content-Type' => 'text' }, ['{ "x": "y", "a": "b" }'] ] + [200, { "Content-Type" => "text" }, ['{ "x": "y", "a": "b" }'] ] end @raw_server, @raw_server_thread = start_app_server(app, 9018) end @@ -226,14 +228,14 @@ EOM @raw_server_thread.kill if @raw_server_thread end - it 'knife raw /blah returns the raw text' do - knife('raw /blah').should_succeed(<<EOM) + it "knife raw /blah returns the raw text" do + knife("raw /blah").should_succeed(<<EOM) { "x": "y", "a": "b" } EOM end - it 'knife raw --no-pretty /blah returns the raw text' do - knife('raw --no-pretty /blah').should_succeed(<<EOM) + it "knife raw --no-pretty /blah returns the raw text" do + knife("raw --no-pretty /blah").should_succeed(<<EOM) { "x": "y", "a": "b" } EOM end diff --git a/spec/integration/knife/redirection_spec.rb b/spec/integration/knife/redirection_spec.rb index 77bda99453..29c1ee6ffb 100644 --- a/spec/integration/knife/redirection_spec.rb +++ b/spec/integration/knife/redirection_spec.rb @@ -1,6 +1,6 @@ # -# Author:: John Keiser (<jkeiser@opscode.com>) -# Copyright:: Copyright (c) 2013 Opscode, Inc. +# Author:: John Keiser (<jkeiser@chef.io>) +# Copyright:: Copyright 2013-2016, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,26 +15,26 @@ # 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 "support/shared/integration/integration_helper" +require "support/shared/context/config" +require "chef/knife/list" -describe 'redirection', :workstation do +describe "redirection", :workstation do include IntegrationSupport include KnifeSupport include AppServerSupport include_context "default config options" - when_the_chef_server 'has a role' do - before { role 'x', {} } + when_the_chef_server "has a role" do + before { role "x", {} } - context 'and another server redirects to it with 302' do + context "and another server redirects to it with 302" do before :each do real_chef_server_url = Chef::Config.chef_server_url Chef::Config.chef_server_url = "http://localhost:9018" app = lambda do |env| - [302, {'Content-Type' => 'text','Location' => "#{real_chef_server_url}#{env['PATH_INFO']}" }, ['302 found'] ] + [302, { "Content-Type" => "text", "Location" => "#{real_chef_server_url}#{env['PATH_INFO']}" }, ["302 found"] ] end @redirector_server, @redirector_server_thread = start_app_server(app, 9018) end @@ -44,8 +44,8 @@ describe 'redirection', :workstation do @redirector_thread.kill if @redirector_thread end - it 'knife list /roles returns the role' do - knife('list /roles').should_succeed "/roles/x.json\n" + it "knife list /roles returns the role" do + knife("list /roles").should_succeed "/roles/x.json\n" end end end diff --git a/spec/integration/knife/role_bulk_delete_spec.rb b/spec/integration/knife/role_bulk_delete_spec.rb new file mode 100644 index 0000000000..0e7ff941e2 --- /dev/null +++ b/spec/integration/knife/role_bulk_delete_spec.rb @@ -0,0 +1,51 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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" + +describe "knife role bulk delete", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + when_the_chef_server "has some roles" do + before do + role "cons", {} + role "car", {} + role "cdr", {} + role "cat", {} + end + + it "deletes all matching roles" do + knife("role bulk delete ^ca.*", input: "Y").should_succeed <<EOM +The following roles will be deleted: + +car cat + +Are you sure you want to delete these roles? (Y/N) Deleted role car +Deleted role cat +EOM + + knife("role list").should_succeed <<EOM +cdr +cons +EOM + end + + end +end diff --git a/spec/integration/knife/role_create_spec.rb b/spec/integration/knife/role_create_spec.rb new file mode 100644 index 0000000000..941eaf5cb6 --- /dev/null +++ b/spec/integration/knife/role_create_spec.rb @@ -0,0 +1,40 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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" + +describe "knife role create", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + let(:out) { "Created role[bah]\n" } + + when_the_chef_server "is empty" do + it "creates a new role" do + knife("role create bah").should_succeed out + end + + it "refuses to add an existing role" do + pending "Knife role create must not blindly overwrite an existing role" + knife("role create bah").should_succeed out + expect { knife("role create bah") }.to raise_error(Net::HTTPServerException) + end + + end +end diff --git a/spec/integration/knife/role_delete_spec.rb b/spec/integration/knife/role_delete_spec.rb new file mode 100644 index 0000000000..9fbd3758b9 --- /dev/null +++ b/spec/integration/knife/role_delete_spec.rb @@ -0,0 +1,47 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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" + +describe "knife role delete", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + when_the_chef_server "has some roles" do + before do + role "cons", {} + role "car", {} + role "cdr", {} + role "cat", {} + end + + it "deletes a role" do + knife("role delete car", input: "Y").should_succeed <<EOM +Do you really want to delete car? (Y/N) Deleted role[car] +EOM + + knife("role list").should_succeed <<EOM +cat +cdr +cons +EOM + end + + end +end diff --git a/spec/integration/knife/role_from_file_spec.rb b/spec/integration/knife/role_from_file_spec.rb new file mode 100644 index 0000000000..60caa3fa88 --- /dev/null +++ b/spec/integration/knife/role_from_file_spec.rb @@ -0,0 +1,95 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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" + +describe "knife role from file", :workstation do + include IntegrationSupport + include KnifeSupport + + # include_context "default config options" + + let (:role_dir) { "#{@repository_dir}/roles" } + + when_the_chef_server "is empty" do + when_the_repository "has some roles" do + before do + + file "roles/cons.json", <<EOM +{ + "name": "cons", + "description": "An role", + "json_class": "Chef::role", + "chef_type": "role", + "default_attributes": { + "hola": "Amigos!" + }, + "override_attributes": { + + } +} +EOM + + file "roles/car.json", <<EOM +{ + "name": "car", + "description": "A role for list nodes", + "json_class": "Chef::Role", + "chef_type": "role", + "default_attributes": { + "hola": "Amigos!" + }, + "override_attributes": { + + } +} +EOM + + file "roles/cdr.json", <<EOM +{ + "name": "cdr", + "description": "A role for last nodes", + "json_class": "Chef::Role", + "chef_type": "role", + "default_attributes": { + "hola": "Amigos!" + }, + "override_attributes": { + + } +} +EOM + + end + + it "uploads a single file" do + knife("role from file #{role_dir}/cons.json").should_succeed stderr: <<EOM +Updated Role cons +EOM + end + + it "uploads many files" do + knife("role from file #{role_dir}/cons.json #{role_dir}/car.json #{role_dir}/cdr.json").should_succeed stderr: <<EOM +Updated Role cons +Updated Role car +Updated Role cdr +EOM + end + + end + end +end diff --git a/spec/integration/knife/role_list_spec.rb b/spec/integration/knife/role_list_spec.rb new file mode 100644 index 0000000000..36dc76be4c --- /dev/null +++ b/spec/integration/knife/role_list_spec.rb @@ -0,0 +1,44 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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" + +describe "knife role list", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + when_the_chef_server "has some roles" do + before do + role "cons", {} + role "car", {} + role "cdr", {} + role "cat", {} + end + + it "lists all cookbooks" do + knife("role list").should_succeed <<EOM +car +cat +cdr +cons +EOM + end + + end +end diff --git a/spec/integration/knife/role_show_spec.rb b/spec/integration/knife/role_show_spec.rb new file mode 100644 index 0000000000..df2572447c --- /dev/null +++ b/spec/integration/knife/role_show_spec.rb @@ -0,0 +1,50 @@ +# +# Copyright:: Copyright 2013-2016, Chef Software 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" + +describe "knife role show", :workstation do + include IntegrationSupport + include KnifeSupport + + include_context "default config options" + + when_the_chef_server "has some roles" do + before do + role "cons", {} + role "car", {} + role "cdr", {} + role "cat", {} + end + + # rubocop:disable Style/TrailingWhitespace + it "shows a cookbook" do + knife("role show cons").should_succeed <<EOM +chef_type: role +default_attributes: +description: +env_run_lists: +json_class: Chef::Role +name: cons +override_attributes: +run_list: +EOM + end + # rubocop:enable Style/TrailingWhitespace + + end +end diff --git a/spec/integration/knife/serve_spec.rb b/spec/integration/knife/serve_spec.rb index 7bf7d29b40..72f0bb59ed 100644 --- a/spec/integration/knife/serve_spec.rb +++ b/spec/integration/knife/serve_spec.rb @@ -1,6 +1,6 @@ # -# Author:: John Keiser (<jkeiser@opscode.com>) -# Copyright:: Copyright (c) 2013 Opscode, Inc. +# Author:: John Keiser (<jkeiser@chef.io>) +# Copyright:: Copyright 2013-2016, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,34 +15,34 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'support/shared/integration/integration_helper' -require 'chef/knife/serve' -require 'chef/server_api' +require "support/shared/integration/integration_helper" +require "chef/knife/serve" +require "chef/server_api" -describe 'knife serve', :workstation do +describe "knife serve", :workstation do include IntegrationSupport include KnifeSupport include AppServerSupport - when_the_repository 'also has one of each thing' do - before { file 'nodes/x.json', { 'foo' => 'bar' } } + when_the_repository "also has one of each thing" do + before { file "nodes/x.json", { "foo" => "bar" } } - it 'knife serve serves up /nodes/x' do + it "knife serve serves up /nodes/x" do exception = nil t = Thread.new do begin - knife('serve --chef-zero-port=8890') + knife("serve --chef-zero-port=8890") rescue exception = $! end end begin Chef::Config.log_level = :debug - Chef::Config.chef_server_url = 'http://localhost:8890' + Chef::Config.chef_server_url = "http://localhost:8890" Chef::Config.node_name = nil Chef::Config.client_key = nil api = Chef::ServerAPI.new - expect(api.get('nodes/x')['name']).to eq('x') + expect(api.get("nodes/x")["name"]).to eq("x") rescue if exception raise exception diff --git a/spec/integration/knife/show_spec.rb b/spec/integration/knife/show_spec.rb index 8f1887e738..ed4802fef9 100644 --- a/spec/integration/knife/show_spec.rb +++ b/spec/integration/knife/show_spec.rb @@ -1,6 +1,6 @@ # -# Author:: John Keiser (<jkeiser@opscode.com>) -# Copyright:: Copyright (c) 2013 Opscode, Inc. +# Author:: John Keiser (<jkeiser@chef.io>) +# Copyright:: Copyright 2013-2016, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,11 +15,11 @@ # 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/show' +require "support/shared/integration/integration_helper" +require "support/shared/context/config" +require "chef/knife/show" -describe 'knife show', :workstation do +describe "knife show", :workstation do include IntegrationSupport include KnifeSupport @@ -27,81 +27,81 @@ describe 'knife show', :workstation do when_the_chef_server "has one of each thing" do before do - client 'x', '{}' - cookbook 'x', '1.0.0' - data_bag 'x', { 'y' => '{}' } - environment 'x', '{}' - node 'x', '{}' - role 'x', '{}' - user 'x', '{}' + 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 + when_the_repository "also has one of each thing" do 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' } + 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 + 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: 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 + 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: name "x"; version "1.0.0" EOM end - it 'knife show /data_bags/x/y.json shows the remote version' do - knife('show /data_bags/x/y.json').should_succeed <<EOM + it "knife show /data_bags/x/y.json shows the remote version" do + knife("show /data_bags/x/y.json").should_succeed <<EOM /data_bags/x/y.json: { "id": "y" } EOM end - it 'knife show --local /data_bags/x/y.json shows the local version' do - knife('show --local /data_bags/x/y.json').should_succeed <<EOM + it "knife show --local /data_bags/x/y.json shows the local version" do + knife("show --local /data_bags/x/y.json").should_succeed <<EOM /data_bags/x/y.json: { "foo": "bar" } EOM end - it 'knife show /environments/x.json shows the remote version', :skip => (RUBY_VERSION < "1.9") do - knife('show /environments/x.json').should_succeed <<EOM + it "knife show /environments/x.json shows the remote version", :skip => (RUBY_VERSION < "1.9") do + knife("show /environments/x.json").should_succeed <<EOM /environments/x.json: { "name": "x" } EOM end - it 'knife show --local /environments/x.json shows the local version' do - knife('show --local /environments/x.json').should_succeed <<EOM + it "knife show --local /environments/x.json shows the local version" do + knife("show --local /environments/x.json").should_succeed <<EOM /environments/x.json: { "foo": "bar" } EOM end - it 'knife show /roles/x.json shows the remote version', :skip => (RUBY_VERSION < "1.9") do - knife('show /roles/x.json').should_succeed <<EOM + it "knife show /roles/x.json shows the remote version", :skip => (RUBY_VERSION < "1.9") do + knife("show /roles/x.json").should_succeed <<EOM /roles/x.json: { "name": "x" } EOM end - it 'knife show --local /roles/x.json shows the local version' do - knife('show --local /roles/x.json').should_succeed <<EOM + it "knife show --local /roles/x.json shows the local version" do + knife("show --local /roles/x.json").should_succeed <<EOM /roles/x.json: { "foo": "bar" @@ -109,34 +109,34 @@ EOM EOM end # show directory - it 'knife show /data_bags/x fails' do - knife('show /data_bags/x').should_fail "ERROR: /data_bags/x: is a directory\n" + it "knife show /data_bags/x fails" do + knife("show /data_bags/x").should_fail "ERROR: /data_bags/x: is a directory\n" end - it 'knife show --local /data_bags/x fails' do - knife('show --local /data_bags/x').should_fail "ERROR: /data_bags/x: is a directory\n" + it "knife show --local /data_bags/x fails" do + knife("show --local /data_bags/x").should_fail "ERROR: /data_bags/x: is a directory\n" end # show nonexistent file - it 'knife show /environments/nonexistent.json fails' do - knife('show /environments/nonexistent.json').should_fail "ERROR: /environments/nonexistent.json: No such file or directory\n" + it "knife show /environments/nonexistent.json fails" do + knife("show /environments/nonexistent.json").should_fail "ERROR: /environments/nonexistent.json: No such file or directory\n" end - it 'knife show --local /environments/nonexistent.json fails' do - knife('show --local /environments/nonexistent.json').should_fail "ERROR: /environments/nonexistent.json: No such file or directory\n" + it "knife show --local /environments/nonexistent.json fails" do + knife("show --local /environments/nonexistent.json").should_fail "ERROR: /environments/nonexistent.json: No such file or directory\n" end end end - when_the_chef_server 'has a hash with multiple keys' do + when_the_chef_server "has a hash with multiple keys" do before do - environment 'x', { - 'default_attributes' => { 'foo' => 'bar' }, - 'cookbook_versions' => { 'blah' => '= 1.0.0'}, - 'override_attributes' => { 'x' => 'y' }, - 'description' => 'woo', - 'name' => 'x' + 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', :skip => (RUBY_VERSION < "1.9") do - knife('show /environments/x.json').should_succeed <<EOM + it "knife show shows the attributes in a predetermined order", :skip => (RUBY_VERSION < "1.9") do + knife("show /environments/x.json").should_succeed <<EOM /environments/x.json: { "name": "x", @@ -155,10 +155,10 @@ EOM end end - when_the_repository 'has an environment with bad JSON' do - before { file 'environments/x.json', '{' } - it 'knife show succeeds' do - knife('show --local /environments/x.json').should_succeed <<EOM + when_the_repository "has an environment with bad JSON" do + before { file "environments/x.json", "{" } + it "knife show succeeds" do + knife("show --local /environments/x.json").should_succeed <<EOM /environments/x.json: { EOM diff --git a/spec/integration/knife/upload_spec.rb b/spec/integration/knife/upload_spec.rb index 6ca8c3d8ce..d372a83a35 100644 --- a/spec/integration/knife/upload_spec.rb +++ b/spec/integration/knife/upload_spec.rb @@ -1,6 +1,6 @@ # -# Author:: John Keiser (<jkeiser@opscode.com>) -# Copyright:: Copyright (c) 2013 Opscode, Inc. +# Author:: John Keiser (<jkeiser@chef.io>) +# Copyright:: Copyright 2013-2016, Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,44 +15,44 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'support/shared/integration/integration_helper' -require 'chef/knife/upload' -require 'chef/knife/diff' -require 'chef/knife/raw' -require 'chef/json_compat' +require "support/shared/integration/integration_helper" +require "chef/knife/upload" +require "chef/knife/diff" +require "chef/knife/raw" +require "chef/json_compat" -describe 'knife upload', :workstation do +describe "knife upload", :workstation do include IntegrationSupport include KnifeSupport - context 'without versioned cookbooks' do + context "without versioned cookbooks" do when_the_chef_server "has one of each thing" do before do - client 'x', {} - cookbook 'x', '1.0.0' - data_bag 'x', { 'y' => {} } - environment 'x', {} - node 'x', {} - role 'x', {} - user 'x', {} + 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 + when_the_repository "has only top-level directories" do 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 '' - knife('diff --name-status /').should_succeed <<EOM + 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 "" + knife("diff --name-status /").should_succeed <<EOM D\t/clients/chef-validator.json D\t/clients/chef-webui.json D\t/clients/x.json @@ -67,8 +67,8 @@ D\t/users/x.json EOM end - it 'knife upload --purge deletes everything' do - knife('upload --purge /').should_succeed(<<EOM, :stderr => "WARNING: /environments/_default.json cannot be deleted (default environment cannot be modified).\n") + it "knife upload --purge deletes everything" do + knife("upload --purge /").should_succeed(<<EOM, :stderr => "WARNING: /environments/_default.json cannot be deleted (default environment cannot be modified).\n") Deleted extra entry /clients/chef-validator.json (purge is on) Deleted extra entry /clients/chef-webui.json (purge is on) Deleted extra entry /clients/x.json (purge is on) @@ -80,56 +80,56 @@ Deleted extra entry /roles/x.json (purge is on) Deleted extra entry /users/admin.json (purge is on) Deleted extra entry /users/x.json (purge is on) EOM - knife('diff --name-status /').should_succeed <<EOM + knife("diff --name-status /").should_succeed <<EOM D\t/environments/_default.json EOM end end - when_the_repository 'has an identical copy of each thing' do + when_the_repository "has an identical copy of each thing" do 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 } + 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", { "normal" => { "tags" => [] } } + 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 '' - knife('diff --name-status /').should_succeed '' + it "knife upload makes no changes" do + knife("upload /cookbooks/x").should_succeed "" + knife("diff --name-status /").should_succeed "" end - it 'knife upload --purge makes no changes' do - knife('upload --purge /').should_succeed '' - knife('diff --name-status /').should_succeed '' + it "knife upload --purge makes no changes" do + knife("upload --purge /").should_succeed "" + knife("diff --name-status /").should_succeed "" end - context 'except the role file' do + context "except the role file" do before do - file 'roles/x.json', { 'description' => 'blarghle' } + 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 '' + it "knife upload changes the role" do + knife("upload /").should_succeed "Updated /roles/x.json\n" + knife("diff --name-status /").should_succeed "" end - it 'knife upload --no-diff does not change the role' do - knife('upload --no-diff /').should_succeed '' - knife('diff --name-status /').should_succeed "M\t/roles/x.json\n" + it "knife upload --no-diff does not change the role" do + knife("upload --no-diff /").should_succeed "" + knife("diff --name-status /").should_succeed "M\t/roles/x.json\n" end end - context 'except the role file is textually different, but not ACTUALLY different' do + context "except the role file is textually different, but not ACTUALLY different" do before do - file 'roles/x.json', <<EOM + file "roles/x.json", <<EOM { "chef_type": "role", "default_attributes": { @@ -148,45 +148,64 @@ EOM EOM end - it 'knife upload / does not change anything' do - knife('upload /').should_succeed '' - knife('diff --name-status /').should_succeed '' + it "knife upload / does not change anything" do + knife("upload /").should_succeed "" + knife("diff --name-status /").should_succeed "" end end - context 'when cookbook metadata has a self-dependency' do + context "the role is in ruby" do before do - file 'cookbooks/x/metadata.rb', "name 'x'; version '1.0.0'; depends 'x'" + file "roles/x.rb", <<EOM +name "x" +description "blargle" +EOM + end + + it "knife upload changes the role" do + knife("upload /").should_succeed "Updated /roles/x.json\n" + knife("diff --name-status /").should_succeed "" + end + + it "knife upload --no-diff does not change the role" do + knife("upload --no-diff /").should_succeed "" + knife("diff --name-status /").should_succeed "M\t/roles/x.rb\n" end + end - it "should warn", :chef_lt_13_only do - knife('upload /cookbooks').should_succeed( + context "when cookbook metadata has a self-dependency" do + before do + file "cookbooks/x/metadata.rb", "name 'x'; version '1.0.0'; depends 'x'" + end + + it "should warn", chef: "< 13" do + knife("upload /cookbooks").should_succeed( stdout: "Updated /cookbooks/x\n", stderr: "WARN: Ignoring self-dependency in cookbook x, please remove it (in the future this will be fatal).\n" ) - knife('diff --name-status /').should_succeed '' + knife("diff --name-status /").should_succeed "" end - it "should fail in Chef 13", :chef_gte_13_only do - knife('upload /cookbooks').should_fail '' + it "should fail in Chef 13", chef: ">= 13" do + knife("upload /cookbooks").should_fail "" # FIXME: include the error message here end end - context 'as well as one extra copy of each thing' do + context "as well as one extra copy of each thing" do 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 } + 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 + it "knife upload adds the new files" do + knife("upload /").should_succeed <<EOM Created /clients/y.json Updated /cookbooks/x Created /cookbooks/y @@ -198,11 +217,11 @@ Created /nodes/y.json Created /roles/y.json Created /users/y.json EOM - knife('diff /').should_succeed '' + knife("diff /").should_succeed "" end - it 'knife upload --no-diff adds the new files' do - knife('upload --no-diff /').should_succeed <<EOM + it "knife upload --no-diff adds the new files" do + knife("upload --no-diff /").should_succeed <<EOM Created /clients/y.json Updated /cookbooks/x Created /cookbooks/y @@ -214,15 +233,15 @@ Created /nodes/y.json Created /roles/y.json Created /users/y.json EOM - knife('diff --name-status /').should_succeed '' + knife("diff --name-status /").should_succeed "" end end end - when_the_repository 'is empty' do - it 'knife upload does nothing' do - knife('upload /').should_succeed '' - knife('diff --name-status /').should_succeed <<EOM + when_the_repository "is empty" do + it "knife upload does nothing" do + knife("upload /").should_succeed "" + knife("diff --name-status /").should_succeed <<EOM D\t/clients D\t/cookbooks D\t/data_bags @@ -233,8 +252,8 @@ D\t/users EOM end - it 'knife upload --purge deletes nothing' do - knife('upload --purge /').should_fail <<EOM + it "knife upload --purge deletes nothing" do + knife("upload --purge /").should_fail <<EOM ERROR: /clients cannot be deleted. ERROR: /cookbooks cannot be deleted. ERROR: /data_bags cannot be deleted. @@ -243,7 +262,7 @@ ERROR: /nodes cannot be deleted. ERROR: /roles cannot be deleted. ERROR: /users cannot be deleted. EOM - knife('diff --name-status /').should_succeed <<EOM + knife("diff --name-status /").should_succeed <<EOM D\t/clients D\t/cookbooks D\t/data_bags @@ -254,178 +273,178 @@ D\t/users EOM end - context 'when current directory is top level' do + context "when current directory is top level" do before do - cwd '.' + 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/ + it "knife upload with no parameters reports an error" do + knife("upload").should_fail "FATAL: You must specify at least one argument. If you want to upload everything in this directory, run \"knife upload .\"\n", :stdout => /USAGE/ end end end end - when_the_chef_server 'is empty' do - when_the_repository 'has a data bag item' do + when_the_chef_server "is empty" do + when_the_repository "has a data bag item" do before do - file 'data_bags/x/y.json', { 'foo' => 'bar' } + 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 + 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 Created /data_bags/x/y.json EOM - knife('diff --name-status /data_bags').should_succeed <<EOM + knife("diff --name-status /data_bags").should_succeed <<EOM EOM - expect(Chef::JSONCompat.parse(knife('raw /data/x/y').stdout, :create_additions => false).keys.sort).to eq([ 'foo', 'id' ]) + expect(Chef::JSONCompat.parse(knife("raw /data/x/y").stdout, :create_additions => false).keys.sort).to eq(%w{foo id}) end - it 'knife upload /data_bags/x /data_bags/x/y.json uploads x once' do - knife('upload /data_bags/x /data_bags/x/y.json').should_succeed <<EOM + it "knife upload /data_bags/x /data_bags/x/y.json uploads x once" do + knife("upload /data_bags/x /data_bags/x/y.json").should_succeed <<EOM Created /data_bags/x Created /data_bags/x/y.json EOM end end - when_the_repository 'has a data bag item with keys chef_type and data_bag' do + when_the_repository "has a data bag item with keys chef_type and data_bag" do before do - file 'data_bags/x/y.json', { 'chef_type' => 'aaa', 'data_bag' => 'bbb' } + 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 + it "upload preserves chef_type and data_bag" do + knife("upload /data_bags/x/y.json").should_succeed <<EOM Created /data_bags/x Created /data_bags/x/y.json EOM - knife('diff --name-status /data_bags').should_succeed '' - result = Chef::JSONCompat.parse(knife('raw /data/x/y').stdout, :create_additions => false) - expect(result.keys.sort).to eq([ 'chef_type', 'data_bag', 'id' ]) - expect(result['chef_type']).to eq('aaa') - expect(result['data_bag']).to eq('bbb') + knife("diff --name-status /data_bags").should_succeed "" + result = Chef::JSONCompat.parse(knife("raw /data/x/y").stdout, :create_additions => false) + expect(result.keys.sort).to eq(%w{chef_type data_bag id}) + expect(result["chef_type"]).to eq("aaa") + expect(result["data_bag"]).to eq("bbb") end end # Test upload of an item when the other end doesn't even have the container - when_the_repository 'has two data bag items' do + when_the_repository "has two data bag items" do before do - file 'data_bags/x/y.json', {} - file 'data_bags/x/z.json', {} + 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 + 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 Created /data_bags/x/y.json EOM - knife('diff --name-status /data_bags').should_succeed <<EOM + knife("diff --name-status /data_bags").should_succeed <<EOM A\t/data_bags/x/z.json EOM end end end - when_the_chef_server 'has three data bag items' do + when_the_chef_server "has three data bag items" do before do - data_bag 'x', { 'deleted' => {}, 'modified' => {}, 'unmodified' => {} } + data_bag "x", { "deleted" => {}, "modified" => {}, "unmodified" => {} } end - when_the_repository 'has a modified, unmodified, added and deleted data bag item' do + when_the_repository "has a modified, unmodified, added and deleted data bag item" do before do - file 'data_bags/x/added.json', {} - file 'data_bags/x/modified.json', { 'foo' => 'bar' } - file 'data_bags/x/unmodified.json', {} + 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 + it "knife upload of the modified file succeeds" do + knife("upload /data_bags/x/modified.json").should_succeed <<EOM Updated /data_bags/x/modified.json EOM - knife('diff --name-status /data_bags').should_succeed <<EOM + knife("diff --name-status /data_bags").should_succeed <<EOM D\t/data_bags/x/deleted.json A\t/data_bags/x/added.json EOM end - it 'knife upload of the unmodified file does nothing' do - knife('upload /data_bags/x/unmodified.json').should_succeed '' - knife('diff --name-status /data_bags').should_succeed <<EOM + it "knife upload of the unmodified file does nothing" do + knife("upload /data_bags/x/unmodified.json").should_succeed "" + knife("diff --name-status /data_bags").should_succeed <<EOM D\t/data_bags/x/deleted.json M\t/data_bags/x/modified.json A\t/data_bags/x/added.json EOM end - it 'knife upload of the added file succeeds' do - knife('upload /data_bags/x/added.json').should_succeed <<EOM + it "knife upload of the added file succeeds" do + knife("upload /data_bags/x/added.json").should_succeed <<EOM Created /data_bags/x/added.json EOM - knife('diff --name-status /data_bags').should_succeed <<EOM + knife("diff --name-status /data_bags").should_succeed <<EOM D\t/data_bags/x/deleted.json M\t/data_bags/x/modified.json EOM end - it 'knife upload of the deleted file does nothing' do - knife('upload /data_bags/x/deleted.json').should_succeed '' - knife('diff --name-status /data_bags').should_succeed <<EOM + it "knife upload of the deleted file does nothing" do + knife("upload /data_bags/x/deleted.json").should_succeed "" + knife("diff --name-status /data_bags").should_succeed <<EOM D\t/data_bags/x/deleted.json M\t/data_bags/x/modified.json A\t/data_bags/x/added.json EOM end - it 'knife upload --purge of the deleted file deletes it' do - knife('upload --purge /data_bags/x/deleted.json').should_succeed <<EOM + it "knife upload --purge of the deleted file deletes it" do + knife("upload --purge /data_bags/x/deleted.json").should_succeed <<EOM Deleted extra entry /data_bags/x/deleted.json (purge is on) EOM - knife('diff --name-status /data_bags').should_succeed <<EOM + knife("diff --name-status /data_bags").should_succeed <<EOM M\t/data_bags/x/modified.json A\t/data_bags/x/added.json EOM end - it 'knife upload of the entire data bag uploads everything' do - knife('upload /data_bags/x').should_succeed <<EOM + it "knife upload of the entire data bag uploads everything" do + knife("upload /data_bags/x").should_succeed <<EOM Created /data_bags/x/added.json Updated /data_bags/x/modified.json EOM - knife('diff --name-status /data_bags').should_succeed <<EOM + knife("diff --name-status /data_bags").should_succeed <<EOM D\t/data_bags/x/deleted.json EOM end - it 'knife upload --purge of the entire data bag uploads everything' do - knife('upload --purge /data_bags/x').should_succeed <<EOM + it "knife upload --purge of the entire data bag uploads everything" do + knife("upload --purge /data_bags/x").should_succeed <<EOM Created /data_bags/x/added.json Updated /data_bags/x/modified.json Deleted extra entry /data_bags/x/deleted.json (purge is on) EOM - knife('diff --name-status /data_bags').should_succeed '' + knife("diff --name-status /data_bags").should_succeed "" end - context 'when cwd is the /data_bags directory' do + context "when cwd is the /data_bags directory" do before do - cwd 'data_bags' + 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/ + it "knife upload fails" do + knife("upload").should_fail "FATAL: You must specify at least one argument. If you want to upload everything in this directory, run \"knife upload .\"\n", :stdout => /USAGE/ end - it 'knife upload --purge . uploads everything' do - knife('upload --purge .').should_succeed <<EOM + it "knife upload --purge . uploads everything" do + knife("upload --purge .").should_succeed <<EOM Created x/added.json Updated x/modified.json Deleted extra entry x/deleted.json (purge is on) EOM - knife('diff --name-status /data_bags').should_succeed '' + knife("diff --name-status /data_bags").should_succeed "" end - it 'knife upload --purge * uploads everything' do - knife('upload --purge *').should_succeed <<EOM + it "knife upload --purge * uploads everything" do + knife("upload --purge *").should_succeed <<EOM Created x/added.json Updated x/modified.json Deleted extra entry x/deleted.json (purge is on) EOM - knife('diff --name-status /data_bags').should_succeed '' + knife("diff --name-status /data_bags").should_succeed "" end end end @@ -434,128 +453,128 @@ EOM # Cookbook upload is a funny thing ... direct cookbook upload works, but # 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 + when_the_chef_server "has a cookbook" do before do - cookbook 'x', '1.0.0', { 'z.rb' => '' } + cookbook "x", "1.0.0", { "z.rb" => "" } end - when_the_repository 'has a modified, extra and missing file for the cookbook' do + when_the_repository "has a modified, extra and missing file for the cookbook" do before do - file 'cookbooks/x/metadata.rb', cb_metadata("x", "1.0.0", "#modified") - file 'cookbooks/x/y.rb', 'hi' + 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" - knife('upload --purge /cookbooks/x/z.rb').should_fail "ERROR: /cookbooks/x/z.rb cannot be deleted.\n" + 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" + knife("upload --purge /cookbooks/x/z.rb").should_fail "ERROR: /cookbooks/x/z.rb cannot be deleted.\n" end # TODO this is a bit of an inconsistency: if we didn't specify --purge, # technically we shouldn't have deleted missing files. But ... cookbooks # are a special case. - it 'knife upload of the cookbook itself succeeds' do - knife('upload /cookbooks/x').should_succeed <<EOM + it "knife upload of the cookbook itself succeeds" do + knife("upload /cookbooks/x").should_succeed <<EOM Updated /cookbooks/x EOM - knife('diff --name-status /cookbooks').should_succeed '' + knife("diff --name-status /cookbooks").should_succeed "" end - it 'knife upload --purge of the cookbook itself succeeds' do - knife('upload /cookbooks/x').should_succeed <<EOM + it "knife upload --purge of the cookbook itself succeeds" do + knife("upload /cookbooks/x").should_succeed <<EOM Updated /cookbooks/x EOM - knife('diff --name-status /cookbooks').should_succeed '' + knife("diff --name-status /cookbooks").should_succeed "" end end - when_the_repository 'has a missing file for the cookbook' do + when_the_repository "has a missing file for the cookbook" do before do - file 'cookbooks/x/metadata.rb', cb_metadata('x', '1.0.0') + 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 + it "knife upload of the cookbook succeeds" do + knife("upload /cookbooks/x").should_succeed <<EOM Updated /cookbooks/x EOM - knife('diff --name-status /cookbooks').should_succeed '' + knife("diff --name-status /cookbooks").should_succeed "" end end - when_the_repository 'has an extra file for the cookbook' do + when_the_repository "has an extra file for the cookbook" do before do - file 'cookbooks/x/metadata.rb', cb_metadata('x', '1.0.0') - file 'cookbooks/x/z.rb', '' - file 'cookbooks/x/blah.rb', '' + 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 + it "knife upload of the cookbook succeeds" do + knife("upload /cookbooks/x").should_succeed <<EOM Updated /cookbooks/x EOM - knife('diff --name-status /cookbooks').should_succeed '' + knife("diff --name-status /cookbooks").should_succeed "" end end - when_the_repository 'has a different file in the cookbook' do + when_the_repository "has a different file in the cookbook" do before do - file 'cookbooks/x/metadata.rb', cb_metadata('x', '1.0.0') + 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 + 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', 'name "x"; version "1.0.0"#different' - knife('upload /cookbooks/x').should_fail "ERROR: /cookbooks failed to write: Cookbook x is frozen\n" + 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 + when_the_chef_server "has a frozen cookbook" do before do - cookbook 'frozencook', '1.0.0', {}, :frozen => true + cookbook "frozencook", "1.0.0", {}, :frozen => true end - when_the_repository 'has an update to said cookbook' do + when_the_repository "has an update to said cookbook" do before do - file 'cookbooks/frozencook/metadata.rb', cb_metadata("frozencook", "1.0.0", "# This is different") + 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" + 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" end - it 'knife upload --force uploads the frozen cookbook' do - knife('upload --force /cookbooks/frozencook').should_succeed <<EOM + it "knife upload --force uploads the frozen cookbook" do + knife("upload --force /cookbooks/frozencook").should_succeed <<EOM Updated /cookbooks/frozencook EOM end end end - when_the_repository 'has a cookbook' do + when_the_repository "has a cookbook" do before do - file 'cookbooks/x/metadata.rb', cb_metadata('x', '1.0.0') - file 'cookbooks/x/onlyin1.0.0.rb', 'old_text' + 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 + when_the_chef_server "has a later version for the cookbook" do before do - cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => '' } - cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => 'hi' } + 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 + it "knife upload /cookbooks/x uploads the local version" do + knife("diff --name-status /cookbooks").should_succeed <<EOM M\t/cookbooks/x/metadata.rb D\t/cookbooks/x/onlyin1.0.1.rb A\t/cookbooks/x/onlyin1.0.0.rb EOM - knife('upload --purge /cookbooks/x').should_succeed <<EOM + knife("upload --purge /cookbooks/x").should_succeed <<EOM Updated /cookbooks/x EOM - knife('diff --name-status /cookbooks').should_succeed <<EOM + knife("diff --name-status /cookbooks").should_succeed <<EOM M\t/cookbooks/x/metadata.rb D\t/cookbooks/x/onlyin1.0.1.rb A\t/cookbooks/x/onlyin1.0.0.rb @@ -563,35 +582,35 @@ EOM end end - when_the_chef_server 'has an earlier version for the cookbook' do + when_the_chef_server "has an earlier version for the cookbook" do before do - cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => ''} - cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => 'hi' } + 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 + it "knife upload /cookbooks/x uploads the local version" do + knife("upload --purge /cookbooks/x").should_succeed <<EOM Updated /cookbooks/x EOM - knife('diff --name-status /cookbooks').should_succeed '' + knife("diff --name-status /cookbooks").should_succeed "" end end - when_the_chef_server 'has a later version for the cookbook, and no current version' do + when_the_chef_server "has a later version for the cookbook, and no current version" do before do - cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => 'hi' } + 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 + it "knife upload /cookbooks/x uploads the local version" do + knife("diff --name-status /cookbooks").should_succeed <<EOM M\t/cookbooks/x/metadata.rb D\t/cookbooks/x/onlyin1.0.1.rb A\t/cookbooks/x/onlyin1.0.0.rb EOM - knife('upload --purge /cookbooks/x').should_succeed <<EOM + knife("upload --purge /cookbooks/x").should_succeed <<EOM Updated /cookbooks/x EOM - knife('diff --name-status /cookbooks').should_succeed <<EOM + knife("diff --name-status /cookbooks").should_succeed <<EOM M\t/cookbooks/x/metadata.rb D\t/cookbooks/x/onlyin1.0.1.rb A\t/cookbooks/x/onlyin1.0.0.rb @@ -599,31 +618,31 @@ EOM end end - when_the_chef_server 'has an earlier version for the cookbook, and no current version' do + when_the_chef_server "has an earlier version for the cookbook, and no current version" do before do - cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => 'hi' } + 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 + it "knife upload /cookbooks/x uploads the new version" do + knife("upload --purge /cookbooks/x").should_succeed <<EOM Updated /cookbooks/x EOM - knife('diff --name-status /cookbooks').should_succeed '' + knife("diff --name-status /cookbooks").should_succeed "" end end end - when_the_chef_server 'has an environment' do + when_the_chef_server "has an environment" do before do - environment 'x', {} + environment "x", {} end - when_the_repository 'has an environment with bad JSON' do + when_the_repository "has an environment with bad JSON" do before do - file 'environments/x.json', '{' + file "environments/x.json", "{" end - it 'knife upload tries and fails' do + it "knife upload tries and fails" do error1 = <<-EOH WARN: Parse error reading #{path_to('environments/x.json')} as JSON: parse error: premature EOF { @@ -632,70 +651,83 @@ WARN: Parse error reading #{path_to('environments/x.json')} as JSON: parse error ERROR: /environments/x.json failed to write: Parse error reading JSON: parse error: premature EOF { (right here) ------^ -EOH + EOH warn = <<-EOH WARN: Parse error reading #{path_to('environments/x.json')} as JSON: parse error: premature EOF { (right here) ------^ -EOH - knife('upload /environments/x.json').should_fail(error1) - knife('diff --name-status /environments/x.json').should_succeed("M\t/environments/x.json\n", :stderr => warn) + EOH + knife("upload /environments/x.json").should_fail(error1) + knife("diff --name-status /environments/x.json").should_succeed("M\t/environments/x.json\n", :stderr => warn) end end - when_the_repository 'has the same environment with the wrong name in the file' do + when_the_repository "has the same environment with the wrong name in the file" do before do - file 'environments/x.json', { 'name' => 'y' } + 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" + 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" end end - when_the_repository 'has the same environment with no name in the file' do + when_the_repository "has the same environment with no name in the file" do before do - file 'environments/x.json', { 'description' => 'hi' } + 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 '' + 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 "" end end end - when_the_chef_server 'is empty' do + when_the_chef_server "is empty" do - when_the_repository 'has an environment with the wrong name in the file' do + when_the_repository "has an environment with the wrong name in the file" do before do - file 'environments/x.json', { 'name' => 'y' } + 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" + 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" end end - when_the_repository 'has an environment with no name in the file' do + when_the_repository "has an environment with no name in the file" do before do - file 'environments/x.json', { 'description' => 'hi' } + 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 '' + 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 "" end end - when_the_repository 'has a data bag with no id in the file' do + when_the_repository "has a data bag with no id in the file" do before do - file 'data_bags/bag/x.json', { 'foo' => 'bar' } + 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 '' + 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 "" + end + end + end + when_the_chef_server "is empty" do + when_the_repository "has a cookbook with an invalid chef_version constraint in it" do + before do + file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0", "\nchef_version '~> 999.0'") + end + it "knife upload succeeds" do + knife("upload /cookbooks/x").should_succeed <<EOM +Created /cookbooks/x +EOM + knife("diff --name-status /cookbooks").should_succeed "" end end end @@ -705,29 +737,29 @@ EOH when_the_chef_server "has one of each thing" do before do - client 'x', {} - cookbook 'x', '1.0.0' - data_bag 'x', { 'y' => {} } - environment 'x', {} - node 'x', {} - role 'x', {} - user 'x', {} + 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 + when_the_repository "has only top-level directories" do 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 '' - knife('diff --name-status /').should_succeed <<EOM + 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 "" + knife("diff --name-status /").should_succeed <<EOM D\t/clients/chef-validator.json D\t/clients/chef-webui.json D\t/clients/x.json @@ -742,8 +774,8 @@ D\t/users/x.json EOM end - it 'knife upload --purge deletes everything' do - knife('upload --purge /').should_succeed(<<EOM, :stderr => "WARNING: /environments/_default.json cannot be deleted (default environment cannot be modified).\n") + it "knife upload --purge deletes everything" do + knife("upload --purge /").should_succeed(<<EOM, :stderr => "WARNING: /environments/_default.json cannot be deleted (default environment cannot be modified).\n") Deleted extra entry /clients/chef-validator.json (purge is on) Deleted extra entry /clients/chef-webui.json (purge is on) Deleted extra entry /clients/x.json (purge is on) @@ -755,52 +787,52 @@ Deleted extra entry /roles/x.json (purge is on) Deleted extra entry /users/admin.json (purge is on) Deleted extra entry /users/x.json (purge is on) EOM - knife('diff --name-status /').should_succeed <<EOM + knife("diff --name-status /").should_succeed <<EOM D\t/environments/_default.json EOM end end - when_the_repository 'has an identical copy of each thing' do + when_the_repository "has an identical copy of each thing" do 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 } + 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", { "normal" => { "tags" => [] } } + 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 '' - knife('diff --name-status /').should_succeed '' + it "knife upload makes no changes" do + knife("upload /cookbooks/x-1.0.0").should_succeed "" + knife("diff --name-status /").should_succeed "" end - it 'knife upload --purge makes no changes' do - knife('upload --purge /').should_succeed '' - knife('diff --name-status /').should_succeed '' + it "knife upload --purge makes no changes" do + knife("upload --purge /").should_succeed "" + knife("diff --name-status /").should_succeed "" end - context 'except the role file' do + context "except the role file" do before do - file 'roles/x.json', { 'description' => 'blarghle' } + 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 '' + it "knife upload changes the role" do + knife("upload /").should_succeed "Updated /roles/x.json\n" + knife("diff --name-status /").should_succeed "" end end - context 'except the role file is textually different, but not ACTUALLY different' do + context "except the role file is textually different, but not ACTUALLY different" do before do - file 'roles/x.json', <<EOM + file "roles/x.json", <<EOM { "chef_type": "role", "default_attributes": { @@ -819,28 +851,28 @@ EOM EOM end - it 'knife upload / does not change anything' do - knife('upload /').should_succeed '' - knife('diff --name-status /').should_succeed '' + it "knife upload / does not change anything" do + knife("upload /").should_succeed "" + knife("diff --name-status /").should_succeed "" end end - context 'as well as one extra copy of each thing' do + context "as well as one extra copy of each thing" do 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 } + 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 + it "knife upload adds the new files" do + knife("upload /").should_succeed <<EOM Created /clients/y.json Updated /cookbooks/x-1.0.0 Created /cookbooks/x-2.0.0 @@ -853,15 +885,15 @@ Created /nodes/y.json Created /roles/y.json Created /users/y.json EOM - knife('diff --name-status /').should_succeed '' + knife("diff --name-status /").should_succeed "" end end end - when_the_repository 'is empty' do - it 'knife upload does nothing' do - knife('upload /').should_succeed '' - knife('diff --name-status /').should_succeed <<EOM + when_the_repository "is empty" do + it "knife upload does nothing" do + knife("upload /").should_succeed "" + knife("diff --name-status /").should_succeed <<EOM D\t/clients D\t/cookbooks D\t/data_bags @@ -872,8 +904,8 @@ D\t/users EOM end - it 'knife upload --purge deletes nothing' do - knife('upload --purge /').should_fail <<EOM + it "knife upload --purge deletes nothing" do + knife("upload --purge /").should_fail <<EOM ERROR: /clients cannot be deleted. ERROR: /cookbooks cannot be deleted. ERROR: /data_bags cannot be deleted. @@ -882,7 +914,7 @@ ERROR: /nodes cannot be deleted. ERROR: /roles cannot be deleted. ERROR: /users cannot be deleted. EOM - knife('diff --name-status /').should_succeed <<EOM + knife("diff --name-status /").should_succeed <<EOM D\t/clients D\t/cookbooks D\t/data_bags @@ -893,130 +925,130 @@ D\t/users EOM end - context 'when current directory is top level' do + context "when current directory is top level" do before do - cwd '.' + 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/ + it "knife upload with no parameters reports an error" do + knife("upload").should_fail "FATAL: You must specify at least one argument. If you want to upload everything in this directory, run \"knife upload .\"\n", :stdout => /USAGE/ end end end end # 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 + when_the_chef_server "is empty" do + when_the_repository "has two data bag items" do before do - file 'data_bags/x/y.json', {} - file 'data_bags/x/z.json', {} + 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 + 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 Created /data_bags/x/y.json EOM - knife('diff --name-status /data_bags').should_succeed <<EOM + knife("diff --name-status /data_bags").should_succeed <<EOM A\t/data_bags/x/z.json EOM end end end - when_the_chef_server 'has three data bag items' do + when_the_chef_server "has three data bag items" do before do - data_bag 'x', { 'deleted' => {}, 'modified' => {}, 'unmodified' => {} } + data_bag "x", { "deleted" => {}, "modified" => {}, "unmodified" => {} } end - when_the_repository 'has a modified, unmodified, added and deleted data bag item' do + when_the_repository "has a modified, unmodified, added and deleted data bag item" do before do - file 'data_bags/x/added.json', {} - file 'data_bags/x/modified.json', { 'foo' => 'bar' } - file 'data_bags/x/unmodified.json', {} + 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 + it "knife upload of the modified file succeeds" do + knife("upload /data_bags/x/modified.json").should_succeed <<EOM Updated /data_bags/x/modified.json EOM - knife('diff --name-status /data_bags').should_succeed <<EOM + knife("diff --name-status /data_bags").should_succeed <<EOM D\t/data_bags/x/deleted.json A\t/data_bags/x/added.json EOM end - it 'knife upload of the unmodified file does nothing' do - knife('upload /data_bags/x/unmodified.json').should_succeed '' - knife('diff --name-status /data_bags').should_succeed <<EOM + it "knife upload of the unmodified file does nothing" do + knife("upload /data_bags/x/unmodified.json").should_succeed "" + knife("diff --name-status /data_bags").should_succeed <<EOM D\t/data_bags/x/deleted.json M\t/data_bags/x/modified.json A\t/data_bags/x/added.json EOM end - it 'knife upload of the added file succeeds' do - knife('upload /data_bags/x/added.json').should_succeed <<EOM + it "knife upload of the added file succeeds" do + knife("upload /data_bags/x/added.json").should_succeed <<EOM Created /data_bags/x/added.json EOM - knife('diff --name-status /data_bags').should_succeed <<EOM + knife("diff --name-status /data_bags").should_succeed <<EOM D\t/data_bags/x/deleted.json M\t/data_bags/x/modified.json EOM end - it 'knife upload of the deleted file does nothing' do - knife('upload /data_bags/x/deleted.json').should_succeed '' - knife('diff --name-status /data_bags').should_succeed <<EOM + it "knife upload of the deleted file does nothing" do + knife("upload /data_bags/x/deleted.json").should_succeed "" + knife("diff --name-status /data_bags").should_succeed <<EOM D\t/data_bags/x/deleted.json M\t/data_bags/x/modified.json A\t/data_bags/x/added.json EOM end - it 'knife upload --purge of the deleted file deletes it' do - knife('upload --purge /data_bags/x/deleted.json').should_succeed <<EOM + it "knife upload --purge of the deleted file deletes it" do + knife("upload --purge /data_bags/x/deleted.json").should_succeed <<EOM Deleted extra entry /data_bags/x/deleted.json (purge is on) EOM - knife('diff --name-status /data_bags').should_succeed <<EOM + knife("diff --name-status /data_bags").should_succeed <<EOM M\t/data_bags/x/modified.json A\t/data_bags/x/added.json EOM end - it 'knife upload of the entire data bag uploads everything' do - knife('upload /data_bags/x').should_succeed <<EOM + it "knife upload of the entire data bag uploads everything" do + knife("upload /data_bags/x").should_succeed <<EOM Created /data_bags/x/added.json Updated /data_bags/x/modified.json EOM - knife('diff --name-status /data_bags').should_succeed <<EOM + knife("diff --name-status /data_bags").should_succeed <<EOM D\t/data_bags/x/deleted.json EOM end - it 'knife upload --purge of the entire data bag uploads everything' do - knife('upload --purge /data_bags/x').should_succeed <<EOM + it "knife upload --purge of the entire data bag uploads everything" do + knife("upload --purge /data_bags/x").should_succeed <<EOM Created /data_bags/x/added.json Updated /data_bags/x/modified.json Deleted extra entry /data_bags/x/deleted.json (purge is on) EOM - knife('diff --name-status /data_bags').should_succeed '' + knife("diff --name-status /data_bags").should_succeed "" end - context 'when cwd is the /data_bags directory' do + context "when cwd is the /data_bags directory" do before do - cwd 'data_bags' + 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/ + it "knife upload fails" do + knife("upload").should_fail "FATAL: You must specify at least one argument. If you want to upload everything in this directory, run \"knife upload .\"\n", :stdout => /USAGE/ end - it 'knife upload --purge . uploads everything' do - knife('upload --purge .').should_succeed <<EOM + it "knife upload --purge . uploads everything" do + knife("upload --purge .").should_succeed <<EOM Created x/added.json Updated x/modified.json Deleted extra entry x/deleted.json (purge is on) EOM - knife('diff --name-status /data_bags').should_succeed '' + knife("diff --name-status /data_bags").should_succeed "" end - it 'knife upload --purge * uploads everything' do - knife('upload --purge *').should_succeed <<EOM + it "knife upload --purge * uploads everything" do + knife("upload --purge *").should_succeed <<EOM Created x/added.json Updated x/modified.json Deleted extra entry x/deleted.json (purge is on) EOM - knife('diff --name-status /data_bags').should_succeed '' + knife("diff --name-status /data_bags").should_succeed "" end end end @@ -1025,256 +1057,275 @@ EOM # Cookbook upload is a funny thing ... direct cookbook upload works, but # 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 + when_the_chef_server "has a cookbook" do before do - cookbook 'x', '1.0.0', { 'z.rb' => '' } + cookbook "x", "1.0.0", { "z.rb" => "" } end - when_the_repository 'has a modified, extra and missing file for the cookbook' do + when_the_repository "has a modified, extra and missing file for the cookbook" do 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' + 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" - knife('upload /cookbooks/x-1.0.0/y.rb').should_fail "ERROR: /cookbooks/x-1.0.0 cannot have a child created under it.\n" - knife('upload --purge /cookbooks/x-1.0.0/z.rb').should_fail "ERROR: /cookbooks/x-1.0.0/z.rb cannot be deleted.\n" + 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" + knife("upload /cookbooks/x-1.0.0/y.rb").should_fail "ERROR: /cookbooks/x-1.0.0 cannot have a child created under it.\n" + knife("upload --purge /cookbooks/x-1.0.0/z.rb").should_fail "ERROR: /cookbooks/x-1.0.0/z.rb cannot be deleted.\n" end # TODO this is a bit of an inconsistency: if we didn't specify --purge, # technically we shouldn't have deleted missing files. But ... cookbooks # are a special case. - it 'knife upload of the cookbook itself succeeds' do - knife('upload /cookbooks/x-1.0.0').should_succeed <<EOM + it "knife upload of the cookbook itself succeeds" do + knife("upload /cookbooks/x-1.0.0").should_succeed <<EOM Updated /cookbooks/x-1.0.0 EOM - knife('diff --name-status /cookbooks').should_succeed '' + knife("diff --name-status /cookbooks").should_succeed "" end - it 'knife upload --purge of the cookbook itself succeeds' do - knife('upload /cookbooks/x-1.0.0').should_succeed <<EOM + it "knife upload --purge of the cookbook itself succeeds" do + knife("upload /cookbooks/x-1.0.0").should_succeed <<EOM Updated /cookbooks/x-1.0.0 EOM - knife('diff --name-status /cookbooks').should_succeed '' + knife("diff --name-status /cookbooks").should_succeed "" end end - when_the_repository 'has a missing file for the cookbook' do + when_the_repository "has a missing file for the cookbook" do before do - file 'cookbooks/x-1.0.0/metadata.rb', cb_metadata('x', "1.0.0") + 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 + it "knife upload of the cookbook succeeds" do + knife("upload /cookbooks/x-1.0.0").should_succeed <<EOM Updated /cookbooks/x-1.0.0 EOM - knife('diff --name-status /cookbooks').should_succeed '' + knife("diff --name-status /cookbooks").should_succeed "" end end - when_the_repository 'has an extra file for the cookbook' do + when_the_repository "has an extra file for the cookbook" do 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', '' + 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 + it "knife upload of the cookbook succeeds" do + knife("upload /cookbooks/x-1.0.0").should_succeed <<EOM Updated /cookbooks/x-1.0.0 EOM - knife('diff --name-status /cookbooks').should_succeed '' + knife("diff --name-status /cookbooks").should_succeed "" end end end - when_the_repository 'has a cookbook' do + when_the_repository "has a cookbook" do 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' + 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 + when_the_chef_server "has a later version for the cookbook" do before do - cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => '' } - cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => 'hi' } + 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 + it "knife upload /cookbooks uploads the local version" do + knife("diff --name-status /cookbooks").should_succeed <<EOM M\t/cookbooks/x-1.0.0/onlyin1.0.0.rb D\t/cookbooks/x-1.0.1 EOM - knife('upload --purge /cookbooks').should_succeed <<EOM + knife("upload --purge /cookbooks").should_succeed <<EOM Updated /cookbooks/x-1.0.0 Deleted extra entry /cookbooks/x-1.0.1 (purge is on) EOM - knife('diff --name-status /cookbooks').should_succeed '' + knife("diff --name-status /cookbooks").should_succeed "" end end - when_the_chef_server 'has an earlier version for the cookbook' do + when_the_chef_server "has an earlier version for the cookbook" do before do - cookbook 'x', '1.0.0', { 'onlyin1.0.0.rb' => ''} - cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => 'hi' } + 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 + it "knife upload /cookbooks uploads the local version" do + knife("upload --purge /cookbooks").should_succeed <<EOM Updated /cookbooks/x-1.0.0 Deleted extra entry /cookbooks/x-0.9.9 (purge is on) EOM - knife('diff --name-status /cookbooks').should_succeed '' + knife("diff --name-status /cookbooks").should_succeed "" end end - when_the_chef_server 'has a later version for the cookbook, and no current version' do + when_the_chef_server "has a later version for the cookbook, and no current version" do before do - cookbook 'x', '1.0.1', { 'onlyin1.0.1.rb' => 'hi' } + 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 + it "knife upload /cookbooks/x uploads the local version" do + knife("diff --name-status /cookbooks").should_succeed <<EOM D\t/cookbooks/x-1.0.1 A\t/cookbooks/x-1.0.0 EOM - knife('upload --purge /cookbooks').should_succeed <<EOM + knife("upload --purge /cookbooks").should_succeed <<EOM Created /cookbooks/x-1.0.0 Deleted extra entry /cookbooks/x-1.0.1 (purge is on) EOM - knife('diff --name-status /cookbooks').should_succeed '' + knife("diff --name-status /cookbooks").should_succeed "" end end - when_the_chef_server 'has an earlier version for the cookbook, and no current version' do + when_the_chef_server "has an earlier version for the cookbook, and no current version" do before do - cookbook 'x', '0.9.9', { 'onlyin0.9.9.rb' => 'hi' } + 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 + it "knife upload /cookbooks/x uploads the new version" do + knife("upload --purge /cookbooks").should_succeed <<EOM Created /cookbooks/x-1.0.0 Deleted extra entry /cookbooks/x-0.9.9 (purge is on) EOM - knife('diff --name-status /cookbooks').should_succeed '' + knife("diff --name-status /cookbooks").should_succeed "" end end end - when_the_chef_server 'has an environment' do + when_the_chef_server "has an environment" do before do - environment 'x', {} + environment "x", {} end - when_the_repository 'has the same environment with the wrong name in the file' do + when_the_repository "has the same environment with the wrong name in the file" do before do - file 'environments/x.json', { 'name' => 'y' } + 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" + 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" end end - when_the_repository 'has the same environment with no name in the file' do + when_the_repository "has the same environment with no name in the file" do before do - file 'environments/x.json', { 'description' => 'hi' } + 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 '' + 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 "" end end end - when_the_chef_server 'is empty' do + when_the_chef_server "is empty" do - when_the_repository 'has an environment with the wrong name in the file' do + when_the_repository "has an environment with the wrong name in the file" do before do - file 'environments/x.json', { 'name' => 'y' } + 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" + 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" end end - when_the_repository 'has an environment with no name in the file' do + when_the_repository "has an environment with no name in the file" do before do - file 'environments/x.json', { 'description' => 'hi' } + 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 '' + 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 "" end end - when_the_repository 'has a data bag with no id in the file' do + when_the_repository "has a data bag with no id in the file" do + 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 "" + end + end + end + + when_the_chef_server "is empty" do + when_the_repository "has a cookbook with an invalid chef_version constraint in it" do before do - file 'data_bags/bag/x.json', { 'foo' => 'bar' } + file "cookbooks/x-1.0.0/metadata.rb", cb_metadata("x", "1.0.0", "\nchef_version '~> 999.0'") 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 '' + it "knife upload succeeds" do + knife("upload /cookbooks/x-1.0.0").should_succeed <<EOM +Created /cookbooks/x-1.0.0 +EOM + knife("diff --name-status /cookbooks").should_succeed "" end end end end # with versioned cookbooks - when_the_chef_server 'has a user' do + when_the_chef_server "has a user" do before do - user 'x', {} + user "x", {} end - when_the_repository 'has the same user with json_class in it' do + when_the_repository "has the same user with json_class in it" do before do - file 'users/x.json', { 'admin' => true, 'json_class' => 'Chef::WebUIUser' } + 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" + it "knife upload /users/x.json succeeds" do + knife("upload /users/x.json").should_succeed "Updated /users/x.json\n" end end end when_the_chef_server "is in Enterprise mode", :osc_compat => false, :single_org => false do before do - user 'foo', {} - user 'bar', {} - user 'foobar', {} - organization 'foo', { 'full_name' => 'Something'} + user "foo", {} + user "bar", {} + user "foobar", {} + organization "foo", { "full_name" => "Something" } end before :each do - Chef::Config.chef_server_url = URI.join(Chef::Config.chef_server_url, '/organizations/foo') + Chef::Config.chef_server_url = URI.join(Chef::Config.chef_server_url, "/organizations/foo") end - context 'and has nothing but a single group named blah' do - group 'blah', {} + context "and has nothing but a single group named blah" do + group "blah", {} - when_the_repository 'has one of each thing' do + when_the_repository "has at least one of each thing" do before do # TODO We have to upload acls for an existing group due to a lack of # dependency detection during upload. Fix that! - file 'acls/groups/blah.json', {} - file 'clients/x.json', { 'public_key' => ChefZero::PUBLIC_KEY } - file 'containers/x.json', {} - file 'cookbooks/x/metadata.rb', cb_metadata("x", "1.0.0") - file 'data_bags/x/y.json', {} - file 'environments/x.json', {} - file 'groups/x.json', {} - file 'invitations.json', [ 'foo' ] - file 'members.json', [ 'bar' ] - file 'nodes/x.json', {} - file 'org.json', { 'full_name' => 'wootles' } - file 'roles/x.json', {} - end - - it 'knife upload / uploads everything' do - knife('upload /').should_succeed <<EOM + file "acls/groups/blah.json", {} + file "clients/x.json", { "public_key" => ChefZero::PUBLIC_KEY } + file "containers/x.json", {} + file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0") + file "cookbook_artifacts/x-1x1/metadata.rb", cb_metadata("x", "1.0.0") + file "data_bags/x/y.json", {} + file "environments/x.json", {} + file "groups/x.json", {} + file "invitations.json", [ "foo" ] + file "members.json", [ "bar" ] + file "org.json", { "full_name" => "wootles" } + file "nodes/x.json", { "normal" => { "tags" => [] } } + file "policies/x-1.0.0.json", {} + file "policies/blah-1.0.0.json", {} + file "policy_groups/x.json", { "policies" => { "x" => { "revision_id" => "1.0.0" }, "blah" => { "revision_id" => "1.0.0" } } } + file "roles/x.json", {} + end + + it "knife upload / uploads everything" do + knife("upload /").should_succeed <<EOM Updated /acls/groups/blah.json Created /clients/x.json Created /containers/x.json +Created /cookbook_artifacts/x-1x1 Created /cookbooks/x Created /data_bags/x Created /data_bags/x/y.json @@ -1284,105 +1335,211 @@ Updated /invitations.json Updated /members.json Created /nodes/x.json Updated /org.json +Created /policies/blah-1.0.0.json +Created /policies/x-1.0.0.json +Created /policy_groups/x.json Created /roles/x.json EOM - expect(api.get('association_requests').map { |a| a['username'] }).to eq([ 'foo' ]) - expect(api.get('users').map { |a| a['user']['username'] }).to eq([ 'bar' ]) + expect(api.get("association_requests").map { |a| a["username"] }).to eq([ "foo" ]) + expect(api.get("users").map { |a| a["user"]["username"] }).to eq([ "bar" ]) + knife("diff --name-status --diff-filter=AMT /").should_succeed "" + end + + context "When the chef server has an identical copy of each thing" do + before do + file "invitations.json", [ "foo" ] + file "members.json", [ "bar" ] + file "org.json", { "full_name" => "Something" } + + # acl_for %w(organizations foo groups blah) + client "x", {} + cookbook "x", "1.0.0" + cookbook_artifact "x", "1x1", "metadata.rb" => cb_metadata("x", "1.0.0") + container "x", {} + data_bag "x", { "y" => {} } + environment "x", {} + group "x", {} + org_invite "foo" + org_member "bar" + node "x", {} + policy "x", "1.0.0", {} + policy "blah", "1.0.0", {} + policy_group "x", { + "policies" => { + "x" => { "revision_id" => "1.0.0" }, + "blah" => { "revision_id" => "1.0.0" }, + }, + } + role "x", {} + end + + it "knife upload makes no changes" do + knife("upload /").should_succeed <<EOM +Updated /acls/groups/blah.json +EOM + end + end + + context "When the chef server has a slightly different copy of the policy revision" do + before do + policy "x", "1.0.0", { "run_list" => [ "blah" ] } + end + + it "should fail because policies are not updateable" do + knife("upload /policies/x-1.0.0.json").should_fail <<EOM +ERROR: /policies/x-1.0.0.json cannot be updated: policy revisions are immutable once uploaded. If you want to change the policy, create a new revision with your changes. +EOM + end + end + + context "When the chef server has a slightly different copy of the cookbook artifact" do + before do + cookbook_artifact "x", "1x1", { "recipes" => { "default.rb" => "" } } + end + + it "should fail because cookbook_artifacts cannot be updated" do + knife("upload /cookbook_artifacts/x-1x1").should_fail <<EOM +ERROR: /cookbook_artifacts/x-1x1 cannot be updated: cookbook artifacts are immutable once uploaded. +EOM + end + end + + context "When the chef server has a slightly different copy of each thing (except policy revisions)" do + before do + # acl_for %w(organizations foo groups blah) + client "x", { "validator" => true } + container "x", {} + cookbook "x", "1.0.0", { "recipes" => { "default.rb" => "" } } + cookbook_artifact "x", "1x1", { "metadata.rb" => cb_metadata("x", "1.0.0") } + data_bag "x", { "y" => { "a" => "b" } } + environment "x", { "description" => "foo" } + group "x", { "groups" => [ "admin" ] } + node "x", { "run_list" => [ "blah" ] } + policy "x", "1.0.0", {} + policy "x", "1.0.1", {} + policy "y", "1.0.0", {} + policy_group "x", { + "policies" => { + "x" => { "revision_id" => "1.0.1" }, + "y" => { "revision_id" => "1.0.0" }, + }, + } + role "x", { "run_list" => [ "blah" ] } + end + + it "knife upload updates everything" do + knife("upload /").should_succeed <<EOM +Updated /acls/groups/blah.json +Updated /clients/x.json +Updated /cookbooks/x +Updated /data_bags/x/y.json +Updated /environments/x.json +Updated /groups/x.json +Updated /invitations.json +Updated /members.json +Updated /nodes/x.json +Updated /org.json +Created /policies/blah-1.0.0.json +Updated /policy_groups/x.json +Updated /roles/x.json +EOM + knife("diff --name-status --diff-filter=AMT /").should_succeed "" + end end end - when_the_repository 'has an org.json that does not change full_name' do + when_the_repository "has an org.json that does not change full_name" do before do - file 'org.json', { 'full_name' => 'Something' } + file "org.json", { "full_name" => "Something" } end - it 'knife upload / emits a warning for bar and adds foo and foobar' do - knife('upload /').should_succeed '' - expect(api.get('/')['full_name']).to eq('Something') + it "knife upload / emits a warning for bar and adds foo and foobar" do + knife("upload /").should_succeed "" + expect(api.get("/")["full_name"]).to eq("Something") end end - when_the_repository 'has an org.json that changes full_name' do + when_the_repository "has an org.json that changes full_name" do before do - file 'org.json', { 'full_name' => 'Something Else'} + file "org.json", { "full_name" => "Something Else" } end - it 'knife upload / emits a warning for bar and adds foo and foobar' do - knife('upload /').should_succeed "Updated /org.json\n" - expect(api.get('/')['full_name']).to eq('Something Else') + it "knife upload / emits a warning for bar and adds foo and foobar" do + knife("upload /").should_succeed "Updated /org.json\n" + expect(api.get("/")["full_name"]).to eq("Something Else") end end - context 'and has invited foo and bar is already a member' do - org_invite 'foo' - org_member 'bar' + context "and has invited foo and bar is already a member" do + org_invite "foo" + org_member "bar" - when_the_repository 'wants to invite foo, bar and foobar' do + when_the_repository "wants to invite foo, bar and foobar" do before do - file 'invitations.json', [ 'foo', 'bar', 'foobar' ] + file "invitations.json", %w{foo bar foobar} end - it 'knife upload / emits a warning for bar and invites foobar' do - knife('upload /').should_succeed "Updated /invitations.json\n", :stderr => "WARN: Could not invite bar to organization foo: User bar is already in organization foo\n" - expect(api.get('association_requests').map { |a| a['username'] }).to eq([ 'foo', 'foobar' ]) - expect(api.get('users').map { |a| a['user']['username'] }).to eq([ 'bar' ]) + it "knife upload / emits a warning for bar and invites foobar" do + knife("upload /").should_succeed "Updated /invitations.json\n", :stderr => "WARN: Could not invite bar to organization foo: User bar is already in organization foo\n" + expect(api.get("association_requests").map { |a| a["username"] }).to eq(%w{foo foobar}) + expect(api.get("users").map { |a| a["user"]["username"] }).to eq([ "bar" ]) end end - when_the_repository 'wants to make foo, bar and foobar members' do + when_the_repository "wants to make foo, bar and foobar members" do before do - file 'members.json', [ 'foo', 'bar', 'foobar' ] + file "members.json", %w{foo bar foobar} end - it 'knife upload / emits a warning for bar and adds foo and foobar' do - knife('upload /').should_succeed "Updated /members.json\n" - expect(api.get('association_requests').map { |a| a['username'] }).to eq([ ]) - expect(api.get('users').map { |a| a['user']['username'] }).to eq([ 'bar', 'foo', 'foobar' ]) + it "knife upload / emits a warning for bar and adds foo and foobar" do + knife("upload /").should_succeed "Updated /members.json\n" + expect(api.get("association_requests").map { |a| a["username"] }).to eq([ ]) + expect(api.get("users").map { |a| a["user"]["username"] }).to eq(%w{bar foo foobar}) end end - when_the_repository 'wants to invite foo and have bar as a member' do + when_the_repository "wants to invite foo and have bar as a member" do before do - file 'invitations.json', [ 'foo' ] - file 'members.json', [ 'bar' ] + file "invitations.json", [ "foo" ] + file "members.json", [ "bar" ] end - it 'knife upload / does nothing' do - knife('upload /').should_succeed '' - expect(api.get('association_requests').map { |a| a['username'] }).to eq([ 'foo' ]) - expect(api.get('users').map { |a| a['user']['username'] }).to eq([ 'bar' ]) + it "knife upload / does nothing" do + knife("upload /").should_succeed "" + expect(api.get("association_requests").map { |a| a["username"] }).to eq([ "foo" ]) + expect(api.get("users").map { |a| a["user"]["username"] }).to eq([ "bar" ]) end end end - context 'and has invited bar and foo' do - org_invite 'bar', 'foo' + context "and has invited bar and foo" do + org_invite "bar", "foo" - when_the_repository 'wants to invite foo and bar (different order)' do + when_the_repository "wants to invite foo and bar (different order)" do before do - file 'invitations.json', [ 'foo', 'bar' ] + file "invitations.json", %w{foo bar} end - it 'knife upload / does nothing' do - knife('upload /').should_succeed '' - expect(api.get('association_requests').map { |a| a['username'] }).to eq([ 'bar', 'foo' ]) - expect(api.get('users').map { |a| a['user']['username'] }).to eq([ ]) + it "knife upload / does nothing" do + knife("upload /").should_succeed "" + expect(api.get("association_requests").map { |a| a["username"] }).to eq(%w{bar foo}) + expect(api.get("users").map { |a| a["user"]["username"] }).to eq([ ]) end end end - context 'and has already added bar and foo as members of the org' do - org_member 'bar', 'foo' + context "and has already added bar and foo as members of the org" do + org_member "bar", "foo" - when_the_repository 'wants to add foo and bar (different order)' do + when_the_repository "wants to add foo and bar (different order)" do before do - file 'members.json', [ 'foo', 'bar' ] + file "members.json", %w{foo bar} end - it 'knife upload / does nothing' do - knife('upload /').should_succeed '' - expect(api.get('association_requests').map { |a| a['username'] }).to eq([ ]) - expect(api.get('users').map { |a| a['user']['username'] }).to eq([ 'bar', 'foo' ]) + it "knife upload / does nothing" do + knife("upload /").should_succeed "" + expect(api.get("association_requests").map { |a| a["username"] }).to eq([ ]) + expect(api.get("users").map { |a| a["user"]["username"] }).to eq(%w{bar foo}) end end end diff --git a/spec/integration/recipes/accumulator_spec.rb b/spec/integration/recipes/accumulator_spec.rb new file mode 100644 index 0000000000..e6afe09b8c --- /dev/null +++ b/spec/integration/recipes/accumulator_spec.rb @@ -0,0 +1,232 @@ +require "support/shared/integration/integration_helper" +require "chef/mixin/shell_out" + +describe "Accumulators" do + include IntegrationSupport + include Chef::Mixin::ShellOut + + let(:chef_dir) { File.expand_path("../../../../bin", __FILE__) } + + # Invoke `chef-client` as `ruby PATH/TO/chef-client`. This ensures the + # following constraints are satisfied: + # * Windows: windows can only run batch scripts as bare executables. Rubygems + # creates batch wrappers for installed gems, but we don't have batch wrappers + # in the source tree. + # * Other `chef-client` in PATH: A common case is running the tests on a + # machine that has omnibus chef installed. In that case we need to ensure + # we're running `chef-client` from the source tree and not the external one. + # cf. CHEF-4914 + let(:chef_client) { "ruby '#{chef_dir}/chef-client' --minimal-ohai" } + + let(:aliases_temppath) do + t = Tempfile.new("chef_accumulator_test") + path = t.path + t.close + t.unlink + path + end + + when_the_repository "edit_resource-based delayed accumulators work" do + before do + directory "cookbooks/x" do + file "resources/email_alias.rb", <<-EOM + provides :email_alias + resource_name :email_alias + + property :address, String, name_property: true, identity: true + property :recipients, Array + + default_action :create + + action :create do + with_run_context :root do + edit_resource(:template, "#{aliases_temppath}") do |new_resource| + source "aliases.erb" + variables[:aliases] ||= {} + variables[:aliases][new_resource.address] ||= [] + variables[:aliases][new_resource.address] += new_resource.recipients + action :nothing + delayed_action :create + end + end + end + EOM + + file "resources/nested.rb", <<-EOM + provides :nested + resource_name :nested + + property :address, String, name_property: true, identity: true + property :recipients, Array + + default_action :create + + action :create do + email_alias address do + recipients new_resource.recipients + end + end + EOM + + file "resources/doubly_nested.rb", <<-EOM + provides :doubly_nested + resource_name :doubly_nested + + property :address, String, name_property: true, identity: true + property :recipients, Array + + default_action :create + + action :create do + nested address do + recipients new_resource.recipients + end + end + EOM + + file "recipes/default.rb", <<-EOM + email_alias "outer1" do + recipients [ "out1a", "out1b" ] + end + + nested "nested1" do + recipients [ "nested1a", "nested1b" ] + end + + email_alias "outer2" do + recipients [ "out2a", "out2b" ] + end + + doubly_nested "nested2" do + recipients [ "nested2a", "nested2b" ] + end + + email_alias "outer3" do + recipients [ "out3a", "out3b" ] + end + EOM + + file "templates/aliases.erb", <<-EOM.gsub(/^\s+/, "") + <%= pp @aliases %> + EOM + end # directory 'cookbooks/x' + end + + it "should complete with success" do + file "config/client.rb", <<-EOM + local_mode true + cookbook_path "#{path_to('cookbooks')}" + log_level :warn + EOM + + result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" --no-color -F doc -o 'x::default'", :cwd => chef_dir) + result.error! + # runs only a single template resource (in the outer run context, as a delayed resource) + expect(result.stdout.scan(/template\S+ action create/).size).to eql(1) + # hash order is insertion order in ruby >= 1.9, so this next line does test that all calls were in the correct order + expect(IO.read(aliases_temppath).chomp).to eql('{"outer1"=>["out1a", "out1b"], "nested1"=>["nested1a", "nested1b"], "outer2"=>["out2a", "out2b"], "nested2"=>["nested2a", "nested2b"], "outer3"=>["out3a", "out3b"]}') + end + end + + when_the_repository "find_resource-based delayed accumulators work" do + before do + directory "cookbooks/x" do + file "resources/email_alias.rb", <<-EOM + provides :email_alias + resource_name :email_alias + + property :address, String, name_property: true, identity: true + property :recipients, Array + + default_action :create + + action :create do + r = with_run_context :root do + find_resource(:template, "#{aliases_temppath}") do + source "aliases.erb" + variables[:aliases] = {} + action :nothing + delayed_action :create + end + end + r.variables[:aliases][address] ||= [] + r.variables[:aliases][address] += new_resource.recipients + end + EOM + + file "resources/nested.rb", <<-EOM + provides :nested + resource_name :nested + + property :address, String, name_property: true, identity: true + property :recipients, Array + + default_action :create + + action :create do + email_alias address do + recipients new_resource.recipients + end + end + EOM + + file "resources/doubly_nested.rb", <<-EOM + provides :doubly_nested + resource_name :doubly_nested + + property :address, String, name_property: true, identity: true + property :recipients, Array + + default_action :create + + action :create do + nested address do + recipients new_resource.recipients + end + end + EOM + + file "recipes/default.rb", <<-EOM + email_alias "outer1" do + recipients [ "out1a", "out1b" ] + end + + nested "nested1" do + recipients [ "nested1a", "nested1b" ] + end + + email_alias "outer2" do + recipients [ "out2a", "out2b" ] + end + + doubly_nested "nested2" do + recipients [ "nested2a", "nested2b" ] + end + + email_alias "outer3" do + recipients [ "out3a", "out3b" ] + end + EOM + + file "templates/aliases.erb", <<-EOM.gsub(/^\s+/, "") + <%= pp @aliases %> + EOM + end # directory 'cookbooks/x' + end + + it "should complete with success" do + file "config/client.rb", <<-EOM + local_mode true + cookbook_path "#{path_to('cookbooks')}" + log_level :warn + EOM + + result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" --no-color -F doc -o 'x::default'", :cwd => chef_dir) + result.error! + # runs only a single template resource (in the outer run context, as a delayed resource) + expect(result.stdout.scan(/template\S+ action create/).size).to eql(1) + # hash order is insertion order in ruby >= 1.9, so this next line does test that all calls were in the correct order + expect(IO.read(aliases_temppath).chomp).to eql('{"outer1"=>["out1a", "out1b"], "nested1"=>["nested1a", "nested1b"], "outer2"=>["out2a", "out2b"], "nested2"=>["nested2a", "nested2b"], "outer3"=>["out3a", "out3b"]}') + end + end +end diff --git a/spec/integration/recipes/lwrp_inline_resources_spec.rb b/spec/integration/recipes/lwrp_inline_resources_spec.rb index e70605d3d3..65931d4764 100644 --- a/spec/integration/recipes/lwrp_inline_resources_spec.rb +++ b/spec/integration/recipes/lwrp_inline_resources_spec.rb @@ -1,5 +1,5 @@ -require 'support/shared/integration/integration_helper' -require 'chef/mixin/shell_out' +require "support/shared/integration/integration_helper" +require "chef/mixin/shell_out" describe "LWRPs with inline resources" do include IntegrationSupport @@ -18,41 +18,138 @@ describe "LWRPs with inline resources" do # cf. CHEF-4914 let(:chef_client) { "ruby '#{chef_dir}/chef-client' --minimal-ohai" } + context "with a use_inline_resources provider with 'def action_a' instead of action :a" do + class LwrpInlineResourcesTest < Chef::Resource::LWRPBase + resource_name :lwrp_inline_resources_test + actions :a, :nothing + default_action :a + property :ran_a + class Provider < Chef::Provider::LWRPBase + provides :lwrp_inline_resources_test + use_inline_resources + def action_a + r = new_resource + ruby_block "run a" do + block { r.ran_a "ran a" } + end + end + end + end + + it "this is totally a bug, but for backcompat purposes, it adds the resources to the main resource collection and does not get marked updated" do + r = nil + expect_recipe do + r = lwrp_inline_resources_test "hi" + end.to have_updated("ruby_block[run a]", :run) + expect(r.ran_a).to eq "ran a" + end + end + + context "with an inline resource with a property that shadows the enclosing provider's property" do + class LwrpShadowedPropertyTest < Chef::Resource::LWRPBase + PATH = ::File.join(Dir.tmpdir, "shadow-property.txt") + use_automatic_resource_name + actions :fiddle + property :content + action :fiddle do + file PATH do + content new_resource.content + action [:create, :delete] + end + end + end + + after { File.delete(LwrpShadowedPropertyTest::PATH) if File.exists?(LwrpShadowedPropertyTest::PATH) } + + # https://github.com/chef/chef/issues/4334 + it "does not warn spuriously" do + expect(Chef::Log).to_not receive(:warn).with(/is declared in both/) + expect_recipe do + lwrp_shadowed_property_test "fnord" do + action :fiddle + end + end + end + end + + context "with an inline_resources provider with two actions, one calling the other" do + class LwrpInlineResourcesTest2 < Chef::Resource::LWRPBase + resource_name :lwrp_inline_resources_test2 + actions :a, :b, :nothing + default_action :b + property :ran_a + property :ran_b + class Provider < Chef::Provider::LWRPBase + provides :lwrp_inline_resources_test2 + use_inline_resources + + action :a do + r = new_resource + ruby_block "run a" do + block { r.ran_a "ran a" } + end + end + + action :b do + action_a + r = new_resource + # Grab ran_a right now, before we converge + ran_a = r.ran_a + ruby_block "run b" do + block { r.ran_b "ran b: ran_a value was #{ran_a.inspect}" } + end + end + end + end + + it "resources declared in b are executed immediately inline" do + r = nil + expect_recipe do + r = lwrp_inline_resources_test2 "hi" do + action :b + end + end.to have_updated("lwrp_inline_resources_test2[hi]", :b). + and have_updated("ruby_block[run a]", :run). + and have_updated("ruby_block[run b]", :run) + expect(r.ran_b).to eq "ran b: ran_a value was \"ran a\"" + end + end + when_the_repository "has a cookbook with a nested LWRP" do before do - directory 'cookbooks/x' do + directory "cookbooks/x" do - file 'resources/do_nothing.rb', <<EOM -actions :create, :nothing -default_action :create -EOM - file 'providers/do_nothing.rb', <<EOM -action :create do -end -EOM + file "resources/do_nothing.rb", <<-EOM + actions :create, :nothing + default_action :create + EOM + file "providers/do_nothing.rb", <<-EOM + action :create do + end + EOM - file 'resources/my_machine.rb', <<EOM -actions :create, :nothing -default_action :create -EOM - file 'providers/my_machine.rb', <<EOM -use_inline_resources -action :create do - x_do_nothing 'a' - x_do_nothing 'b' -end -EOM + file "resources/my_machine.rb", <<-EOM + actions :create, :nothing + default_action :create + EOM + file "providers/my_machine.rb", <<-EOM + use_inline_resources + action :create do + x_do_nothing 'a' + x_do_nothing 'b' + end + EOM - file 'recipes/default.rb', <<EOM -x_my_machine "me" -x_my_machine "you" -EOM + file "recipes/default.rb", <<-EOM + x_my_machine "me" + x_my_machine "you" + EOM end # directory 'cookbooks/x' end it "should complete with success" do - file 'config/client.rb', <<EOM + file "config/client.rb", <<EOM local_mode true cookbook_path "#{path_to('cookbooks')}" log_level :warn diff --git a/spec/integration/recipes/lwrp_spec.rb b/spec/integration/recipes/lwrp_spec.rb index 7ecdfc7c3a..3bc008d4f8 100644 --- a/spec/integration/recipes/lwrp_spec.rb +++ b/spec/integration/recipes/lwrp_spec.rb @@ -1,5 +1,5 @@ -require 'support/shared/integration/integration_helper' -require 'chef/mixin/shell_out' +require "support/shared/integration/integration_helper" +require "chef/mixin/shell_out" describe "LWRPs" do include IntegrationSupport @@ -20,17 +20,17 @@ describe "LWRPs" do when_the_repository "has a cookbook named l-w-r-p" do before do - directory 'cookbooks/l-w-r-p' do + directory "cookbooks/l-w-r-p" do - file 'resources/foo.rb', <<EOM + file "resources/foo.rb", <<EOM default_action :create EOM - file 'providers/foo.rb', <<EOM + file "providers/foo.rb", <<EOM action :create do end EOM - file 'recipes/default.rb', <<EOM + file "recipes/default.rb", <<EOM l_w_r_p_foo "me" EOM @@ -38,7 +38,7 @@ EOM end it "should complete with success" do - file 'config/client.rb', <<EOM + file "config/client.rb", <<EOM local_mode true cookbook_path "#{path_to('cookbooks')}" log_level :warn diff --git a/spec/integration/recipes/noop_resource_spec.rb b/spec/integration/recipes/noop_resource_spec.rb new file mode 100644 index 0000000000..e0cf47c371 --- /dev/null +++ b/spec/integration/recipes/noop_resource_spec.rb @@ -0,0 +1,24 @@ +require "support/shared/integration/integration_helper" + +describe "Resources with a no-op provider" do + include IntegrationSupport + + context "with noop provider providing foo" do + before(:context) do + class NoOpFoo < Chef::Resource + resource_name "hi_there" + default_action :update + end + Chef::Provider::Noop.provides :hi_there + end + + it "does not blow up a run with a noop'd resource" do + recipe = converge do + hi_there "blah" do + action :update + end + end + expect(recipe.logged_warnings).to eq "" + end + end +end diff --git a/spec/integration/recipes/notifies_spec.rb b/spec/integration/recipes/notifies_spec.rb new file mode 100644 index 0000000000..000f5e37bf --- /dev/null +++ b/spec/integration/recipes/notifies_spec.rb @@ -0,0 +1,334 @@ +require "support/shared/integration/integration_helper" +require "chef/mixin/shell_out" + +describe "notifications" do + include IntegrationSupport + include Chef::Mixin::ShellOut + + let(:chef_dir) { File.expand_path("../../../../bin", __FILE__) } + let(:chef_client) { "ruby '#{chef_dir}/chef-client' --minimal-ohai" } + + when_the_repository "notifies delayed one" do + before do + directory "cookbooks/x" do + + file "resources/notifying_test.rb", <<EOM +default_action :run +provides :notifying_test +resource_name :notifying_test + +action :run do + log "bar" do + notifies :write, 'log[foo]', :delayed + end +end +EOM + + file "recipes/default.rb", <<EOM +log "foo" do + action :nothing +end +notifying_test "whatever" +log "baz" +EOM + + end + end + + it "should complete with success" do + file "config/client.rb", <<EOM +local_mode true +cookbook_path "#{path_to('cookbooks')}" +log_level :warn +EOM + + result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" --no-color -F doc -o 'x::default'", :cwd => chef_dir) + # our delayed notification should run at the end of the parent run_context after the baz resource + expect(result.stdout).to match(/\* log\[bar\] action write\s+\* log\[baz\] action write\s+\* log\[foo\] action write/) + result.error! + end + end + + when_the_repository "notifies delayed two" do + before do + directory "cookbooks/x" do + + file "resources/notifying_test.rb", <<EOM +default_action :run +provides :notifying_test +resource_name :notifying_test + +action :run do + log "bar" do + notifies :write, 'log[foo]', :delayed + end +end +EOM + + file "recipes/default.rb", <<EOM +log "foo" do + action :nothing +end +notifying_test "whatever" +log "baz" do + notifies :write, 'log[foo]', :delayed +end +EOM + + end + end + + it "should complete with success" do + file "config/client.rb", <<EOM +local_mode true +cookbook_path "#{path_to('cookbooks')}" +log_level :warn +EOM + + result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" --no-color -F doc -o 'x::default'", :cwd => chef_dir) + # our delayed notification should run at the end of the parent run_context after the baz resource + expect(result.stdout).to match(/\* log\[bar\] action write\s+\* log\[baz\] action write\s+\* log\[foo\] action write/) + # and only run once + expect(result.stdout).not_to match(/\* log\[foo\] action write.*\* log\[foo\] action write/) + result.error! + end + end + + when_the_repository "notifies delayed three" do + before do + directory "cookbooks/x" do + + file "resources/notifying_test.rb", <<EOM +default_action :run +provides :notifying_test +resource_name :notifying_test + +action :run do + log "bar" do + notifies :write, 'log[foo]', :delayed + end +end +EOM + + file "recipes/default.rb", <<EOM +log "foo" do + action :nothing +end +log "quux" do + notifies :write, 'log[foo]', :delayed + notifies :write, 'log[baz]', :delayed +end +notifying_test "whatever" +log "baz" +EOM + + end + end + + it "should complete with success" do + file "config/client.rb", <<EOM +local_mode true +cookbook_path "#{path_to('cookbooks')}" +log_level :warn +EOM + + result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" --no-color -F doc -o 'x::default'", :cwd => chef_dir) + # the delayed notification from the sub-resource is de-duplicated by the notification already in the parent run_context + expect(result.stdout).to match(/\* log\[quux\] action write\s+\* notifying_test\[whatever\] action run\s+\* log\[bar\] action write\s+\* log\[baz\] action write\s+\* log\[foo\] action write\s+\* log\[baz\] action write/) + # and only run once + expect(result.stdout).not_to match(/\* log\[foo\] action write.*\* log\[foo\] action write/) + result.error! + end + end + + when_the_repository "notifies delayed four" do + before do + directory "cookbooks/x" do + file "recipes/default.rb", <<EOM +log "foo" do + action :nothing +end +log "bar" do + notifies :write, 'log[foo]', :delayed +end +log "baz" do + notifies :write, 'log[foo]', :delayed +end +EOM + + end + end + + it "should complete with success" do + file "config/client.rb", <<EOM +local_mode true +cookbook_path "#{path_to('cookbooks')}" +log_level :warn +EOM + + result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" --no-color -F doc -o 'x::default'", :cwd => chef_dir) + # the delayed notification from the sub-resource is de-duplicated by the notification already in the parent run_context + expect(result.stdout).to match(/\* log\[bar\] action write\s+\* log\[baz\] action write\s+\* log\[foo\] action write/) + # and only run once + expect(result.stdout).not_to match(/\* log\[foo\] action write.*\* log\[foo\] action write/) + result.error! + end + end + + when_the_repository "notifies immediately" do + before do + directory "cookbooks/x" do + + file "resources/notifying_test.rb", <<EOM +default_action :run +provides :notifying_test +resource_name :notifying_test + +action :run do + log "bar" do + notifies :write, 'log[foo]', :immediately + end +end +EOM + + file "recipes/default.rb", <<EOM +log "foo" do + action :nothing +end +notifying_test "whatever" +log "baz" +EOM + + end + end + + it "should complete with success" do + file "config/client.rb", <<EOM +local_mode true +cookbook_path "#{path_to('cookbooks')}" +log_level :warn +EOM + + result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" --no-color -F doc -o 'x::default'", :cwd => chef_dir) + expect(result.stdout).to match(/\* log\[bar\] action write\s+\* log\[foo\] action write\s+\* log\[baz\] action write/) + result.error! + end + end + + when_the_repository "uses old notifies syntax" do + before do + directory "cookbooks/x" do + + file "resources/notifying_test.rb", <<EOM +default_action :run +provides :notifying_test +resource_name :notifying_test + +action :run do + log "bar" do + notifies :write, resources(log: "foo"), :immediately + end +end +EOM + + file "recipes/default.rb", <<EOM +log "foo" do + action :nothing +end +notifying_test "whatever" +log "baz" +EOM + + end + end + + it "should complete with success" do + file "config/client.rb", <<EOM +local_mode true +cookbook_path "#{path_to('cookbooks')}" +log_level :warn +EOM + + result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" --no-color -F doc -o 'x::default'", :cwd => chef_dir) + expect(result.stdout).to match(/\* log\[bar\] action write\s+\* log\[foo\] action write\s+\* log\[baz\] action write/) + result.error! + end + end + + when_the_repository "does not have a matching resource" do + before do + directory "cookbooks/x" do + + file "resources/notifying_test.rb", <<EOM +default_action :run +provides :notifying_test +resource_name :notifying_test + +action :run do + log "bar" do + notifies :write, "log[foo]" + end +end +EOM + + file "recipes/default.rb", <<EOM +notifying_test "whatever" +log "baz" +EOM + + end + end + + it "should complete with success" do + file "config/client.rb", <<EOM +local_mode true +cookbook_path "#{path_to('cookbooks')}" +log_level :warn +EOM + + result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" --no-color -F doc -o 'x::default'", :cwd => chef_dir) + expect(result.stdout).to match(/Chef::Exceptions::ResourceNotFound/) + expect(result.exitstatus).not_to eql(0) + end + end + + when_the_repository "encounters identical resources in parent and child resource collections" do + before do + directory "cookbooks/x" do + + file "resources/cloning_test.rb", <<EOM +default_action :run +provides :cloning_test +resource_name :cloning_test + +action :run do + log "bar" do + level :info + end +end +EOM + + file "recipes/default.rb", <<EOM +log "bar" do + level :warn +end + +cloning_test "whatever" +EOM + + end + end + + it "should complete with success" do + file "config/client.rb", <<EOM +local_mode true +cookbook_path "#{path_to('cookbooks')}" +log_level :warn +EOM + + result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" --no-color -F doc -o 'x::default'", :cwd => chef_dir) + expect(result.stdout).not_to match(/CHEF-3694/) + result.error! + end + end +end diff --git a/spec/integration/recipes/notifying_block_spec.rb b/spec/integration/recipes/notifying_block_spec.rb new file mode 100644 index 0000000000..6a1287c7b1 --- /dev/null +++ b/spec/integration/recipes/notifying_block_spec.rb @@ -0,0 +1,111 @@ +# +# Author:: John Keiser (<jkeiser@chef.io>) +# Copyright:: Copyright 2013-2016, Chef Software 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 "chef/mixin/shell_out" + +describe "notifying_block" do + include IntegrationSupport + include Chef::Mixin::ShellOut + + let(:chef_dir) { File.expand_path("../../../../bin", __FILE__) } + let(:chef_client) { "ruby '#{chef_dir}/chef-client' --minimal-ohai" } + + when_the_repository "notifying_block test one" do + before do + directory "cookbooks/x" do + file "recipes/default.rb", <<-EOM + notifying_block do + log "gamma" do + action :nothing + end + log "alpha" do + notifies :write, "log[gamma]", :delayed + end + log "beta" do + notifies :write, "log[gamma]", :delayed + end + end + log "delta" + EOM + end + file "config/client.rb", <<-EOM + local_mode true + cookbook_path "#{path_to('cookbooks')}" + log_level :warn + EOM + end + + # implicitly tests - + # 1. notifying block opens up a subcontext + # 2. delayed notifications are de-dup'd in the subcontext + # 3. delayed notifications (to resources inside the subcontext) are run at the end of the subcontext + it "should run alpha, beta, gamma, and delta in that order" do + result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" --no-color -F doc -o 'x::default'", :cwd => chef_dir) + expect(result.stdout).to match(/\* log\[alpha\] action write\s+\* log\[beta\] action write\s+\* log\[gamma\] action write\s+Converging 1 resources\s+\* log\[delta\] action write/) + result.error! + end + end + + when_the_repository "notifying_block test two" do + before do + directory "cookbooks/x" do + file "resources/nb_test.rb", <<-EOM + default_action :run + provides :nb_test + resource_name :nb_test + + action :run do + notifying_block do + log "foo" do + notifies :write, 'log[bar]', :delayed + end + end + end + EOM + file "recipes/default.rb", <<-EOM + log "bar" do + action :nothing + end + log "baz" do + action :nothing + end + + nb_test "testing" do + notifies :write, 'log[baz]', :delayed + end + + log "quux" + EOM + end + file "config/client.rb", <<-EOM + local_mode true + cookbook_path "#{path_to('cookbooks')}" + log_level :warn + EOM + end + + # implicitly tests - + # 1. notifying block will correctly update wrapping new_resource updated_by_last_action status + # 2. delayed notifications from a subcontext inside a resource will notify resources in their outer run_context + it "should run foo, quux, bar, and baz in that order" do + result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" --no-color -F doc -o 'x::default'", :cwd => chef_dir) + expect(result.stdout).to match(/\* log\[foo\] action write\s+\* log\[quux\] action write\s+\* log\[bar\] action write\s+\* log\[baz\] action write/) + result.error! + end + end +end diff --git a/spec/integration/recipes/provider_choice.rb b/spec/integration/recipes/provider_choice.rb index 01537b2c05..1895d93891 100644 --- a/spec/integration/recipes/provider_choice.rb +++ b/spec/integration/recipes/provider_choice.rb @@ -1,4 +1,4 @@ -require 'support/shared/integration/integration_helper' +require "support/shared/integration/integration_helper" describe "Recipe DSL methods" do include IntegrationSupport @@ -18,6 +18,7 @@ describe "Recipe DSL methods" do class Chef::Provider::ProviderThingy < Chef::Provider def load_current_resource end + def action_create Chef::Log.warn("hello from #{self.class.name}") end @@ -25,9 +26,9 @@ describe "Recipe DSL methods" do end it "provider_thingy 'blah' runs the provider and warns" do - recipe = converge { - provider_thingy 'blah' do; end - } + recipe = converge do + provider_thingy("blah") {} + end expect(recipe.logged_warnings).to match /hello from Chef::Provider::ProviderThingy/ expect(recipe.logged_warnings).to match /you must use 'provides' to provide DSL/i end diff --git a/spec/integration/recipes/recipe_dsl_spec.rb b/spec/integration/recipes/recipe_dsl_spec.rb index 52bca87c99..e2fa7df1fc 100644 --- a/spec/integration/recipes/recipe_dsl_spec.rb +++ b/spec/integration/recipes/recipe_dsl_spec.rb @@ -1,4 +1,4 @@ -require 'support/shared/integration/integration_helper' +require "support/shared/integration/integration_helper" describe "Recipe DSL methods" do include IntegrationSupport @@ -12,10 +12,10 @@ describe "Recipe DSL methods" do before { Namer.current_index += 1 } context "with resource 'base_thingy' declared as BaseThingy" do - before(:context) { + before(:context) do class BaseThingy < Chef::Resource - resource_name 'base_thingy' + resource_name "base_thingy" default_action :create class<<self @@ -30,6 +30,7 @@ describe "Recipe DSL methods" do class Provider < Chef::Provider def load_current_resource end + def action_create BaseThingy.created_name = new_resource.name BaseThingy.created_resource = new_resource.class @@ -42,7 +43,7 @@ describe "Recipe DSL methods" do module RecipeDSLSpecNamespace; end module RecipeDSLSpecNamespace::Bar; end - } + end before :each do BaseThingy.created_resource = nil @@ -50,28 +51,28 @@ describe "Recipe DSL methods" do end it "creates base_thingy when you call base_thingy in a recipe" do - recipe = converge { - base_thingy 'blah' do; end - } - expect(recipe.logged_warnings).to eq '' - expect(BaseThingy.created_name).to eq 'blah' + recipe = converge do + base_thingy("blah") {} + end + expect(recipe.logged_warnings).to eq "" + expect(BaseThingy.created_name).to eq "blah" expect(BaseThingy.created_resource).to eq BaseThingy end it "errors out when you call base_thingy do ... end in a recipe" do - expect_converge { - base_thingy do; end - }.to raise_error(ArgumentError, 'You must supply a name when declaring a base_thingy resource') + expect_converge do + base_thingy { ; } + end.to raise_error(ArgumentError, "You must supply a name when declaring a base_thingy resource") end it "emits a warning when you call base_thingy 'foo', 'bar' do ... end in a recipe" do Chef::Config[:treat_deprecation_warnings_as_errors] = false - recipe = converge { - base_thingy 'foo', 'bar' do + recipe = converge do + base_thingy "foo", "bar" do end - } + end expect(recipe.logged_warnings).to match(/Cannot create resource base_thingy with more than one argument. All arguments except the name \("foo"\) will be ignored. This will cause an error in Chef 13. Arguments: \["foo", "bar"\]/) - expect(BaseThingy.created_name).to eq 'foo' + expect(BaseThingy.created_name).to eq "foo" expect(BaseThingy.created_resource).to eq BaseThingy end @@ -81,7 +82,7 @@ describe "Recipe DSL methods" do end context "with a resource 'backcompat_thingy' declared in Chef::Resource and Chef::Provider" do - before(:context) { + before(:context) do class Chef::Resource::BackcompatThingy < Chef::Resource default_action :create @@ -89,36 +90,37 @@ describe "Recipe DSL methods" do class Chef::Provider::BackcompatThingy < Chef::Provider def load_current_resource end + def action_create BaseThingy.created_resource = new_resource.class BaseThingy.created_provider = self.class end end - } + end it "backcompat_thingy creates a Chef::Resource::BackcompatThingy" do - recipe = converge { - backcompat_thingy 'blah' do; end - } + recipe = converge do + backcompat_thingy("blah") {} + end expect(BaseThingy.created_resource).to eq Chef::Resource::BackcompatThingy expect(BaseThingy.created_provider).to eq Chef::Provider::BackcompatThingy end context "and another resource 'backcompat_thingy' in BackcompatThingy with 'provides'" do - before(:context) { + before(:context) do class RecipeDSLSpecNamespace::BackcompatThingy < BaseThingy provides :backcompat_thingy resource_name :backcompat_thingy end - } + end it "backcompat_thingy creates a BackcompatThingy" do - recipe = converge { - backcompat_thingy 'blah' do; end - } + recipe = converge do + backcompat_thingy("blah") {} + end expect(recipe.logged_warnings).to match(/Class Chef::Provider::BackcompatThingy does not declare 'provides :backcompat_thingy'./) expect(BaseThingy.created_resource).not_to be_nil end @@ -126,307 +128,307 @@ describe "Recipe DSL methods" do end context "with a resource named RecipeDSLSpecNamespace::Bar::BarThingy" do - before(:context) { + before(:context) do class RecipeDSLSpecNamespace::Bar::BarThingy < BaseThingy end - } + end it "bar_thingy does not work" do - expect_converge { - bar_thingy 'blah' do; end - }.to raise_error(NoMethodError) + expect_converge do + bar_thingy("blah") {} + end.to raise_error(NoMethodError) end end context "with a resource named Chef::Resource::NoNameThingy with resource_name nil" do - before(:context) { + before(:context) do class Chef::Resource::NoNameThingy < BaseThingy resource_name nil end - } + end it "no_name_thingy does not work" do - expect_converge { - no_name_thingy 'blah' do; end - }.to raise_error(NoMethodError) + expect_converge do + no_name_thingy("blah") {} + end.to raise_error(NoMethodError) end end context "with a resource named AnotherNoNameThingy with resource_name :another_thingy_name" do - before(:context) { + before(:context) do class AnotherNoNameThingy < BaseThingy resource_name :another_thingy_name end - } + end it "another_no_name_thingy does not work" do - expect_converge { - another_no_name_thingy 'blah' do; end - }.to raise_error(NoMethodError) + expect_converge do + another_no_name_thingy("blah") {} + end.to raise_error(NoMethodError) end it "another_thingy_name works" do - recipe = converge { - another_thingy_name 'blah' do; end - } - expect(recipe.logged_warnings).to eq '' + recipe = converge do + another_thingy_name("blah") {} + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq(AnotherNoNameThingy) end end context "with a resource named AnotherNoNameThingy2 with resource_name :another_thingy_name2; resource_name :another_thingy_name3" do - before(:context) { + before(:context) do class AnotherNoNameThingy2 < BaseThingy resource_name :another_thingy_name2 resource_name :another_thingy_name3 end - } + end it "another_no_name_thingy does not work" do - expect_converge { - another_no_name_thingy2 'blah' do; end - }.to raise_error(NoMethodError) + expect_converge do + another_no_name_thingy2("blah") {} + end.to raise_error(NoMethodError) end it "another_thingy_name2 does not work" do - expect_converge { - another_thingy_name2 'blah' do; end - }.to raise_error(NoMethodError) + expect_converge do + another_thingy_name2("blah") {} + end.to raise_error(NoMethodError) end it "yet_another_thingy_name3 works" do - recipe = converge { - another_thingy_name3 'blah' do; end - } - expect(recipe.logged_warnings).to eq '' + recipe = converge do + another_thingy_name3("blah") {} + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq(AnotherNoNameThingy2) end end context "provides overriding resource_name" do context "with a resource named AnotherNoNameThingy3 with provides :another_no_name_thingy3, os: 'blarghle'" do - before(:context) { + before(:context) do class AnotherNoNameThingy3 < BaseThingy resource_name :another_no_name_thingy_3 - provides :another_no_name_thingy3, os: 'blarghle' + provides :another_no_name_thingy3, os: "blarghle" end - } + end it "and os = linux, another_no_name_thingy3 does not work" do - expect_converge { + expect_converge do # TODO this is an ugly way to test, make Cheffish expose node attrs - run_context.node.automatic[:os] = 'linux' - another_no_name_thingy3 'blah' do; end - }.to raise_error(Chef::Exceptions::NoSuchResourceType) + run_context.node.automatic[:os] = "linux" + another_no_name_thingy3("blah") {} + end.to raise_error(Chef::Exceptions::NoSuchResourceType) end it "and os = blarghle, another_no_name_thingy3 works" do - recipe = converge { + recipe = converge do # TODO this is an ugly way to test, make Cheffish expose node attrs - run_context.node.automatic[:os] = 'blarghle' - another_no_name_thingy3 'blah' do; end - } - expect(recipe.logged_warnings).to eq '' + run_context.node.automatic[:os] = "blarghle" + another_no_name_thingy3("blah") {} + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy3) end end context "with a resource named AnotherNoNameThingy4 with two provides" do - before(:context) { + before(:context) do class AnotherNoNameThingy4 < BaseThingy resource_name :another_no_name_thingy_4 - provides :another_no_name_thingy4, os: 'blarghle' - provides :another_no_name_thingy4, platform_family: 'foo' + provides :another_no_name_thingy4, os: "blarghle" + provides :another_no_name_thingy4, platform_family: "foo" end - } + end it "and os = linux, another_no_name_thingy4 does not work" do - expect_converge { + expect_converge do # TODO this is an ugly way to test, make Cheffish expose node attrs - run_context.node.automatic[:os] = 'linux' - another_no_name_thingy4 'blah' do; end - }.to raise_error(Chef::Exceptions::NoSuchResourceType) + run_context.node.automatic[:os] = "linux" + another_no_name_thingy4("blah") {} + end.to raise_error(Chef::Exceptions::NoSuchResourceType) end it "and os = blarghle, another_no_name_thingy4 works" do - recipe = converge { + recipe = converge do # TODO this is an ugly way to test, make Cheffish expose node attrs - run_context.node.automatic[:os] = 'blarghle' - another_no_name_thingy4 'blah' do; end - } - expect(recipe.logged_warnings).to eq '' + run_context.node.automatic[:os] = "blarghle" + another_no_name_thingy4("blah") {} + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy4) end it "and platform_family = foo, another_no_name_thingy4 works" do - recipe = converge { + recipe = converge do # TODO this is an ugly way to test, make Cheffish expose node attrs - run_context.node.automatic[:platform_family] = 'foo' - another_no_name_thingy4 'blah' do; end - } - expect(recipe.logged_warnings).to eq '' + run_context.node.automatic[:platform_family] = "foo" + another_no_name_thingy4("blah") {} + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy4) end end context "with a resource named AnotherNoNameThingy5, a different resource_name, and a provides with the original resource_name" do - before(:context) { + before(:context) do class AnotherNoNameThingy5 < BaseThingy resource_name :another_thingy_name_for_another_no_name_thingy5 - provides :another_no_name_thingy5, os: 'blarghle' + provides :another_no_name_thingy5, os: "blarghle" end - } + end it "and os = linux, another_no_name_thingy5 does not work" do - expect_converge { + expect_converge do # this is an ugly way to test, make Cheffish expose node attrs - run_context.node.automatic[:os] = 'linux' - another_no_name_thingy5 'blah' do; end - }.to raise_error(Chef::Exceptions::NoSuchResourceType) + run_context.node.automatic[:os] = "linux" + another_no_name_thingy5("blah") {} + end.to raise_error(Chef::Exceptions::NoSuchResourceType) end it "and os = blarghle, another_no_name_thingy5 works" do - recipe = converge { + recipe = converge do # this is an ugly way to test, make Cheffish expose node attrs - run_context.node.automatic[:os] = 'blarghle' - another_no_name_thingy5 'blah' do; end - } - expect(recipe.logged_warnings).to eq '' + run_context.node.automatic[:os] = "blarghle" + another_no_name_thingy5("blah") {} + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy5) end it "the new resource name can be used in a recipe" do - recipe = converge { - another_thingy_name_for_another_no_name_thingy5 'blah' do; end - } - expect(recipe.logged_warnings).to eq '' + recipe = converge do + another_thingy_name_for_another_no_name_thingy5("blah") {} + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy5) end end context "with a resource named AnotherNoNameThingy6, a provides with the original resource name, and a different resource_name" do - before(:context) { + before(:context) do class AnotherNoNameThingy6 < BaseThingy - provides :another_no_name_thingy6, os: 'blarghle' + provides :another_no_name_thingy6, os: "blarghle" resource_name :another_thingy_name_for_another_no_name_thingy6 end - } + end it "and os = linux, another_no_name_thingy6 does not work" do - expect_converge { + expect_converge do # this is an ugly way to test, make Cheffish expose node attrs - run_context.node.automatic[:os] = 'linux' - another_no_name_thingy6 'blah' do; end - }.to raise_error(Chef::Exceptions::NoSuchResourceType) + run_context.node.automatic[:os] = "linux" + another_no_name_thingy6("blah") {} + end.to raise_error(Chef::Exceptions::NoSuchResourceType) end it "and os = blarghle, another_no_name_thingy6 works" do - recipe = converge { + recipe = converge do # this is an ugly way to test, make Cheffish expose node attrs - run_context.node.automatic[:os] = 'blarghle' - another_no_name_thingy6 'blah' do; end - } - expect(recipe.logged_warnings).to eq '' + run_context.node.automatic[:os] = "blarghle" + another_no_name_thingy6("blah") {} + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy6) end it "the new resource name can be used in a recipe" do - recipe = converge { - another_thingy_name_for_another_no_name_thingy6 'blah' do; end - } - expect(recipe.logged_warnings).to eq '' + recipe = converge do + another_thingy_name_for_another_no_name_thingy6("blah") {} + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy6) end end context "with a resource named AnotherNoNameThingy7, a new resource_name, and provides with that new resource name" do - before(:context) { + before(:context) do class AnotherNoNameThingy7 < BaseThingy resource_name :another_thingy_name_for_another_no_name_thingy7 - provides :another_thingy_name_for_another_no_name_thingy7, os: 'blarghle' + provides :another_thingy_name_for_another_no_name_thingy7, os: "blarghle" end - } + end it "and os = linux, another_thingy_name_for_another_no_name_thingy7 does not work" do - expect_converge { + expect_converge do # this is an ugly way to test, make Cheffish expose node attrs - run_context.node.automatic[:os] = 'linux' - another_thingy_name_for_another_no_name_thingy7 'blah' do; end - }.to raise_error(Chef::Exceptions::NoSuchResourceType) + run_context.node.automatic[:os] = "linux" + another_thingy_name_for_another_no_name_thingy7("blah") {} + end.to raise_error(Chef::Exceptions::NoSuchResourceType) end it "and os = blarghle, another_thingy_name_for_another_no_name_thingy7 works" do - recipe = converge { + recipe = converge do # this is an ugly way to test, make Cheffish expose node attrs - run_context.node.automatic[:os] = 'blarghle' - another_thingy_name_for_another_no_name_thingy7 'blah' do; end - } - expect(recipe.logged_warnings).to eq '' + run_context.node.automatic[:os] = "blarghle" + another_thingy_name_for_another_no_name_thingy7("blah") {} + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy7) end it "the old resource name does not work" do - expect_converge { + expect_converge do # this is an ugly way to test, make Cheffish expose node attrs - run_context.node.automatic[:os] = 'linux' - another_no_name_thingy_7 'blah' do; end - }.to raise_error(NoMethodError) + run_context.node.automatic[:os] = "linux" + another_no_name_thingy_7("blah") {} + end.to raise_error(NoMethodError) end end # opposite order from the previous test (provides, then resource_name) context "with a resource named AnotherNoNameThingy8, a provides with a new resource name, and resource_name with that new resource name" do - before(:context) { + before(:context) do class AnotherNoNameThingy8 < BaseThingy - provides :another_thingy_name_for_another_no_name_thingy8, os: 'blarghle' + provides :another_thingy_name_for_another_no_name_thingy8, os: "blarghle" resource_name :another_thingy_name_for_another_no_name_thingy8 end - } + end it "and os = linux, another_thingy_name_for_another_no_name_thingy8 does not work" do - expect_converge { + expect_converge do # this is an ugly way to test, make Cheffish expose node attrs - run_context.node.automatic[:os] = 'linux' - another_thingy_name_for_another_no_name_thingy8 'blah' do; end - }.to raise_error(Chef::Exceptions::NoSuchResourceType) + run_context.node.automatic[:os] = "linux" + another_thingy_name_for_another_no_name_thingy8("blah") {} + end.to raise_error(Chef::Exceptions::NoSuchResourceType) end it "and os = blarghle, another_thingy_name_for_another_no_name_thingy8 works" do - recipe = converge { + recipe = converge do # this is an ugly way to test, make Cheffish expose node attrs - run_context.node.automatic[:os] = 'blarghle' - another_thingy_name_for_another_no_name_thingy8 'blah' do; end - } - expect(recipe.logged_warnings).to eq '' + run_context.node.automatic[:os] = "blarghle" + another_thingy_name_for_another_no_name_thingy8("blah") {} + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy8) end it "the old resource name does not work" do - expect_converge { + expect_converge do # this is an ugly way to test, make Cheffish expose node attrs - run_context.node.automatic[:os] = 'linux' - another_thingy_name8 'blah' do; end - }.to raise_error(NoMethodError) + run_context.node.automatic[:os] = "linux" + another_thingy_name8("blah") {} + end.to raise_error(NoMethodError) end end end @@ -434,64 +436,64 @@ describe "Recipe DSL methods" do context "provides" do context "when MySupplier provides :hemlock" do - before(:context) { + before(:context) do class RecipeDSLSpecNamespace::MySupplier < BaseThingy resource_name :hemlock end - } + end it "my_supplier does not work in a recipe" do - expect_converge { - my_supplier 'blah' do; end - }.to raise_error(NoMethodError) + expect_converge do + my_supplier("blah") {} + end.to raise_error(NoMethodError) end it "hemlock works in a recipe" do - expect_recipe { - hemlock 'blah' do; end - }.to emit_no_warnings_or_errors + expect_recipe do + hemlock("blah") {} + end.to emit_no_warnings_or_errors expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::MySupplier end end context "when Thingy3 has resource_name :thingy3" do - before(:context) { + before(:context) do class RecipeDSLSpecNamespace::Thingy3 < BaseThingy resource_name :thingy3 end - } + end it "thingy3 works in a recipe" do - expect_recipe { - thingy3 'blah' do; end - }.to emit_no_warnings_or_errors + expect_recipe do + thingy3("blah") {} + end.to emit_no_warnings_or_errors expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy3 end context "and Thingy4 has resource_name :thingy3" do - before(:context) { + before(:context) do class RecipeDSLSpecNamespace::Thingy4 < BaseThingy resource_name :thingy3 end - } + end it "thingy3 works in a recipe and yields Thingy3 (the alphabetical one)" do - recipe = converge { - thingy3 'blah' do; end - } + recipe = converge do + thingy3("blah") {} + end expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy3 end it "thingy4 does not work in a recipe" do - expect_converge { - thingy4 'blah' do; end - }.to raise_error(NoMethodError) + expect_converge do + thingy4("blah") {} + end.to raise_error(NoMethodError) end it "resource_matching_short_name returns Thingy4" do @@ -501,7 +503,7 @@ describe "Recipe DSL methods" do end context "when Thingy5 has resource_name :thingy5 and provides :thingy5reverse, :thingy5_2 and :thingy5_2reverse" do - before(:context) { + before(:context) do class RecipeDSLSpecNamespace::Thingy5 < BaseThingy resource_name :thingy5 @@ -510,36 +512,36 @@ describe "Recipe DSL methods" do provides :thingy5_2reverse end - } + end it "thingy5 works in a recipe" do - expect_recipe { - thingy5 'blah' do; end - }.to emit_no_warnings_or_errors + expect_recipe do + thingy5("blah") {} + end.to emit_no_warnings_or_errors expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy5 end context "and Thingy6 provides :thingy5" do - before(:context) { + before(:context) do class RecipeDSLSpecNamespace::Thingy6 < BaseThingy resource_name :thingy6 provides :thingy5 end - } + end it "thingy6 works in a recipe and yields Thingy6" do - recipe = converge { - thingy6 'blah' do; end - } + recipe = converge do + thingy6("blah") {} + end expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy6 end it "thingy5 works in a recipe and yields Foo::Thingy5 (the alphabetical one)" do - recipe = converge { - thingy5 'blah' do; end - } + recipe = converge do + thingy5("blah") {} + end expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy5 end @@ -548,24 +550,24 @@ describe "Recipe DSL methods" do end context "and AThingy5 provides :thingy5reverse" do - before(:context) { + before(:context) do class RecipeDSLSpecNamespace::AThingy5 < BaseThingy resource_name :thingy5reverse end - } + end it "thingy5reverse works in a recipe and yields AThingy5 (the alphabetical one)" do - recipe = converge { - thingy5reverse 'blah' do; end - } + recipe = converge do + thingy5reverse("blah") {} + end expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::AThingy5 end end context "and ZRecipeDSLSpecNamespace::Thingy5 provides :thingy5_2" do - before(:context) { + before(:context) do module ZRecipeDSLSpecNamespace class Thingy5 < BaseThingy @@ -573,18 +575,18 @@ describe "Recipe DSL methods" do end end - } + end it "thingy5_2 works in a recipe and yields the RecipeDSLSpaceNamespace one (the alphabetical one)" do - recipe = converge { - thingy5_2 'blah' do; end - } + recipe = converge do + thingy5_2("blah") {} + end expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy5 end end context "and ARecipeDSLSpecNamespace::Thingy5 provides :thingy5_2" do - before(:context) { + before(:context) do module ARecipeDSLSpecNamespace class Thingy5 < BaseThingy @@ -592,53 +594,53 @@ describe "Recipe DSL methods" do end end - } + end it "thingy5_2reverse works in a recipe and yields the ARecipeDSLSpaceNamespace one (the alphabetical one)" do - recipe = converge { - thingy5_2reverse 'blah' do; end - } + recipe = converge do + thingy5_2reverse("blah") {} + end expect(BaseThingy.created_resource).to eq ARecipeDSLSpecNamespace::Thingy5 end end end context "when Thingy3 has resource_name :thingy3" do - before(:context) { + before(:context) do class RecipeDSLSpecNamespace::Thingy3 < BaseThingy resource_name :thingy3 end - } + end it "thingy3 works in a recipe" do - expect_recipe { - thingy3 'blah' do; end - }.to emit_no_warnings_or_errors + expect_recipe do + thingy3("blah") {} + end.to emit_no_warnings_or_errors expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy3 end context "and Thingy4 has resource_name :thingy3" do - before(:context) { + before(:context) do class RecipeDSLSpecNamespace::Thingy4 < BaseThingy resource_name :thingy3 end - } + end it "thingy3 works in a recipe and yields Thingy3 (the alphabetical one)" do - recipe = converge { - thingy3 'blah' do; end - } + recipe = converge do + thingy3("blah") {} + end expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy3 end it "thingy4 does not work in a recipe" do - expect_converge { - thingy4 'blah' do; end - }.to raise_error(NoMethodError) + expect_converge do + thingy4("blah") {} + end.to raise_error(NoMethodError) end it "resource_matching_short_name returns Thingy4" do @@ -647,25 +649,25 @@ describe "Recipe DSL methods" do end context "and Thingy4 has resource_name :thingy3" do - before(:context) { + before(:context) do class RecipeDSLSpecNamespace::Thingy4 < BaseThingy resource_name :thingy3 end - } + end it "thingy3 works in a recipe and yields Thingy3 (the alphabetical one)" do - recipe = converge { - thingy3 'blah' do; end - } + recipe = converge do + thingy3("blah") {} + end expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy3 end it "thingy4 does not work in a recipe" do - expect_converge { - thingy4 'blah' do; end - }.to raise_error(NoMethodError) + expect_converge do + thingy4("blah") {} + end.to raise_error(NoMethodError) end it "resource_matching_short_name returns Thingy4" do @@ -677,35 +679,35 @@ describe "Recipe DSL methods" do end context "when Thingy7 provides :thingy8" do - before(:context) { + before(:context) do class RecipeDSLSpecNamespace::Thingy7 < BaseThingy resource_name :thingy7 provides :thingy8 end - } + end context "and Thingy8 has resource_name :thingy8" do - before(:context) { + before(:context) do class RecipeDSLSpecNamespace::Thingy8 < BaseThingy resource_name :thingy8 end - } + end it "thingy7 works in a recipe and yields Thingy7" do - recipe = converge { - thingy7 'blah' do; end - } + recipe = converge do + thingy7("blah") {} + end expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy7 end it "thingy8 works in a recipe and yields Thingy7 (alphabetical)" do - recipe = converge { - thingy8 'blah' do; end - } + recipe = converge do + thingy8("blah") {} + end expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy7 end @@ -716,7 +718,7 @@ describe "Recipe DSL methods" do end context "when Thingy12 provides :thingy12, :twizzle and :twizzle2" do - before(:context) { + before(:context) do class RecipeDSLSpecNamespace::Thingy12 < BaseThingy resource_name :thingy12 @@ -724,49 +726,49 @@ describe "Recipe DSL methods" do provides :twizzle2 end - } + end it "thingy12 works in a recipe and yields Thingy12" do - expect_recipe { - thingy12 'blah' do; end - }.to emit_no_warnings_or_errors + expect_recipe do + thingy12("blah") {} + end.to emit_no_warnings_or_errors expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy12 end it "twizzle works in a recipe and yields Thingy12" do - expect_recipe { - twizzle 'blah' do; end - }.to emit_no_warnings_or_errors + expect_recipe do + twizzle("blah") {} + end.to emit_no_warnings_or_errors expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy12 end it "twizzle2 works in a recipe and yields Thingy12" do - expect_recipe { - twizzle2 'blah' do; end - }.to emit_no_warnings_or_errors + expect_recipe do + twizzle2("blah") {} + end.to emit_no_warnings_or_errors expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy12 end end context "with platform-specific resources 'my_super_thingy_foo' and 'my_super_thingy_bar'" do - before(:context) { + before(:context) do class MySuperThingyFoo < BaseThingy resource_name :my_super_thingy_foo - provides :my_super_thingy, platform: 'foo' + provides :my_super_thingy, platform: "foo" end class MySuperThingyBar < BaseThingy resource_name :my_super_thingy_bar - provides :my_super_thingy, platform: 'bar' + provides :my_super_thingy, platform: "bar" end - } + end it "A run with platform 'foo' uses MySuperThingyFoo" do r = Cheffish::ChefRun.new(chef_config) - r.client.run_context.node.automatic['platform'] = 'foo' - r.compile_recipe { - my_super_thingy 'blah' do; end - } + r.client.run_context.node.automatic["platform"] = "foo" + r.compile_recipe do + my_super_thingy("blah") {} + end r.converge expect(r).to emit_no_warnings_or_errors expect(BaseThingy.created_resource).to eq MySuperThingyFoo @@ -774,10 +776,10 @@ describe "Recipe DSL methods" do it "A run with platform 'bar' uses MySuperThingyBar" do r = Cheffish::ChefRun.new(chef_config) - r.client.run_context.node.automatic['platform'] = 'bar' - r.compile_recipe { - my_super_thingy 'blah' do; end - } + r.client.run_context.node.automatic["platform"] = "bar" + r.compile_recipe do + my_super_thingy("blah") {} + end r.converge expect(r).to emit_no_warnings_or_errors expect(BaseThingy.created_resource).to eq MySuperThingyBar @@ -785,21 +787,21 @@ describe "Recipe DSL methods" do it "A run with platform 'x' reports that my_super_thingy is not supported" do r = Cheffish::ChefRun.new(chef_config) - r.client.run_context.node.automatic['platform'] = 'x' - expect { - r.compile_recipe { - my_super_thingy 'blah' do; end - } - }.to raise_error(Chef::Exceptions::NoSuchResourceType) + r.client.run_context.node.automatic["platform"] = "x" + expect do + r.compile_recipe do + my_super_thingy("blah") {} + end + end.to raise_error(Chef::Exceptions::NoSuchResourceType) end end context "when Thingy10 provides :thingy10" do - before(:context) { + before(:context) do class RecipeDSLSpecNamespace::Thingy10 < BaseThingy resource_name :thingy10 end - } + end it "declaring a resource providing the same :thingy10 with override: true does not produce a warning" do expect(Chef::Log).not_to receive(:warn) @@ -810,16 +812,16 @@ describe "Recipe DSL methods" do end context "when Thingy11 provides :thingy11" do - before(:context) { + before(:context) do class RecipeDSLSpecNamespace::Thingy11 < BaseThingy resource_name :thingy10 end - } + end it "declaring a resource providing the same :thingy11 with os: 'linux' does not produce a warning" do expect(Chef::Log).not_to receive(:warn) class RecipeDSLSpecNamespace::Thingy11AlternateProvider < BaseThingy - provides :thingy11, os: 'linux' + provides :thingy11, os: "linux" end end end @@ -827,39 +829,43 @@ describe "Recipe DSL methods" do context "with a resource named 'B' with resource name :two_classes_one_dsl" do let(:two_classes_one_dsl) { :"two_classes_one_dsl#{Namer.current_index}" } - let(:resource_class) { + let(:resource_class) do result = Class.new(BaseThingy) do def self.name "B" end + def self.to_s; name; end + def self.inspect; name.inspect; end end result.resource_name two_classes_one_dsl result - } + end before { resource_class } # pull on it so it gets defined before the recipe runs context "and another resource named 'A' with resource_name :two_classes_one_dsl" do - let(:resource_class_a) { + let(:resource_class_a) do result = Class.new(BaseThingy) do def self.name "A" end + def self.to_s; name; end + def self.inspect; name.inspect; end end result.resource_name two_classes_one_dsl result - } + end before { resource_class_a } # pull on it so it gets defined before the recipe runs it "two_classes_one_dsl resolves to A (alphabetically earliest)" do - two_classes_one_dsl = self.two_classes_one_dsl - recipe = converge { - instance_eval("#{two_classes_one_dsl} 'blah'") - } - expect(recipe.logged_warnings).to eq '' + temp_two_classes_one_dsl = two_classes_one_dsl + recipe = converge do + instance_eval("#{temp_two_classes_one_dsl} 'blah'") + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq resource_class_a end @@ -869,25 +875,27 @@ describe "Recipe DSL methods" do end context "and another resource named 'Z' with resource_name :two_classes_one_dsl" do - let(:resource_class_z) { + let(:resource_class_z) do result = Class.new(BaseThingy) do def self.name "Z" end + def self.to_s; name; end + def self.inspect; name.inspect; end end result.resource_name two_classes_one_dsl result - } + end before { resource_class_z } # pull on it so it gets defined before the recipe runs it "two_classes_one_dsl resolves to B (alphabetically earliest)" do - two_classes_one_dsl = self.two_classes_one_dsl - recipe = converge { - instance_eval("#{two_classes_one_dsl} 'blah'") - } - expect(recipe.logged_warnings).to eq '' + temp_two_classes_one_dsl = two_classes_one_dsl + recipe = converge do + instance_eval("#{temp_two_classes_one_dsl} 'blah'") + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq resource_class end @@ -901,11 +909,11 @@ describe "Recipe DSL methods" do end it "two_classes_one_dsl resolves to Z (respects the priority array)" do - two_classes_one_dsl = self.two_classes_one_dsl - recipe = converge { - instance_eval("#{two_classes_one_dsl} 'blah'") - } - expect(recipe.logged_warnings).to eq '' + temp_two_classes_one_dsl = two_classes_one_dsl + recipe = converge do + instance_eval("#{temp_two_classes_one_dsl} 'blah'") + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq resource_class_z end @@ -919,11 +927,11 @@ describe "Recipe DSL methods" do end it "two_classes_one_dsl resolves to B (picks the next thing in the priority array)" do - two_classes_one_dsl = self.two_classes_one_dsl - recipe = converge { - instance_eval("#{two_classes_one_dsl} 'blah'") - } - expect(recipe.logged_warnings).to eq '' + temp_two_classes_one_dsl = two_classes_one_dsl + recipe = converge do + instance_eval("#{temp_two_classes_one_dsl} 'blah'") + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq resource_class end @@ -940,11 +948,11 @@ describe "Recipe DSL methods" do end it "two_classes_one_dsl resolves to Z (respects the most recent priority array)" do - two_classes_one_dsl = self.two_classes_one_dsl - recipe = converge { - instance_eval("#{two_classes_one_dsl} 'blah'") - } - expect(recipe.logged_warnings).to eq '' + temp_two_classes_one_dsl = two_classes_one_dsl + recipe = converge do + instance_eval("#{temp_two_classes_one_dsl} 'blah'") + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq resource_class_z end @@ -958,11 +966,11 @@ describe "Recipe DSL methods" do end it "two_classes_one_dsl resolves to B (picks the first match from the other priority array)" do - two_classes_one_dsl = self.two_classes_one_dsl - recipe = converge { - instance_eval("#{two_classes_one_dsl} 'blah'") - } - expect(recipe.logged_warnings).to eq '' + temp_two_classes_one_dsl = two_classes_one_dsl + recipe = converge do + instance_eval("#{temp_two_classes_one_dsl} 'blah'") + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq resource_class end @@ -983,11 +991,11 @@ describe "Recipe DSL methods" do end it "two_classes_one_dsl resolves to B (picks the first match outside the priority array)" do - two_classes_one_dsl = self.two_classes_one_dsl - recipe = converge { - instance_eval("#{two_classes_one_dsl} 'blah'") - } - expect(recipe.logged_warnings).to eq '' + temp_two_classes_one_dsl = two_classes_one_dsl + recipe = converge do + instance_eval("#{temp_two_classes_one_dsl} 'blah'") + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq resource_class end @@ -1004,39 +1012,43 @@ describe "Recipe DSL methods" do resource_class.send(:define_method, :provider) { nil } end - let(:provider_class) { + let(:provider_class) do result = Class.new(BaseThingy::Provider) do def self.name "B" end + def self.to_s; name; end + def self.inspect; name.inspect; end end result.provides two_classes_one_dsl result - } + end before { provider_class } # pull on it so it gets defined before the recipe runs context "and another provider named 'A'" do - let(:provider_class_a) { + let(:provider_class_a) do result = Class.new(BaseThingy::Provider) do def self.name "A" end + def self.to_s; name; end + def self.inspect; name.inspect; end end result - } + end context "which provides :two_classes_one_dsl" do before { provider_class_a.provides two_classes_one_dsl } it "two_classes_one_dsl resolves to A (alphabetically earliest)" do - two_classes_one_dsl = self.two_classes_one_dsl - recipe = converge { - instance_eval("#{two_classes_one_dsl} 'blah'") - } - expect(recipe.logged_warnings).to eq '' + temp_two_classes_one_dsl = two_classes_one_dsl + recipe = converge do + instance_eval("#{temp_two_classes_one_dsl} 'blah'") + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_provider).to eq provider_class_a end end @@ -1044,38 +1056,40 @@ describe "Recipe DSL methods" do before { provider_class_a.provides(two_classes_one_dsl) { false } } it "two_classes_one_dsl resolves to B (since A declined)" do - two_classes_one_dsl = self.two_classes_one_dsl - recipe = converge { - instance_eval("#{two_classes_one_dsl} 'blah'") - } - expect(recipe.logged_warnings).to eq '' + temp_two_classes_one_dsl = two_classes_one_dsl + recipe = converge do + instance_eval("#{temp_two_classes_one_dsl} 'blah'") + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_provider).to eq provider_class end end end context "and another provider named 'Z'" do - let(:provider_class_z) { + let(:provider_class_z) do result = Class.new(BaseThingy::Provider) do def self.name "Z" end + def self.to_s; name; end + def self.inspect; name.inspect; end end result - } + end before { provider_class_z } # pull on it so it gets defined before the recipe runs context "which provides :two_classes_one_dsl" do before { provider_class_z.provides two_classes_one_dsl } it "two_classes_one_dsl resolves to B (alphabetically earliest)" do - two_classes_one_dsl = self.two_classes_one_dsl - recipe = converge { - instance_eval("#{two_classes_one_dsl} 'blah'") - } - expect(recipe.logged_warnings).to eq '' + temp_two_classes_one_dsl = two_classes_one_dsl + recipe = converge do + instance_eval("#{temp_two_classes_one_dsl} 'blah'") + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_provider).to eq provider_class end @@ -1083,11 +1097,11 @@ describe "Recipe DSL methods" do before { Chef.set_provider_priority_array two_classes_one_dsl, [ provider_class_z, provider_class ] } it "two_classes_one_dsl resolves to Z (respects the priority map)" do - two_classes_one_dsl = self.two_classes_one_dsl - recipe = converge { - instance_eval("#{two_classes_one_dsl} 'blah'") - } - expect(recipe.logged_warnings).to eq '' + temp_two_classes_one_dsl = two_classes_one_dsl + recipe = converge do + instance_eval("#{temp_two_classes_one_dsl} 'blah'") + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_provider).to eq provider_class_z end end @@ -1100,11 +1114,11 @@ describe "Recipe DSL methods" do before { Chef.set_provider_priority_array two_classes_one_dsl, [ provider_class_z, provider_class ] } it "two_classes_one_dsl resolves to B (the next one in the priority map)" do - two_classes_one_dsl = self.two_classes_one_dsl - recipe = converge { - instance_eval("#{two_classes_one_dsl} 'blah'") - } - expect(recipe.logged_warnings).to eq '' + temp_two_classes_one_dsl = two_classes_one_dsl + recipe = converge do + instance_eval("#{temp_two_classes_one_dsl} 'blah'") + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_provider).to eq provider_class end end @@ -1114,11 +1128,11 @@ describe "Recipe DSL methods" do before { Chef.set_provider_priority_array two_classes_one_dsl, [ provider_class ] } it "two_classes_one_dsl resolves to B (the one in the next priority map)" do - two_classes_one_dsl = self.two_classes_one_dsl - recipe = converge { - instance_eval("#{two_classes_one_dsl} 'blah'") - } - expect(recipe.logged_warnings).to eq '' + temp_two_classes_one_dsl = two_classes_one_dsl + recipe = converge do + instance_eval("#{temp_two_classes_one_dsl} 'blah'") + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_provider).to eq provider_class end end @@ -1127,76 +1141,80 @@ describe "Recipe DSL methods" do end context "and another resource Blarghle with provides :two_classes_one_dsl, os: 'blarghle'" do - let(:resource_class_blarghle) { + let(:resource_class_blarghle) do result = Class.new(BaseThingy) do def self.name "Blarghle" end + def self.to_s; name; end + def self.inspect; name.inspect; end end result.resource_name two_classes_one_dsl - result.provides two_classes_one_dsl, os: 'blarghle' + result.provides two_classes_one_dsl, os: "blarghle" result - } + end before { resource_class_blarghle } # pull on it so it gets defined before the recipe runs it "on os = blarghle, two_classes_one_dsl resolves to Blarghle" do - two_classes_one_dsl = self.two_classes_one_dsl - recipe = converge { + temp_two_classes_one_dsl = two_classes_one_dsl + recipe = converge do # this is an ugly way to test, make Cheffish expose node attrs - run_context.node.automatic[:os] = 'blarghle' - instance_eval("#{two_classes_one_dsl} 'blah' do; end") - } - expect(recipe.logged_warnings).to eq '' + run_context.node.automatic[:os] = "blarghle" + instance_eval("#{temp_two_classes_one_dsl} 'blah' do; end") + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq resource_class_blarghle end it "on os = linux, two_classes_one_dsl resolves to B" do - two_classes_one_dsl = self.two_classes_one_dsl - recipe = converge { + temp_two_classes_one_dsl = two_classes_one_dsl + recipe = converge do # this is an ugly way to test, make Cheffish expose node attrs - run_context.node.automatic[:os] = 'linux' - instance_eval("#{two_classes_one_dsl} 'blah' do; end") - } - expect(recipe.logged_warnings).to eq '' + run_context.node.automatic[:os] = "linux" + instance_eval("#{temp_two_classes_one_dsl} 'blah' do; end") + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq resource_class end end end context "with a resource MyResource" do - let(:resource_class) { Class.new(BaseThingy) do - def self.called_provides - @called_provides - end - def to_s - "MyResource" - end - end } + let(:resource_class) do + Class.new(BaseThingy) do + def self.called_provides + @called_provides + end + + def to_s + "MyResource" + end + end end let(:my_resource) { :"my_resource#{Namer.current_index}" } let(:blarghle_blarghle_little_star) { :"blarghle_blarghle_little_star#{Namer.current_index}" } context "with resource_name :my_resource" do - before { + before do resource_class.resource_name my_resource - } + end context "with provides? returning true to my_resource" do - before { - my_resource = self.my_resource + before do + temp_my_resource = my_resource resource_class.define_singleton_method(:provides?) do |node, resource_name| @called_provides = true - resource_name == my_resource + resource_name == temp_my_resource end - } + end it "my_resource returns the resource and calls provides?, but does not emit a warning" do - dsl_name = self.my_resource - recipe = converge { + dsl_name = my_resource + recipe = converge do instance_eval("#{dsl_name} 'foo'") - } - expect(recipe.logged_warnings).to eq '' + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq resource_class expect(resource_class.called_provides).to be_truthy end @@ -1204,27 +1222,27 @@ describe "Recipe DSL methods" do context "with provides? returning true to blarghle_blarghle_little_star and not resource_name" do before do - blarghle_blarghle_little_star = self.blarghle_blarghle_little_star + temp_blarghle_blarghle_little_star = blarghle_blarghle_little_star resource_class.define_singleton_method(:provides?) do |node, resource_name| @called_provides = true - resource_name == blarghle_blarghle_little_star + resource_name == temp_blarghle_blarghle_little_star end end it "my_resource does not return the resource" do - dsl_name = self.my_resource - expect_converge { + dsl_name = my_resource + expect_converge do instance_eval("#{dsl_name} 'foo'") - }.to raise_error(Chef::Exceptions::NoSuchResourceType) + end.to raise_error(Chef::Exceptions::NoSuchResourceType) expect(resource_class.called_provides).to be_truthy end it "blarghle_blarghle_little_star 'foo' returns the resource and emits a warning" do Chef::Config[:treat_deprecation_warnings_as_errors] = false - dsl_name = self.blarghle_blarghle_little_star - recipe = converge { + dsl_name = blarghle_blarghle_little_star + recipe = converge do instance_eval("#{dsl_name} 'foo'") - } + end expect(recipe.logged_warnings).to include "WARN: #{resource_class}.provides? returned true when asked if it provides DSL #{dsl_name}, but provides :#{dsl_name} was never called!" expect(BaseThingy.created_resource).to eq resource_class expect(resource_class.called_provides).to be_truthy @@ -1237,8 +1255,11 @@ describe "Recipe DSL methods" do def self.name "MyProvider" end + def self.to_s; name; end + def self.inspect; name.inspect; end + def self.called_provides @called_provides end @@ -1256,15 +1277,15 @@ describe "Recipe DSL methods" do context "with supports? returning true" do before do - provider_class.define_singleton_method(:supports?) { |resource,action| true } + provider_class.define_singleton_method(:supports?) { |resource, action| true } end it "my_resource runs the provider and does not emit a warning" do - my_resource = self.my_resource - recipe = converge { - instance_eval("#{my_resource} 'foo'") - } - expect(recipe.logged_warnings).to eq '' + temp_my_resource = my_resource + recipe = converge do + instance_eval("#{temp_my_resource} 'foo'") + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_provider).to eq provider_class end @@ -1274,8 +1295,11 @@ describe "Recipe DSL methods" do def self.name "MyProvider2" end + def self.to_s; name; end + def self.inspect; name.inspect; end + def self.called_provides @called_provides end @@ -1287,11 +1311,11 @@ describe "Recipe DSL methods" do end it "my_resource runs the first provider" do - my_resource = self.my_resource - recipe = converge { - instance_eval("#{my_resource} 'foo'") - } - expect(recipe.logged_warnings).to eq '' + temp_my_resource = my_resource + recipe = converge do + instance_eval("#{temp_my_resource} 'foo'") + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_provider).to eq provider_class end end @@ -1299,32 +1323,35 @@ describe "Recipe DSL methods" do context "with supports? returning false" do before do - provider_class.define_singleton_method(:supports?) { |resource,action| false } + provider_class.define_singleton_method(:supports?) { |resource, action| false } end # TODO no warning? ick it "my_resource runs the provider anyway" do - my_resource = self.my_resource - recipe = converge { - instance_eval("#{my_resource} 'foo'") - } - expect(recipe.logged_warnings).to eq '' + temp_my_resource = my_resource + recipe = converge do + instance_eval("#{temp_my_resource} 'foo'") + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_provider).to eq provider_class end context "and another provider supporting :my_resource with supports? true" do let(:provider_class2) do - my_resource = self.my_resource + temp_my_resource = my_resource Class.new(BaseThingy::Provider) do def self.name "MyProvider2" end + def self.to_s; name; end + def self.inspect; name.inspect; end + def self.called_provides @called_provides end - provides my_resource + provides temp_my_resource def self.supports?(resource, action) true end @@ -1333,11 +1360,11 @@ describe "Recipe DSL methods" do before { provider_class2 } # make sure the provider class shows up it "my_resource runs the other provider" do - my_resource = self.my_resource - recipe = converge { - instance_eval("#{my_resource} 'foo'") - } - expect(recipe.logged_warnings).to eq '' + temp_my_resource = my_resource + recipe = converge do + instance_eval("#{temp_my_resource} 'foo'") + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_provider).to eq provider_class2 end end @@ -1345,25 +1372,25 @@ describe "Recipe DSL methods" do end context "with provides? returning true" do - before { - my_resource = self.my_resource + before do + temp_my_resource = my_resource provider_class.define_singleton_method(:provides?) do |node, resource| @called_provides = true - resource.declared_type == my_resource + resource.declared_type == temp_my_resource end - } + end context "that provides :my_resource" do - before { + before do provider_class.provides my_resource - } + end it "my_resource calls the provider (and calls provides?), but does not emit a warning" do - my_resource = self.my_resource - recipe = converge { - instance_eval("#{my_resource} 'foo'") - } - expect(recipe.logged_warnings).to eq '' + temp_my_resource = my_resource + recipe = converge do + instance_eval("#{temp_my_resource} 'foo'") + end + expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_provider).to eq provider_class expect(provider_class.called_provides).to be_truthy end @@ -1372,10 +1399,10 @@ describe "Recipe DSL methods" do context "that does not call provides :my_resource" do it "my_resource calls the provider (and calls provides?), and emits a warning" do Chef::Config[:treat_deprecation_warnings_as_errors] = false - my_resource = self.my_resource - recipe = converge { - instance_eval("#{my_resource} 'foo'") - } + temp_my_resource = my_resource + recipe = converge do + instance_eval("#{temp_my_resource} 'foo'") + end expect(recipe.logged_warnings).to include("WARN: #{provider_class}.provides? returned true when asked if it provides DSL #{my_resource}, but provides :#{my_resource} was never called!") expect(BaseThingy.created_provider).to eq provider_class expect(provider_class.called_provides).to be_truthy @@ -1384,34 +1411,36 @@ describe "Recipe DSL methods" do end context "with provides? returning false to my_resource" do - before { - my_resource = self.my_resource + before do + temp_my_resource = my_resource provider_class.define_singleton_method(:provides?) do |node, resource| @called_provides = true false end - } + end context "that provides :my_resource" do - before { + before do provider_class.provides my_resource - } + end it "my_resource fails to find a provider (and calls provides)" do - my_resource = self.my_resource - expect_converge { - instance_eval("#{my_resource} 'foo'") - }.to raise_error(Chef::Exceptions::ProviderNotFound) + Chef::Config[:treat_deprecation_warnings_as_errors] = false + temp_my_resource = my_resource + expect_converge do + instance_eval("#{temp_my_resource} 'foo'") + end.to raise_error(Chef::Exceptions::ProviderNotFound) expect(provider_class.called_provides).to be_truthy end end context "that does not provide :my_resource" do it "my_resource fails to find a provider (and calls provides)" do - my_resource = self.my_resource - expect_converge { - instance_eval("#{my_resource} 'foo'") - }.to raise_error(Chef::Exceptions::ProviderNotFound) + Chef::Config[:treat_deprecation_warnings_as_errors] = false + temp_my_resource = my_resource + expect_converge do + instance_eval("#{temp_my_resource} 'foo'") + end.to raise_error(Chef::Exceptions::ProviderNotFound) expect(provider_class.called_provides).to be_truthy end end @@ -1425,15 +1454,15 @@ describe "Recipe DSL methods" do before { Namer.current_index += 1 } context "with an LWRP that declares actions" do - let(:resource_class) { + let(:resource_class) do Class.new(Chef::Resource::LWRPBase) do provides :"recipe_dsl_spec#{Namer.current_index}" actions :create end - } - let(:resource) { + end + let(:resource) do resource_class.new("blah", run_context) - } + end it "The actions are part of actions along with :nothing" do expect(resource_class.actions).to eq [ :nothing, :create ] end @@ -1442,15 +1471,15 @@ describe "Recipe DSL methods" do end context "and a subclass that declares more actions" do - let(:subresource_class) { + let(:subresource_class) do Class.new(Chef::Resource::LWRPBase) do provides :"recipe_dsl_spec_sub#{Namer.current_index}" actions :delete end - } - let(:subresource) { + end + let(:subresource) do subresource_class.new("subblah", run_context) - } + end it "The parent class actions are not part of actions" do expect(subresource_class.actions).to eq [ :nothing, :delete ] @@ -1475,6 +1504,7 @@ describe "Recipe DSL methods" do class Chef::Provider::LwResourceWithHwProviderTestCase < Chef::Provider def load_current_resource end + def action_create new_resource.created_provider = self.class end @@ -1482,10 +1512,11 @@ describe "Recipe DSL methods" do end it "looks up the provider in Chef::Provider converting the resource name from snake case to camel case" do + Chef::Config[:treat_deprecation_warnings_as_errors] = false resource = nil - recipe = converge { - resource = lw_resource_with_hw_provider_test_case 'blah' do; end - } + recipe = converge do + resource = lw_resource_with_hw_provider_test_case("blah") {} + end expect(resource.created_provider).to eq(Chef::Provider::LwResourceWithHwProviderTestCase) end end diff --git a/spec/integration/recipes/remote_directory.rb b/spec/integration/recipes/remote_directory.rb index a1988ccd52..77fe183136 100644 --- a/spec/integration/recipes/remote_directory.rb +++ b/spec/integration/recipes/remote_directory.rb @@ -1,4 +1,4 @@ -require 'support/shared/integration/integration_helper' +require "support/shared/integration/integration_helper" describe Chef::Resource::RemoteDirectory do include IntegrationSupport @@ -20,7 +20,7 @@ describe Chef::Resource::RemoteDirectory do when_the_repository "has a cookbook with a source_dir with two subdirectories, each with one file and subdir in a different alphabetical order" do before do - file 'config/client.rb', <<-EOM + file "config/client.rb", <<-EOM local_mode true cookbook_path "#{path_to('cookbooks')}" EOM diff --git a/spec/integration/recipes/resource_action_spec.rb b/spec/integration/recipes/resource_action_spec.rb index 6f3f5ab47e..f11696bae4 100644 --- a/spec/integration/recipes/resource_action_spec.rb +++ b/spec/integration/recipes/resource_action_spec.rb @@ -1,131 +1,150 @@ -require 'support/shared/integration/integration_helper' +require "support/shared/integration/integration_helper" -describe "Resource.action" do - include IntegrationSupport +# Houses any classes we declare +module ResourceActionSpec - shared_context "ActionJackson" do - it "the default action is the first declared action" do - converge <<-EOM, __FILE__, __LINE__+1 - #{resource_dsl} 'hi' do - foo 'foo!' - end - EOM - expect(ActionJackson.ran_action).to eq :access_recipe_dsl - expect(ActionJackson.succeeded).to eq true - end + describe "Resource.action" do + include IntegrationSupport - it "the action can access recipe DSL" do - converge <<-EOM, __FILE__, __LINE__+1 - #{resource_dsl} 'hi' do - foo 'foo!' - action :access_recipe_dsl - end - EOM - expect(ActionJackson.ran_action).to eq :access_recipe_dsl - expect(ActionJackson.succeeded).to eq true - end + shared_context "ActionJackson" do + it "the default action is the first declared action" do + converge <<-EOM, __FILE__, __LINE__ + 1 + #{resource_dsl} "hi" do + foo "foo!" + end + EOM + expect(ActionJackson.ran_action).to eq :access_recipe_dsl + expect(ActionJackson.succeeded).to eq true + end - it "the action can access attributes" do - converge <<-EOM, __FILE__, __LINE__+1 - #{resource_dsl} 'hi' do - foo 'foo!' - action :access_attribute + context "when running in whyrun mode" do + before do + Chef::Config[:why_run] = true end - EOM - expect(ActionJackson.ran_action).to eq :access_attribute - expect(ActionJackson.succeeded).to eq 'foo!' - end - it "the action can access public methods" do - converge <<-EOM, __FILE__, __LINE__+1 - #{resource_dsl} 'hi' do - foo 'foo!' - action :access_method + it "the default action runs" do + converge <<-EOM, __FILE__, __LINE__ + 1 + #{resource_dsl} "hi" do + foo "foo!" + end + EOM + expect(ActionJackson.ran_action).to eq :access_recipe_dsl + expect(ActionJackson.succeeded).to eq true end - EOM - expect(ActionJackson.ran_action).to eq :access_method - expect(ActionJackson.succeeded).to eq 'foo_public!' - end + end - it "the action can access protected methods" do - converge <<-EOM, __FILE__, __LINE__+1 - #{resource_dsl} 'hi' do - foo 'foo!' - action :access_protected_method - end - EOM - expect(ActionJackson.ran_action).to eq :access_protected_method - expect(ActionJackson.succeeded).to eq 'foo_protected!' - end + it "the action can access recipe DSL" do + converge <<-EOM, __FILE__, __LINE__ + 1 + #{resource_dsl} "hi" do + foo "foo!" + action :access_recipe_dsl + end + EOM + expect(ActionJackson.ran_action).to eq :access_recipe_dsl + expect(ActionJackson.succeeded).to eq true + end - it "the action cannot access private methods" do - expect { - converge(<<-EOM, __FILE__, __LINE__+1) - #{resource_dsl} 'hi' do - foo 'foo!' - action :access_private_method + it "the action can access attributes" do + converge <<-EOM, __FILE__, __LINE__ + 1 + #{resource_dsl} "hi" do + foo "foo!" + action :access_attribute end EOM - }.to raise_error(NameError) - expect(ActionJackson.ran_action).to eq :access_private_method - end + expect(ActionJackson.ran_action).to eq :access_attribute + expect(ActionJackson.succeeded).to eq "foo!" + end - it "the action cannot access resource instance variables" do - converge <<-EOM, __FILE__, __LINE__+1 - #{resource_dsl} 'hi' do - foo 'foo!' - action :access_instance_variable - end - EOM - expect(ActionJackson.ran_action).to eq :access_instance_variable - expect(ActionJackson.succeeded).to be_nil - end + it "the action can access public methods" do + converge <<-EOM, __FILE__, __LINE__ + 1 + #{resource_dsl} "hi" do + foo "foo!" + action :access_method + end + EOM + expect(ActionJackson.ran_action).to eq :access_method + expect(ActionJackson.succeeded).to eq "foo_public!" + end - it "the action does not compile until the prior resource has converged" do - converge <<-EOM, __FILE__, __LINE__+1 - ruby_block 'wow' do - block do - ActionJackson.ruby_block_converged = 'ruby_block_converged!' + it "the action can access protected methods" do + converge <<-EOM, __FILE__, __LINE__ + 1 + #{resource_dsl} "hi" do + foo "foo!" + action :access_protected_method end - end + EOM + expect(ActionJackson.ran_action).to eq :access_protected_method + expect(ActionJackson.succeeded).to eq "foo_protected!" + end - #{resource_dsl} 'hi' do - foo 'foo!' - action :access_class_method - end - EOM - expect(ActionJackson.ran_action).to eq :access_class_method - expect(ActionJackson.succeeded).to eq 'ruby_block_converged!' - end + it "the action cannot access private methods" do + expect do + converge(<<-EOM, __FILE__, __LINE__ + 1) + #{resource_dsl} "hi" do + foo "foo!" + action :access_private_method + end + EOM + end.to raise_error(NameError) + expect(ActionJackson.ran_action).to eq :access_private_method + end + + it "the action cannot access resource instance variables" do + converge <<-EOM, __FILE__, __LINE__ + 1 + #{resource_dsl} "hi" do + foo "foo!" + action :access_instance_variable + end + EOM + expect(ActionJackson.ran_action).to eq :access_instance_variable + expect(ActionJackson.succeeded).to be_nil + end + + it "the action does not compile until the prior resource has converged" do + converge <<-EOM, __FILE__, __LINE__ + 1 + ruby_block "wow" do + block do + ResourceActionSpec::ActionJackson.ruby_block_converged = "ruby_block_converged!" + end + end - it "the action's resources converge before the next resource converges" do - converge <<-EOM, __FILE__, __LINE__+1 - #{resource_dsl} 'hi' do - foo 'foo!' + #{resource_dsl} "hi" do + foo "foo!" + action :access_class_method + end + EOM + expect(ActionJackson.ran_action).to eq :access_class_method + expect(ActionJackson.succeeded).to eq "ruby_block_converged!" + end + + it "the action's resources converge before the next resource converges" do + converge <<-EOM, __FILE__, __LINE__ + 1 + #{resource_dsl} "hi" do + foo "foo!" action :access_attribute end - ruby_block 'wow' do + ruby_block "wow" do block do - ActionJackson.ruby_block_converged = ActionJackson.succeeded + ResourceActionSpec::ActionJackson.ruby_block_converged = ResourceActionSpec::ActionJackson.succeeded end end EOM - expect(ActionJackson.ran_action).to eq :access_attribute - expect(ActionJackson.succeeded).to eq 'foo!' - expect(ActionJackson.ruby_block_converged).to eq 'foo!' + expect(ActionJackson.ran_action).to eq :access_attribute + expect(ActionJackson.succeeded).to eq "foo!" + expect(ActionJackson.ruby_block_converged).to eq "foo!" + end end - end - context "With resource 'action_jackson'" do - before(:context) { + context "With resource 'action_jackson'" do class ActionJackson < Chef::Resource use_automatic_resource_name - def foo(value=nil) + def foo(value = nil) @foo = value if value @foo end - def blarghle(value=nil) + + def blarghle(value = nil) @blarghle = value if value @blarghle end @@ -136,23 +155,9 @@ describe "Resource.action" do attr_accessor :ruby_block_converged end - public - def foo_public - 'foo_public!' - end - protected - def foo_protected - 'foo_protected!' - end - private - def foo_private - 'foo_private!' - end - - public action :access_recipe_dsl do ActionJackson.ran_action = :access_recipe_dsl - ruby_block 'hi there' do + whyrun_safe_ruby_block "hi there" do block do ActionJackson.succeeded = true end @@ -190,45 +195,61 @@ describe "Resource.action" do ActionJackson.ran_action = :access_class_method ActionJackson.succeeded = ActionJackson.ruby_block_converged end - end - } - before(:each) { - ActionJackson.ran_action = :error - ActionJackson.succeeded = :error - ActionJackson.ruby_block_converged = :error - } - - it_behaves_like "ActionJackson" do - let(:resource_dsl) { :action_jackson } - end - it "Can retrieve ancestors of action class without crashing" do - converge { action_jackson 'hi' } - expect { ActionJackson.action_class.ancestors.join(",") }.not_to raise_error - end + def foo_public + "foo_public!" + end - context "And 'action_jackgrandson' inheriting from ActionJackson and changing nothing" do - before(:context) { - class ActionJackgrandson < ActionJackson - use_automatic_resource_name + protected + + def foo_protected + "foo_protected!" end - } + + private + + def foo_private + "foo_private!" + end + end + + before(:each) do + ActionJackson.ran_action = :error + ActionJackson.succeeded = :error + ActionJackson.ruby_block_converged = :error + end it_behaves_like "ActionJackson" do - let(:resource_dsl) { :action_jackgrandson } + let(:resource_dsl) { :action_jackson } + end + + it "Can retrieve ancestors of action class without crashing" do + converge { action_jackson "hi" } + expect { ActionJackson.action_class.ancestors.join(",") }.not_to raise_error end - end - context "And 'action_jackalope' inheriting from ActionJackson with an extra attribute, action and custom method" do - before(:context) { + context "And 'action_jackgrandson' inheriting from ActionJackson and changing nothing" do + before(:context) do + class ActionJackgrandson < ActionJackson + use_automatic_resource_name + end + end + + it_behaves_like "ActionJackson" do + let(:resource_dsl) { :action_jackgrandson } + end + end + + context "And 'action_jackalope' inheriting from ActionJackson with an extra attribute, action and custom method" do class ActionJackalope < ActionJackson use_automatic_resource_name - def foo(value=nil) + def foo(value = nil) @foo = "#{value}alope" if value @foo end - def bar(value=nil) + + def bar(value = nil) @bar = "#{value}alope" if value @bar end @@ -246,78 +267,76 @@ describe "Resource.action" do ActionJackalope.succeeded = ActionJackson.succeeded end end - } - before do - ActionJackalope.jackalope_ran = nil - ActionJackalope.load_current_resource_ran = nil - end - - context "action_jackson still behaves the same" do - it_behaves_like "ActionJackson" do - let(:resource_dsl) { :action_jackson } + before do + ActionJackalope.jackalope_ran = nil + ActionJackalope.load_current_resource_ran = nil end - end - it "the default action remains the same even though new actions were specified first" do - converge { - action_jackalope 'hi' do - foo 'foo!' - bar 'bar!' + context "action_jackson still behaves the same" do + it_behaves_like "ActionJackson" do + let(:resource_dsl) { :action_jackson } end - } - expect(ActionJackson.ran_action).to eq :access_recipe_dsl - expect(ActionJackson.succeeded).to eq true - end + end - it "new actions run, and can access overridden, new, and overridden attributes" do - converge { - action_jackalope 'hi' do - foo 'foo!' - bar 'bar!' - blarghle 'blarghle!' - action :access_jackalope - end - } - expect(ActionJackalope.jackalope_ran).to eq :access_jackalope - expect(ActionJackalope.succeeded).to eq "foo!alope blarghle! bar!alope" - end + it "the default action remains the same even though new actions were specified first" do + converge do + action_jackalope "hi" do + foo "foo!" + bar "bar!" + end + end + expect(ActionJackson.ran_action).to eq :access_recipe_dsl + expect(ActionJackson.succeeded).to eq true + end - it "overridden actions run, call super, and can access overridden, new, and overridden attributes" do - converge { - action_jackalope 'hi' do - foo 'foo!' - bar 'bar!' - blarghle 'blarghle!' - action :access_attribute + it "new actions run, and can access overridden, new, and overridden attributes" do + converge do + action_jackalope "hi" do + foo "foo!" + bar "bar!" + blarghle "blarghle!" + action :access_jackalope + end end - } - expect(ActionJackson.ran_action).to eq :access_attribute - expect(ActionJackson.succeeded).to eq "foo!alope blarghle! bar!alope" - expect(ActionJackalope.jackalope_ran).to eq :access_attribute - expect(ActionJackalope.succeeded).to eq "foo!alope blarghle! bar!alope" - end + expect(ActionJackalope.jackalope_ran).to eq :access_jackalope + expect(ActionJackalope.succeeded).to eq "foo!alope blarghle! bar!alope" + end - it "non-overridden actions run and can access overridden and non-overridden variables (but not necessarily new ones)" do - converge { - action_jackalope 'hi' do - foo 'foo!' - bar 'bar!' - blarghle 'blarghle!' - action :access_attribute2 - end - } - expect(ActionJackson.ran_action).to eq :access_attribute2 - expect(ActionJackson.succeeded).to eq("foo!alope blarghle! bar!alope").or(eq("foo!alope blarghle!")) + it "overridden actions run, call super, and can access overridden, new, and overridden attributes" do + converge do + action_jackalope "hi" do + foo "foo!" + bar "bar!" + blarghle "blarghle!" + action :access_attribute + end + end + expect(ActionJackson.ran_action).to eq :access_attribute + expect(ActionJackson.succeeded).to eq "foo!alope blarghle! bar!alope" + expect(ActionJackalope.jackalope_ran).to eq :access_attribute + expect(ActionJackalope.succeeded).to eq "foo!alope blarghle! bar!alope" + end + + it "non-overridden actions run and can access overridden and non-overridden variables (but not necessarily new ones)" do + converge do + action_jackalope "hi" do + foo "foo!" + bar "bar!" + blarghle "blarghle!" + action :access_attribute2 + end + end + expect(ActionJackson.ran_action).to eq :access_attribute2 + expect(ActionJackson.succeeded).to eq("foo!alope blarghle! bar!alope").or(eq("foo!alope blarghle!")) + end end end - end - context "With a resource with no actions" do - before(:context) { + context "With a resource with no actions" do class NoActionJackson < Chef::Resource use_automatic_resource_name - def foo(value=nil) + def foo(value = nil) @foo = value if value @foo end @@ -326,20 +345,19 @@ describe "Resource.action" do attr_accessor :action_was end end - } - it "the default action is :nothing" do - converge { - no_action_jackson 'hi' do - foo 'foo!' - NoActionJackson.action_was = action - end - } - expect(NoActionJackson.action_was).to eq [:nothing] + + it "the default action is :nothing" do + converge do + no_action_jackson "hi" do + foo "foo!" + NoActionJackson.action_was = action + end + end + expect(NoActionJackson.action_was).to eq [:nothing] + end end - end - context "With a resource with action a-b-c d" do - before(:context) { + context "With a resource with action a-b-c d" do class WeirdActionJackson < Chef::Resource use_automatic_resource_name @@ -351,13 +369,213 @@ describe "Resource.action" do WeirdActionJackson.action_was = action end end - } - it "Running the action works" do - expect_recipe { - weird_action_jackson 'hi' - }.to be_up_to_date - expect(WeirdActionJackson.action_was).to eq :"a-b-c d" + it "Running the action works" do + expect_recipe do + weird_action_jackson "hi" + end.to be_up_to_date + expect(WeirdActionJackson.action_was).to eq :"a-b-c d" + end + end + + context "With a resource with property x" do + class ResourceActionSpecWithX < Chef::Resource + resource_name :resource_action_spec_with_x + property :x, default: 20 + action :set do + # Access x during converge to ensure that we emit no warnings there + x + end + end + + context "And another resource with a property x and an action that sets property x to its value" do + class ResourceActionSpecAlsoWithX < Chef::Resource + resource_name :resource_action_spec_also_with_x + property :x + action :set_x_to_x do + resource_action_spec_with_x "hi" do + x x + end + end + def self.x_warning_line + __LINE__ - 4 + end + action :set_x_to_x_in_non_initializer do + r = resource_action_spec_with_x "hi" do + x 10 + end + x_times_2 = r.x * 2 + end + action :set_x_to_10 do + resource_action_spec_with_x "hi" do + x 10 + end + end + end + + attr_reader :x_warning_line + + it "Using the enclosing resource to set x to x emits a warning that you're using the wrong x" do + recipe = converge do + resource_action_spec_also_with_x "hi" do + x 1 + action :set_x_to_x + end + end + warnings = recipe.logs.lines.select { |l| l =~ /warn/i } + expect(warnings.size).to eq 1 + expect(warnings[0]).to match(/property x is declared in both resource_action_spec_with_x\[hi\] and resource_action_spec_also_with_x\[hi\] action :set_x_to_x. Use new_resource.x instead. At #{__FILE__}:#{ResourceActionSpecAlsoWithX.x_warning_line}/) + end + + it "Using the enclosing resource to set x to x outside the initializer emits no warning" do + expect_recipe do + resource_action_spec_also_with_x "hi" do + x 1 + action :set_x_to_x_in_non_initializer + end + end.to emit_no_warnings_or_errors + end + + it "Using the enclosing resource to set x to 10 emits no warning" do + expect_recipe do + resource_action_spec_also_with_x "hi" do + x 1 + action :set_x_to_10 + end + end.to emit_no_warnings_or_errors + end + + it "Using the enclosing resource to set x to 10 emits no warning" do + expect_recipe do + r = resource_action_spec_also_with_x "hi" + r.x 1 + r.action :set_x_to_10 + end.to emit_no_warnings_or_errors + end + end + + end + + context "With a resource with a set_or_return property named group (same name as a resource)" do + class ResourceActionSpecWithGroupAction < Chef::Resource + resource_name :resource_action_spec_set_group_to_nil + action :set_group_to_nil do + # Access x during converge to ensure that we emit no warnings there + resource_action_spec_with_group "hi" do + group nil + action :nothing + end + end + end + + class ResourceActionSpecWithGroup < Chef::Resource + resource_name :resource_action_spec_with_group + def group(value = nil) + set_or_return(:group, value, {}) + end + end + + it "Setting group to nil in an action does not emit a warning about it being defined in two places" do + expect_recipe do + resource_action_spec_set_group_to_nil "hi" do + action :set_group_to_nil + end + end.to emit_no_warnings_or_errors + end + end + + context "When a resource has a property with the same name as another resource" do + class HasPropertyNamedTemplate < Chef::Resource + use_automatic_resource_name + property :template + action :create do + template "x" do + "blah" + end + end + end + + it "Raises an error when attempting to use a template in the action" do + expect_converge do + has_property_named_template "hi" + end.to raise_error(/Property `template` of `has_property_named_template\[hi\]` was incorrectly passed a block. Possible property-resource collision. To call a resource named `template` either rename the property or else use `declare_resource\(:template, ...\)`/) + end + end + + context "When a resource declares methods in action_class and declare_action_class" do + class DeclaresActionClassMethods < Chef::Resource + use_automatic_resource_name + property :x + action :create do + new_resource.x = a + b + c + d + end + action_class do + def a + 1 + end + end + declare_action_class do + def b + 2 + end + end + action_class do + def c + 3 + end + end + declare_action_class do + def d + 4 + end + end + end + + it "the methods are not available on the resource" do + expect { DeclaresActionClassMethods.new("hi").a }.to raise_error(NameError) + expect { DeclaresActionClassMethods.new("hi").b }.to raise_error(NameError) + expect { DeclaresActionClassMethods.new("hi").c }.to raise_error(NameError) + expect { DeclaresActionClassMethods.new("hi").d }.to raise_error(NameError) + end + + it "the methods are available to the action" do + r = nil + expect_recipe do + r = declares_action_class_methods "hi" + end.to emit_no_warnings_or_errors + expect(r.x).to eq(10) + end + + context "And a subclass also creates a method" do + class DeclaresActionClassMethodsToo < DeclaresActionClassMethods + use_automatic_resource_name + action :create do + new_resource.x a + b + c + d + e + end + action_class do + def e + 5 + end + end + end + + it "the methods are not available on the resource" do + expect { DeclaresActionClassMethods.new("hi").a }.to raise_error(NameError) + expect { DeclaresActionClassMethods.new("hi").b }.to raise_error(NameError) + expect { DeclaresActionClassMethods.new("hi").c }.to raise_error(NameError) + expect { DeclaresActionClassMethods.new("hi").d }.to raise_error(NameError) + expect { DeclaresActionClassMethods.new("hi").e }.to raise_error(NameError) + end + + it "the methods are available to the action" do + r = nil + expect_recipe do + r = declares_action_class_methods_too "hi" + end.to emit_no_warnings_or_errors + expect(r.x).to eq(15) + end + end end end + end diff --git a/spec/integration/recipes/resource_converge_if_changed_spec.rb b/spec/integration/recipes/resource_converge_if_changed_spec.rb index 82d38a8faf..89d831ddec 100644 --- a/spec/integration/recipes/resource_converge_if_changed_spec.rb +++ b/spec/integration/recipes/resource_converge_if_changed_spec.rb @@ -1,4 +1,4 @@ -require 'support/shared/integration/integration_helper' +require "support/shared/integration/integration_helper" describe "Resource::ActionClass#converge_if_changed" do include IntegrationSupport @@ -19,14 +19,15 @@ describe "Resource::ActionClass#converge_if_changed" do context "when the resource has identity, state and control properties" do let(:resource_name) { :"converge_if_changed_dsl#{Namer.current_index}" } - let(:resource_class) { + let(:resource_class) do result = Class.new(Chef::Resource) do - def self.to_s; resource_name; end + def self.to_s; resource_name.to_s; end + def self.inspect; resource_name.inspect; end - property :identity1, identity: true, default: 'default_identity1' - property :control1, desired_state: false, default: 'default_control1' - property :state1, default: 'default_state1' - property :state2, default: 'default_state2' + property :identity1, identity: true, default: "default_identity1" + property :control1, desired_state: false, default: "default_control1" + property :state1, default: "default_state1" + property :state2, default: "default_state2" attr_accessor :converged def initialize(*args) super @@ -35,7 +36,7 @@ describe "Resource::ActionClass#converge_if_changed" do end result.resource_name resource_name result - } + end let(:converged_recipe) { converge(converge_recipe) } let(:resource) { converged_recipe.resources.first } @@ -51,8 +52,8 @@ describe "Resource::ActionClass#converge_if_changed" do context "and current_resource with state1=current, state2=current" do before :each do resource_class.load_current_value do - state1 'current_state1' - state2 'current_state2' + state1 "current_state1" + state2 "current_state2" end end @@ -69,13 +70,13 @@ describe "Resource::ActionClass#converge_if_changed" do end context "and state1 is set to a new value" do - let(:converge_recipe) { + let(:converge_recipe) do <<-EOM #{resource_name} 'blah' do state1 'new_state1' end EOM - } + end it "the resource updates state1" do expect(resource.converged).to eq 1 @@ -89,14 +90,14 @@ describe "Resource::ActionClass#converge_if_changed" do end context "and state1 and state2 are set to new values" do - let(:converge_recipe) { + let(:converge_recipe) do <<-EOM #{resource_name} 'blah' do state1 'new_state1' state2 'new_state2' end EOM - } + end it "the resource updates state1 and state2" do expect(resource.converged).to eq 1 @@ -110,15 +111,38 @@ EOM end end + context "and state1 and state2 are set to new sensitive values" do + let(:converge_recipe) do + <<-EOM + #{resource_name} 'blah' do + sensitive true + state1 'new_state1' + state2 'new_state2' + end + EOM + end + + it "the resource updates state1 and state2" do + expect(resource.converged).to eq 1 + expect(resource.updated?).to be_truthy + expect(converged_recipe.stdout).to eq <<-EOM +* #{resource_name}[blah] action create + - update default_identity1 + - set state1 to (suppressed sensitive property) + - set state2 to (suppressed sensitive property) +EOM + end + end + context "and state1 is set to its current value but state2 is set to a new value" do - let(:converge_recipe) { + let(:converge_recipe) do <<-EOM #{resource_name} 'blah' do state1 'current_state1' state2 'new_state2' end EOM - } + end it "the resource updates state2" do expect(resource.converged).to eq 1 @@ -132,14 +156,14 @@ EOM end context "and state1 and state2 are set to their current values" do - let(:converge_recipe) { + let(:converge_recipe) do <<-EOM #{resource_name} 'blah' do state1 'current_state1' state2 'current_state2' end EOM - } + end it "the resource updates nothing" do expect(resource.converged).to eq 0 @@ -151,14 +175,14 @@ EOM end context "and identity1 and control1 are set to new values" do - let(:converge_recipe) { + let(:converge_recipe) do <<-EOM #{resource_name} 'blah' do identity1 'new_identity1' control1 'new_control1' end EOM - } + end # Because the identity value is copied over to the new resource, by # default they do not register as "changed" @@ -175,20 +199,20 @@ EOM context "and current_resource with identity1=current, control1=current" do before :each do resource_class.load_current_value do - identity1 'current_identity1' - control1 'current_control1' + identity1 "current_identity1" + control1 "current_control1" end end context "and identity1 and control1 are set to new values" do - let(:converge_recipe) { + let(:converge_recipe) do <<-EOM #{resource_name} 'blah' do identity1 'new_identity1' control1 'new_control1' end EOM - } + end # Control values are not desired state and are therefore not considered # a reason for converging. @@ -228,14 +252,14 @@ EOM end context "and state1 and state2 are set" do - let(:converge_recipe) { + let(:converge_recipe) do <<-EOM #{resource_name} 'blah' do state1 'new_state1' state2 'new_state2' end EOM - } + end it "the resource is created" do expect(resource.converged).to eq 1 @@ -249,6 +273,30 @@ EOM EOM end end + + context "and state1 and state2 are set with sensitive property" do + let(:converge_recipe) do + <<-EOM + #{resource_name} 'blah' do + sensitive true + state1 'new_state1' + state2 'new_state2' + end + EOM + end + + it "the resource is created" do + expect(resource.converged).to eq 1 + expect(resource.updated?).to be_truthy + expect(converged_recipe.stdout).to eq <<-EOM +* #{resource_name}[blah] action create + - create default_identity1 + - set identity1 to (suppressed sensitive property) (default value) + - set state1 to (suppressed sensitive property) + - set state2 to (suppressed sensitive property) +EOM + end + end end end @@ -267,8 +315,8 @@ EOM context "and current_resource with state1=current, state2=current" do before :each do resource_class.load_current_value do - state1 'current_state1' - state2 'current_state2' + state1 "current_state1" + state2 "current_state2" end end @@ -286,13 +334,13 @@ EOM context "and state1 is set to a new value" do - let(:converge_recipe) { + let(:converge_recipe) do <<-EOM #{resource_name} 'blah' do state1 'new_state1' end EOM - } + end it "the resource updates state1" do expect(resource.converged).to eq 1 @@ -306,14 +354,14 @@ EOM end context "and state1 and state2 are set to new values" do - let(:converge_recipe) { + let(:converge_recipe) do <<-EOM #{resource_name} 'blah' do state1 'new_state1' state2 'new_state2' end EOM - } + end it "the resource updates state1 and state2" do expect(resource.converged).to eq 2 @@ -329,14 +377,14 @@ EOM end context "and state1 is set to its current value but state2 is set to a new value" do - let(:converge_recipe) { + let(:converge_recipe) do <<-EOM #{resource_name} 'blah' do state1 'current_state1' state2 'new_state2' end EOM - } + end it "the resource updates state2" do expect(resource.converged).to eq 1 @@ -350,14 +398,14 @@ EOM end context "and state1 and state2 are set to their current values" do - let(:converge_recipe) { + let(:converge_recipe) do <<-EOM #{resource_name} 'blah' do state1 'current_state1' state2 'current_state2' end EOM - } + end it "the resource updates nothing" do expect(resource.converged).to eq 0 @@ -377,9 +425,9 @@ EOM end context "and nothing is set" do - let(:converge_recipe) { + let(:converge_recipe) do "#{resource_name} 'blah'" - } + end it "the resource is created" do expect(resource.converged).to eq 2 @@ -395,14 +443,14 @@ EOM end context "and state1 and state2 are set to new values" do - let(:converge_recipe) { + let(:converge_recipe) do <<-EOM #{resource_name} 'blah' do state1 'new_state1' state2 'new_state2' end EOM - } + end it "the resource is created" do expect(resource.converged).to eq 2 @@ -416,6 +464,31 @@ EOM EOM end end + + context "and state1 and state2 are set to new sensitive values" do + let(:converge_recipe) do + <<-EOM + #{resource_name} 'blah' do + sensitive true + state1 'new_state1' + state2 'new_state2' + end + EOM + end + + it "the resource is created" do + expect(resource.converged).to eq 2 + expect(resource.updated?).to be_truthy + expect(converged_recipe.stdout).to eq <<-EOM +* #{resource_name}[blah] action create + - create default_identity1 + - set state1 to (suppressed sensitive property) + - create default_identity1 + - set state2 to (suppressed sensitive property) +EOM + end + end + end end diff --git a/spec/integration/recipes/resource_load_spec.rb b/spec/integration/recipes/resource_load_spec.rb index 556201efd8..791b83c23a 100644 --- a/spec/integration/recipes/resource_load_spec.rb +++ b/spec/integration/recipes/resource_load_spec.rb @@ -1,4 +1,4 @@ -require 'support/shared/integration/integration_helper' +require "support/shared/integration/integration_helper" describe "Resource.load_current_value" do include IntegrationSupport @@ -18,14 +18,16 @@ describe "Resource.load_current_value" do before { Namer.incrementing_value = 0 } let(:resource_name) { :"load_current_value_dsl#{Namer.current_index}" } - let(:resource_class) { + let(:resource_class) do result = Class.new(Chef::Resource) do - def self.to_s; resource_name; end + def self.to_s; resource_name.to_s; end + def self.inspect; resource_name.inspect; end property :x, default: lazy { "default #{Namer.incrementing_value}" } def self.created_x=(value) @created = value end + def self.created_x @created end @@ -35,7 +37,7 @@ describe "Resource.load_current_value" do end result.resource_name resource_name result - } + end # Pull on resource_class to initialize it before { resource_class } @@ -43,10 +45,10 @@ describe "Resource.load_current_value" do context "with a resource with load_current_value" do before :each do resource_class.load_current_value do - x "loaded #{Namer.incrementing_value} (#{self.class.properties.sort_by { |name,p| name }. - select { |name,p| p.is_set?(self) }. - map { |name,p| "#{name}=#{p.get(self)}" }. - join(", ") })" + x "loaded #{Namer.incrementing_value} (#{self.class.properties.sort_by { |name, p| name }. + select { |name, p| p.is_set?(self) }. + map { |name, p| "#{name}=#{p.get(self)}" }. + join(", ")})" end end @@ -54,65 +56,65 @@ describe "Resource.load_current_value" do let(:resource) do e = self r = nil - converge { - r = public_send(e.resource_name, 'blah') do - x 'desired' + converge do + r = public_send(e.resource_name, "blah") do + x "desired" end - } + end r end it "current_resource is passed name but not x" do - expect(resource.current_value.x).to eq 'loaded 2 (name=blah)' + expect(resource.current_value.x).to eq "loaded 2 (name=blah)" end it "resource.current_value returns a different resource" do - expect(resource.current_value.x).to eq 'loaded 2 (name=blah)' - expect(resource.x).to eq 'desired' + expect(resource.current_value.x).to eq "loaded 2 (name=blah)" + expect(resource.x).to eq "desired" end it "resource.current_value constructs the resource anew each time" do - expect(resource.current_value.x).to eq 'loaded 2 (name=blah)' - expect(resource.current_value.x).to eq 'loaded 3 (name=blah)' + expect(resource.current_value.x).to eq "loaded 2 (name=blah)" + expect(resource.current_value.x).to eq "loaded 3 (name=blah)" end it "the provider accesses the current value of x" do - expect(resource.class.created_x).to eq 'desired' + expect(resource.class.created_x).to eq "desired" end context "and identity: :i and :d with desired_state: false" do - before { + before do resource_class.class_eval do property :i, identity: true property :d, desired_state: false end - } + end - before { - resource.i 'desired_i' - resource.d 'desired_d' - } + before do + resource.i "desired_i" + resource.d "desired_d" + end it "i, name and d are passed to load_current_value, but not x" do - expect(resource.current_value.x).to eq 'loaded 2 (d=desired_d, i=desired_i, name=blah)' + expect(resource.current_value.x).to eq "loaded 2 (d=desired_d, i=desired_i, name=blah)" end end context "and name_property: :i and :d with desired_state: false" do - before { + before do resource_class.class_eval do property :i, name_property: true property :d, desired_state: false end - } + end - before { - resource.i 'desired_i' - resource.d 'desired_d' - } + before do + resource.i "desired_i" + resource.d "desired_d" + end it "i, name and d are passed to load_current_value, but not x" do - expect(resource.current_value.x).to eq 'loaded 2 (d=desired_d, i=desired_i, name=blah)' + expect(resource.current_value.x).to eq "loaded 2 (d=desired_d, i=desired_i, name=blah)" end end end @@ -121,28 +123,28 @@ describe "Resource.load_current_value" do let(:resource) do e = self r = nil - converge { - r = public_send(e.resource_name, 'blah') do + converge do + r = public_send(e.resource_name, "blah") do end - } + end r end it "the provider accesses values from load_current_value" do - expect(resource.class.created_x).to eq 'loaded 1 (name=blah)' + expect(resource.class.created_x).to eq "loaded 1 (name=blah)" end end - let (:subresource_name) { + let (:subresource_name) do :"load_current_value_subresource_dsl#{Namer.current_index}" - } - let (:subresource_class) { + end + let (:subresource_class) do r = Class.new(resource_class) do property :y, default: lazy { "default_y #{Namer.incrementing_value}" } end r.resource_name subresource_name r - } + end # Pull on subresource_class to initialize it before { subresource_class } @@ -150,17 +152,17 @@ describe "Resource.load_current_value" do let(:subresource) do e = self r = nil - converge { - r = public_send(e.subresource_name, 'blah') do - x 'desired' + converge do + r = public_send(e.subresource_name, "blah") do + x "desired" end - } + end r end context "and a child resource class with no load_current_value" do it "the parent load_current_value is used" do - expect(subresource.current_value.x).to eq 'loaded 2 (name=blah)' + expect(subresource.current_value.x).to eq "loaded 2 (name=blah)" end it "load_current_value yields a copy of the child class" do expect(subresource.current_value).to be_kind_of(subresource_class) @@ -168,37 +170,37 @@ describe "Resource.load_current_value" do end context "And a child resource class with load_current_value" do - before { + before do subresource_class.load_current_value do - y "loaded_y #{Namer.incrementing_value} (#{self.class.properties.sort_by { |name,p| name }. - select { |name,p| p.is_set?(self) }. - map { |name,p| "#{name}=#{p.get(self)}" }. - join(", ") })" + y "loaded_y #{Namer.incrementing_value} (#{self.class.properties.sort_by { |name, p| name }. + select { |name, p| p.is_set?(self) }. + map { |name, p| "#{name}=#{p.get(self)}" }. + join(", ")})" end - } + end it "the overridden load_current_value is used" do current_resource = subresource.current_value - expect(current_resource.x).to eq 'default 3' - expect(current_resource.y).to eq 'loaded_y 2 (name=blah)' + expect(current_resource.x).to eq "default 3" + expect(current_resource.y).to eq "loaded_y 2 (name=blah)" end end context "and a child resource class with load_current_value calling super()" do - before { + before do subresource_class.load_current_value do super() - y "loaded_y #{Namer.incrementing_value} (#{self.class.properties.sort_by { |name,p| name }. - select { |name,p| p.is_set?(self) }. - map { |name,p| "#{name}=#{p.get(self)}" }. - join(", ") })" + y "loaded_y #{Namer.incrementing_value} (#{self.class.properties.sort_by { |name, p| name }. + select { |name, p| p.is_set?(self) }. + map { |name, p| "#{name}=#{p.get(self)}" }. + join(", ")})" end - } + end it "the original load_current_value is called as well as the child one" do current_resource = subresource.current_value - expect(current_resource.x).to eq 'loaded 3 (name=blah)' - expect(current_resource.y).to eq 'loaded_y 4 (name=blah, x=loaded 3 (name=blah))' + expect(current_resource.x).to eq "loaded 3 (name=blah)" + expect(current_resource.y).to eq "loaded_y 4 (name=blah, x=loaded 3 (name=blah))" end end end diff --git a/spec/integration/solo/solo_spec.rb b/spec/integration/solo/solo_spec.rb index f45933c799..f6cb2e43ef 100644 --- a/spec/integration/solo/solo_spec.rb +++ b/spec/integration/solo/solo_spec.rb @@ -1,9 +1,10 @@ -require 'support/shared/integration/integration_helper' -require 'chef/mixin/shell_out' -require 'chef/run_lock' -require 'chef/config' -require 'timeout' -require 'fileutils' +require "support/shared/integration/integration_helper" +require "chef/mixin/shell_out" +require "chef/run_lock" +require "chef/config" +require "timeout" +require "fileutils" +require "chef/win32/security" if Chef::Platform.windows? describe "chef-solo" do include IntegrationSupport @@ -15,16 +16,65 @@ describe "chef-solo" do let(:cookbook_ancient_100_metadata_rb) { cb_metadata("ancient", "1.0.0") } - let(:chef_solo) { "ruby bin/chef-solo --minimal-ohai" } + let(:chef_solo) { "ruby bin/chef-solo --legacy-mode --minimal-ohai" } + + when_the_repository "creates nodes" do + let(:nodes_dir) { File.join(@repository_dir, "nodes") } + let(:node_file) { Dir[File.join(nodes_dir, "*.json")][0] } + + before do + file "config/solo.rb", <<EOM +chef_repo_path "#{@repository_dir}" +EOM + result = shell_out("ruby bin/chef-solo -c \"#{path_to('config/solo.rb')}\" -l debug", :cwd => chef_dir) + result.error! + end + + describe "on unix", :unix_only do + describe "the nodes directory" do + it "has the correct permissions" do + expect(File.stat(nodes_dir).mode.to_s(8)[2..5]).to eq("700") + end + end + + describe "the node file" do + it "has the correct permissions" do + expect(File.stat(node_file).mode.to_s(8)[2..5]).to eq("0600") + end + end + end + + describe "on windows", :windows_only do + let(:read_mask) { Chef::ReservedNames::Win32::API::Security::GENERIC_READ } + let(:write_mask) { Chef::ReservedNames::Win32::API::Security::GENERIC_WRITE } + let(:execute_mask) { Chef::ReservedNames::Win32::API::Security::GENERIC_EXECUTE } + + describe "the nodes directory" do + it "has the correct permissions" do + expect(Chef::ReservedNames::Win32::File.file_access_check(nodes_dir, read_mask)).to be(true) + expect(Chef::ReservedNames::Win32::File.file_access_check(nodes_dir, write_mask)).to be(true) + expect(Chef::ReservedNames::Win32::File.file_access_check(nodes_dir, execute_mask)).to be(true) + end + end + + describe "the node file" do + it "has the correct permissions" do + expect(Chef::ReservedNames::Win32::File.file_access_check(node_file, read_mask)).to be(true) + expect(Chef::ReservedNames::Win32::File.file_access_check(node_file, write_mask)).to be(true) + expect(Chef::ReservedNames::Win32::File.file_access_check(node_file, execute_mask)).to be(false) + end + end + end + end when_the_repository "has a cookbook with a basic recipe" do before do - file 'cookbooks/x/metadata.rb', cookbook_x_100_metadata_rb - file 'cookbooks/x/recipes/default.rb', 'puts "ITWORKS"' + file "cookbooks/x/metadata.rb", cookbook_x_100_metadata_rb + file "cookbooks/x/recipes/default.rb", 'puts "ITWORKS"' end it "should complete with success" do - file 'config/solo.rb', <<EOM + file "config/solo.rb", <<EOM cookbook_path "#{path_to('cookbooks')}" file_cache_path "#{path_to('config/cache')}" EOM @@ -34,12 +84,12 @@ EOM end it "should evaluate its node.json file" do - file 'config/solo.rb', <<EOM + file "config/solo.rb", <<EOM cookbook_path "#{path_to('cookbooks')}" file_cache_path "#{path_to('config/cache')}" EOM - file 'config/node.json',<<-E + file "config/node.json", <<-E {"run_list":["x::default"]} E @@ -52,15 +102,15 @@ E when_the_repository "has a cookbook with an undeclared dependency" do before do - file 'cookbooks/x/metadata.rb', cookbook_x_100_metadata_rb - file 'cookbooks/x/recipes/default.rb', 'include_recipe "ancient::aliens"' + file "cookbooks/x/metadata.rb", cookbook_x_100_metadata_rb + file "cookbooks/x/recipes/default.rb", 'include_recipe "ancient::aliens"' - file 'cookbooks/ancient/metadata.rb', cookbook_ancient_100_metadata_rb - file 'cookbooks/ancient/recipes/aliens.rb', 'print "it was aliens"' + file "cookbooks/ancient/metadata.rb", cookbook_ancient_100_metadata_rb + file "cookbooks/ancient/recipes/aliens.rb", 'print "it was aliens"' end it "should exit with an error" do - file 'config/solo.rb', <<EOM + file "config/solo.rb", <<EOM cookbook_path "#{path_to('cookbooks')}" file_cache_path "#{path_to('config/cache')}" EOM @@ -70,73 +120,97 @@ EOM end end + when_the_repository "has a cookbook with an incompatible chef_version" do + before do + file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0", "\nchef_version '~> 999.0'") + file "cookbooks/x/recipes/default.rb", 'puts "ITWORKS"' + file "config/solo.rb", <<EOM +cookbook_path "#{path_to('cookbooks')}" +file_cache_path "#{path_to('config/cache')}" +EOM + end + + it "should exit with an error" do + result = shell_out("#{chef_solo} -c \"#{path_to('config/solo.rb')}\" -o 'x::default' -l debug", :cwd => chef_dir) + expect(result.exitstatus).to eq(1) + expect(result.stdout).to include("Chef::Exceptions::CookbookChefVersionMismatch") + end + end + + when_the_repository "has a cookbook with an incompatible ohai_version" do + before do + file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0", "\nohai_version '~> 999.0'") + file "cookbooks/x/recipes/default.rb", 'puts "ITWORKS"' + file "config/solo.rb", <<EOM +cookbook_path "#{path_to('cookbooks')}" +file_cache_path "#{path_to('config/cache')}" +EOM + end + + it "should exit with an error" do + result = shell_out("#{chef_solo} -c \"#{path_to('config/solo.rb')}\" -o 'x::default' -l debug", :cwd => chef_dir) + expect(result.exitstatus).to eq(1) + expect(result.stdout).to include("Chef::Exceptions::CookbookOhaiVersionMismatch") + end + end when_the_repository "has a cookbook with a recipe with sleep" do before do - directory 'logs' - file 'logs/runs.log', '' - file 'cookbooks/x/metadata.rb', cookbook_x_100_metadata_rb - file 'cookbooks/x/recipes/default.rb', <<EOM + directory "logs" + file "logs/runs.log", "" + file "cookbooks/x/metadata.rb", cookbook_x_100_metadata_rb + file "cookbooks/x/recipes/default.rb", <<EOM ruby_block "sleeping" do block do - sleep 5 + retries = 200 + while IO.read(Chef::Config[:log_location]) !~ /Chef client .* is running, will wait for it to finish and then run./ + sleep 0.1 + raise "we ran out of retries" if ( retries -= 1 ) <= 0 + end end end EOM end it "while running solo concurrently" do - file 'config/solo.rb', <<EOM + file "config/solo.rb", <<EOM cookbook_path "#{path_to('cookbooks')}" file_cache_path "#{path_to('config/cache')}" EOM # We have a timeout protection here so that if due to some bug # run_lock gets stuck we can discover it. - expect { + expect do Timeout.timeout(120) do chef_dir = File.join(File.dirname(__FILE__), "..", "..", "..") - # Instantiate the first chef-solo run - s1 = Process.spawn("#{chef_solo} -c \"#{path_to('config/solo.rb')}\" -o 'x::default' \ --l debug -L #{path_to('logs/runs.log')}", :chdir => chef_dir) + threads = [] - # Give it some time to progress - sleep 1 + # Instantiate the first chef-solo run + threads << Thread.new do + s1 = Process.spawn("#{chef_solo} -c \"#{path_to('config/solo.rb')}\" -o 'x::default' -l debug -L #{path_to('logs/runs.log')}", :chdir => chef_dir) + Process.waitpid(s1) + end # Instantiate the second chef-solo run - s2 = Process.spawn("#{chef_solo} -c \"#{path_to('config/solo.rb')}\" -o 'x::default' \ --l debug -L #{path_to('logs/runs.log')}", :chdir => chef_dir) + threads << Thread.new do + s2 = Process.spawn("#{chef_solo} -c \"#{path_to('config/solo.rb')}\" -o 'x::default' -l debug -L #{path_to('logs/runs.log')}", :chdir => chef_dir) + Process.waitpid(s2) + end - Process.waitpid(s1) - Process.waitpid(s2) + threads.each(&:join) end - }.not_to raise_error + end.not_to raise_error # Unfortunately file / directory helpers in integration tests # are implemented using before(:each) so we need to do all below # checks in one example. - run_log = File.read(path_to('logs/runs.log')) - - # both of the runs should succeed - expect(run_log.lines.reject {|l| !l.include? "INFO: Chef Run complete in"}.length).to eq(2) + run_log = File.read(path_to("logs/runs.log")) # second run should have a message which indicates it's waiting for the first run - pid_lines = run_log.lines.reject {|l| !l.include? "Chef-client pid:"} - expect(pid_lines.length).to eq(2) - pids = pid_lines.map {|l| l.split(" ").last} - expect(run_log).to include("Chef client #{pids[0]} is running, will wait for it to finish and then run.") - - # second run should start after first run ends - starts = [ ] - ends = [ ] - run_log.lines.each_with_index do |line, index| - if line.include? "Chef-client pid:" - starts << index - elsif line.include? "INFO: Chef Run complete in" - ends << index - end - end - expect(starts[1]).to be > ends[0] + expect(run_log).to match(/Chef client .* is running, will wait for it to finish and then run./) + + # both of the runs should succeed + expect(run_log.lines.reject { |l| !l.include? "INFO: Chef Run complete in" }.length).to eq(2) end end |