From 1603f7363728dc41f67cd189ca0dcbf074ec44b4 Mon Sep 17 00:00:00 2001 From: Jesse Wolfe Date: Thu, 18 Mar 2010 19:01:29 -0700 Subject: Feature #3394 REST Runner, preparation Rename Puppet::Agent::Runner to Puppet::Run, for consistency --- spec/unit/agent/runner.rb | 118 ------------------------------------ spec/unit/indirector/run/rest.rb | 11 ++++ spec/unit/indirector/runner/rest.rb | 11 ---- spec/unit/run.rb | 118 ++++++++++++++++++++++++++++++++++++ 4 files changed, 129 insertions(+), 129 deletions(-) delete mode 100755 spec/unit/agent/runner.rb create mode 100755 spec/unit/indirector/run/rest.rb delete mode 100755 spec/unit/indirector/runner/rest.rb create mode 100755 spec/unit/run.rb (limited to 'spec') diff --git a/spec/unit/agent/runner.rb b/spec/unit/agent/runner.rb deleted file mode 100755 index dfd267a5f..000000000 --- a/spec/unit/agent/runner.rb +++ /dev/null @@ -1,118 +0,0 @@ -#!/usr/bin/env ruby - -require File.dirname(__FILE__) + '/../../spec_helper' -require 'puppet/agent' -require 'puppet/agent/runner' - -describe Puppet::Agent::Runner do - before do - @runner = Puppet::Agent::Runner.new - end - - it "should indirect :runner" do - Puppet::Agent::Runner.indirection.name.should == :runner - end - - it "should use a configurer agent as its agent" do - agent = mock 'agent' - Puppet::Agent.expects(:new).with(Puppet::Configurer).returns agent - - @runner.agent.should equal(agent) - end - - it "should accept options at initialization" do - lambda { Puppet::Agent::Runner.new :background => true }.should_not raise_error - end - - it "should default to running in the foreground" do - Puppet::Agent::Runner.new.should_not be_background - end - - it "should default to its options being an empty hash" do - Puppet::Agent::Runner.new.options.should == {} - end - - it "should accept :tags for the agent" do - Puppet::Agent::Runner.new(:tags => "foo").options[:tags].should == "foo" - end - - it "should accept :ignoreschedules for the agent" do - Puppet::Agent::Runner.new(:ignoreschedules => true).options[:ignoreschedules].should be_true - end - - it "should accept an option to configure it to run in the background" do - Puppet::Agent::Runner.new(:background => true).should be_background - end - - it "should retain the background option" do - Puppet::Agent::Runner.new(:background => true).options[:background].should be_nil - end - - it "should not accept arbitrary options" do - lambda { Puppet::Agent::Runner.new(:foo => true) }.should raise_error(ArgumentError) - end - - describe "when asked to run" do - before do - @agent = stub 'agent', :run => nil, :running? => false - @runner.stubs(:agent).returns @agent - end - - it "should run its agent" do - agent = stub 'agent2', :running? => false - @runner.stubs(:agent).returns agent - - agent.expects(:run) - - @runner.run - end - - it "should pass any of its options on to the agent" do - @runner.stubs(:options).returns(:foo => :bar) - @agent.expects(:run).with(:foo => :bar) - - @runner.run - end - - it "should log its run using the provided options" do - @runner.expects(:log_run) - - @runner.run - end - - it "should set its status to 'already_running' if the agent is already running" do - @agent.expects(:running?).returns true - - @runner.run - - @runner.status.should == "running" - end - - it "should set its status to 'success' if the agent is run" do - @agent.expects(:running?).returns false - - @runner.run - - @runner.status.should == "success" - end - - it "should run the agent in a thread if asked to run it in the background" do - Thread.expects(:new) - - @runner.expects(:background?).returns true - - @agent.expects(:run).never # because our thread didn't yield - - @runner.run - end - - it "should run the agent directly if asked to run it in the foreground" do - Thread.expects(:new).never - - @runner.expects(:background?).returns false - @agent.expects(:run) - - @runner.run - end - end -end diff --git a/spec/unit/indirector/run/rest.rb b/spec/unit/indirector/run/rest.rb new file mode 100755 index 000000000..e07fe7fc2 --- /dev/null +++ b/spec/unit/indirector/run/rest.rb @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +require 'puppet/indirector/runner/rest' + +describe Puppet::Run::Rest do + it "should be a sublcass of Puppet::Indirector::REST" do + Puppet::Run::Rest.superclass.should equal(Puppet::Indirector::REST) + end +end diff --git a/spec/unit/indirector/runner/rest.rb b/spec/unit/indirector/runner/rest.rb deleted file mode 100755 index 61457175d..000000000 --- a/spec/unit/indirector/runner/rest.rb +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env ruby - -require File.dirname(__FILE__) + '/../../../spec_helper' - -require 'puppet/indirector/runner/rest' - -describe Puppet::Agent::Runner::Rest do - it "should be a sublcass of Puppet::Indirector::REST" do - Puppet::Agent::Runner::Rest.superclass.should equal(Puppet::Indirector::REST) - end -end diff --git a/spec/unit/run.rb b/spec/unit/run.rb new file mode 100755 index 000000000..57eff0f98 --- /dev/null +++ b/spec/unit/run.rb @@ -0,0 +1,118 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' +require 'puppet/agent' +require 'puppet/run' + +describe Puppet::Run do + before do + @runner = Puppet::Run.new + end + + it "should indirect :runner" do + Puppet::Run.indirection.name.should == :runner + end + + it "should use a configurer agent as its agent" do + agent = mock 'agent' + Puppet::Agent.expects(:new).with(Puppet::Configurer).returns agent + + @runner.agent.should equal(agent) + end + + it "should accept options at initialization" do + lambda { Puppet::Run.new :background => true }.should_not raise_error + end + + it "should default to running in the foreground" do + Puppet::Run.new.should_not be_background + end + + it "should default to its options being an empty hash" do + Puppet::Run.new.options.should == {} + end + + it "should accept :tags for the agent" do + Puppet::Run.new(:tags => "foo").options[:tags].should == "foo" + end + + it "should accept :ignoreschedules for the agent" do + Puppet::Run.new(:ignoreschedules => true).options[:ignoreschedules].should be_true + end + + it "should accept an option to configure it to run in the background" do + Puppet::Run.new(:background => true).should be_background + end + + it "should retain the background option" do + Puppet::Run.new(:background => true).options[:background].should be_nil + end + + it "should not accept arbitrary options" do + lambda { Puppet::Run.new(:foo => true) }.should raise_error(ArgumentError) + end + + describe "when asked to run" do + before do + @agent = stub 'agent', :run => nil, :running? => false + @runner.stubs(:agent).returns @agent + end + + it "should run its agent" do + agent = stub 'agent2', :running? => false + @runner.stubs(:agent).returns agent + + agent.expects(:run) + + @runner.run + end + + it "should pass any of its options on to the agent" do + @runner.stubs(:options).returns(:foo => :bar) + @agent.expects(:run).with(:foo => :bar) + + @runner.run + end + + it "should log its run using the provided options" do + @runner.expects(:log_run) + + @runner.run + end + + it "should set its status to 'already_running' if the agent is already running" do + @agent.expects(:running?).returns true + + @runner.run + + @runner.status.should == "running" + end + + it "should set its status to 'success' if the agent is run" do + @agent.expects(:running?).returns false + + @runner.run + + @runner.status.should == "success" + end + + it "should run the agent in a thread if asked to run it in the background" do + Thread.expects(:new) + + @runner.expects(:background?).returns true + + @agent.expects(:run).never # because our thread didn't yield + + @runner.run + end + + it "should run the agent directly if asked to run it in the foreground" do + Thread.expects(:new).never + + @runner.expects(:background?).returns false + @agent.expects(:run) + + @runner.run + end + end +end -- cgit