diff options
| author | Matt Robinson <matt@puppetlabs.com> | 2010-06-30 12:43:23 -0700 |
|---|---|---|
| committer | Markus Roberts <Markus@reality.com> | 2010-07-01 13:48:03 -0700 |
| commit | 2a2588392a2eead4265afcb93ff7bc16b5fc1ef1 (patch) | |
| tree | 128c7039ced805af716cd49c25690634de5243ad /spec | |
| parent | 75e0662168936da8255507a10bccad8889326947 (diff) | |
[#4090] Git rid of the idea that run_mode is a configurable option with defaults
Along the way this fixes an issue with 2.6 alpha that sections of the
puppet config file were getting ignored.
Diffstat (limited to 'spec')
| -rwxr-xr-x | spec/unit/application/agent_spec.rb | 25 | ||||
| -rwxr-xr-x | spec/unit/application_spec.rb | 14 | ||||
| -rwxr-xr-x | spec/unit/util/settings_spec.rb | 36 |
3 files changed, 66 insertions, 9 deletions
diff --git a/spec/unit/application/agent_spec.rb b/spec/unit/application/agent_spec.rb index 76a378e82..21f5143bd 100755 --- a/spec/unit/application/agent_spec.rb +++ b/spec/unit/application/agent_spec.rb @@ -8,6 +8,31 @@ require 'puppet/network/server' require 'puppet/daemon' describe Puppet::Application::Agent do + it "should ask Puppet::Application to parse Puppet configuration file" do + agent = Puppet::Application::Agent.new + agent.preinit + + Puppet[:vardir].should == '/dev/null' + Puppet[:report].should be_false + + text = <<-CONF + [main] + vardir='/foo/bar' + [puppetd] + report=true + CONF + + FileTest.expects(:exist?).with('file').returns true + Puppet.settings.expects(:read_file).returns(text) + + Puppet.settings.unsafe_parse('file') + + Puppet[:vardir].should == '/foo/bar' + Puppet[:report].should be_true + end +end + +describe Puppet::Application::Agent do before :each do @puppetd = Puppet::Application[:agent] @puppetd.stubs(:puts) diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb index 9dc655d14..87424fb5d 100755 --- a/spec/unit/application_spec.rb +++ b/spec/unit/application_spec.rb @@ -10,11 +10,23 @@ describe Puppet::Application do before do @app = Class.new(Puppet::Application).new + @appclass = @app.class # avoid actually trying to parse any settings Puppet.settings.stubs(:parse) end + describe ".run_mode" do + it "should default to user" do + @appclass.run_mode.name.should == :user + end + + it "should set and get a value" do + @appclass.run_mode :agent + @appclass.run_mode.name.should == :agent + end + end + it "should have a run entry-point" do @app.should respond_to(:run) end @@ -150,7 +162,7 @@ describe Puppet::Application do describe 'on POSIX systems' do confine "HUP works only on POSIX systems" => Puppet.features.posix? - + it 'should signal process with HUP after block if restart requested during block execution' do Puppet::Application.run_status = nil target = mock 'target' diff --git a/spec/unit/util/settings_spec.rb b/spec/unit/util/settings_spec.rb index 1e694a407..9aeed60f8 100755 --- a/spec/unit/util/settings_spec.rb +++ b/spec/unit/util/settings_spec.rb @@ -274,11 +274,18 @@ describe Puppet::Util::Settings do @settings.value(:one, "env2").should == "twoval" end - it "should have a run_mode determined by the 'run_mode' parameter that cannot be edited" do + it "should have a run_mode that defaults to user" do + @settings.run_mode.should == :user + end + + it "should not give a shit if you set a default run_mode yourself" do @settings.setdefaults(:whatever, :run_mode => ["something", "yayness"]) - @settings.run_mode.should == :something + lambda{ @settings[:run_mode] = :other }.should raise_error(ArgumentError, /read-only/) + end - lambda{ @settings[:run_mode] = :other }.should raise_error + it "CURRENTLY should not allow the user to set a run_mode default" do + @settings.setdefaults(:whatever, :run_mode => ["something", "yayness"]) + @settings.run_mode.should == :user end end @@ -286,10 +293,10 @@ describe Puppet::Util::Settings do before do @settings = Puppet::Util::Settings.new @settings.setdefaults :section, - :config => ["/my/file", "a"], - :one => ["ONE", "a" ], - :run_mode => ["mymode", "w" ] + :config => ["/my/file", "a"], + :one => ["ONE", "a"] FileTest.stubs(:exist?).returns true + Puppet.stubs(:run_mode).returns stub('run_mode', :name => :mymode) end it "should return default values if no values have been set" do @@ -358,6 +365,19 @@ describe Puppet::Util::Settings do FileTest.stubs(:exist?).returns true end + it "should not ignore the report setting" do + @settings.setdefaults :section, :report => ["false", "a"] + myfile = stub "myfile" + @settings[:config] = myfile + text = <<-CONF + [puppetd] + report=true + CONF + @settings.expects(:read_file).returns(text) + @settings.parse + @settings[:report].should be_true + end + it "should use its current ':config' value for the file to parse" do myfile = Puppet.features.posix? ? "/my/file" : "C:/myfile" # do not stub expand_path here, as this leads to a stack overflow, when mocha tries to use it @settings[:config] = myfile @@ -464,9 +484,9 @@ describe Puppet::Util::Settings do values = [] @settings.setdefaults :section, :mysetting => {:default => "defval", :desc => "a", :hook => proc { |v| values << v }} - text = "[main] + text = "[user] mysetting = setval - [puppet] + [main] mysetting = other " @settings.expects(:read_file).returns(text) |
