diff options
author | Ryan Cragun <me@ryan.ec> | 2014-05-20 16:05:10 -0700 |
---|---|---|
committer | Ryan Cragun <me@ryan.ec> | 2014-05-20 16:05:10 -0700 |
commit | 0fe170b0b72f6990ae7ccb55196f16196cd8d3cc (patch) | |
tree | aefd0a6994c92ce44f5011107a088650eb777944 | |
parent | 840682f34c1785426794ff7f656d339d3e276110 (diff) | |
download | chef-0fe170b0b72f6990ae7ccb55196f16196cd8d3cc.tar.gz |
[CHEF-5314] Add unit and fucntional specs
-rw-r--r-- | spec/functional/shell_spec.rb | 10 | ||||
-rw-r--r-- | spec/unit/shell/shell_session_spec.rb | 44 |
2 files changed, 52 insertions, 2 deletions
diff --git a/spec/functional/shell_spec.rb b/spec/functional/shell_spec.rb index 64bd28f16c..f2ce3f53e4 100644 --- a/spec/functional/shell_spec.rb +++ b/spec/functional/shell_spec.rb @@ -118,5 +118,15 @@ describe Shell do output.should include("===fatal===") expect(exitstatus).to eq(0) end + + it "sets the override_runlist from the command line" do + output, exitstatus = run_chef_shell_with("-o 'override::foo,override::bar'") do |out, keyboard| + show_recipes_code = %q[puts "#{node.recipes.inspect}"] + keyboard.puts(show_recipes_code) + read_until(out, show_recipes_code) + end + output.should include(%q{["override::foo", "override::bar"]}) + expect(exitstatus).to eq(0) + end end end diff --git a/spec/unit/shell/shell_session_spec.rb b/spec/unit/shell/shell_session_spec.rb index e5fc46e945..92a2e5d538 100644 --- a/spec/unit/shell/shell_session_spec.rb +++ b/spec/unit/shell/shell_session_spec.rb @@ -48,20 +48,37 @@ describe Shell::ShellSession do end describe Shell::ClientSession do - it "builds the node's run_context with the proper environment" do + before do + Chef::Config[:shell_config] = { :override_runlist => [Chef::RunList::RunListItem.new('shell::override')] } @session = Shell::ClientSession.instance @node = Chef::Node.build("foo") @session.node = @node - @session.instance_variable_set(:@client, double(:sync_cookbooks => {})) + @client = double("Chef::Client.new", + :run_ohai => true, + :load_node => true, + :build_node => true, + :register => true, + :sync_cookbooks => {}) + end + + it "builds the node's run_context with the proper environment" do + @session.instance_variable_set(:@client, @client) @expansion = Chef::RunList::RunListExpansion.new(@node.chef_environment, []) @node.run_list.should_receive(:expand).with(@node.chef_environment).and_return(@expansion) @session.rebuild_context end + + it "passes the shell CLI args to the client" do + Chef::Client.should_receive(:new).with(nil, Chef::Config[:shell_config]).and_return(@client) + @session.send(:rebuild_node) + end + end describe Shell::StandAloneSession do before do + Chef::Config[:shell_config] = { :override_runlist => [Chef::RunList::RunListItem.new('shell::override')] } @session = Shell::StandAloneSession.instance @node = @session.node = Chef::Node.new @events = Chef::EventDispatch::Dispatcher.new @@ -97,10 +114,22 @@ describe Shell::StandAloneSession do @recipe.run_chef.should == :converged end + it "passes the shell CLI args to the client" do + @client = double("Chef::Client.new", + :run_ohai => true, + :load_node => true, + :build_node => true, + :register => true, + :sync_cookbooks => {}) + Chef::Client.should_receive(:new).with(nil, Chef::Config[:shell_config]).and_return(@client) + @session.send(:rebuild_node) + end + end describe Shell::SoloSession do before do + Chef::Config[:shell_config] = { :override_runlist => [Chef::RunList::RunListItem.new('shell::override')] } Chef::Config[:shell_solo] = true @session = Shell::SoloSession.instance @node = Chef::Node.new @@ -151,4 +180,15 @@ describe Shell::SoloSession do @recipe.run_chef.should == :converged end + it "passes the shell CLI args to the client" do + @client = double("Chef::Client.new", + :run_ohai => true, + :load_node => true, + :build_node => true, + :register => true, + :sync_cookbooks => {}) + Chef::Client.should_receive(:new).with(nil, Chef::Config[:shell_config]).and_return(@client) + @session.send(:rebuild_node) + end + end |