diff options
author | Luke Kanies <luke@madstop.com> | 2009-08-19 11:31:19 -0700 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-08-24 11:36:20 +1000 |
commit | 058514aaf44f981a3239b402f2ff116ebf0d951f (patch) | |
tree | 12ee14aa7e1f693671167c2190ad1021e10d4fee /spec | |
parent | b0f219ad177c8e9c261578586f0324cef0c71cd2 (diff) | |
download | puppet-058514aaf44f981a3239b402f2ff116ebf0d951f.tar.gz puppet-058514aaf44f981a3239b402f2ff116ebf0d951f.tar.xz puppet-058514aaf44f981a3239b402f2ff116ebf0d951f.zip |
Moving Setting classes into separate files
This isn't really a refactor, just moving code around.
I did some simple method renaming, also.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec')
-rwxr-xr-x | spec/integration/defaults.rb | 10 | ||||
-rwxr-xr-x | spec/unit/util/settings.rb | 122 | ||||
-rwxr-xr-x | spec/unit/util/settings/file_setting.rb | 117 |
3 files changed, 128 insertions, 121 deletions
diff --git a/spec/integration/defaults.rb b/spec/integration/defaults.rb index 1a73521bd..b0fd7254a 100755 --- a/spec/integration/defaults.rb +++ b/spec/integration/defaults.rb @@ -39,14 +39,14 @@ describe "Puppet defaults" do # See #1232 it "should not specify a user or group for the clientyamldir" do - Puppet.settings.element(:clientyamldir).owner.should be_nil - Puppet.settings.element(:clientyamldir).group.should be_nil + Puppet.settings.setting(:clientyamldir).owner.should be_nil + Puppet.settings.setting(:clientyamldir).group.should be_nil end # See #1232 it "should not specify a user or group for the rundir" do - Puppet.settings.element(:rundir).owner.should be_nil - Puppet.settings.element(:rundir).group.should be_nil + Puppet.settings.setting(:rundir).owner.should be_nil + Puppet.settings.setting(:rundir).group.should be_nil end it "should use a bind address of ''" do @@ -61,7 +61,7 @@ describe "Puppet defaults" do [:modulepath, :factpath].each do |setting| it "should configure '#{setting}' not to be a file setting, so multi-directory settings are acceptable" do - Puppet.settings.element(setting).should be_instance_of(Puppet::Util::Settings::CElement) + Puppet.settings.setting(setting).should be_instance_of(Puppet::Util::Settings::Setting) end end diff --git a/spec/unit/util/settings.rb b/spec/unit/util/settings.rb index 5e9ab3a18..903779915 100755 --- a/spec/unit/util/settings.rb +++ b/spec/unit/util/settings.rb @@ -47,8 +47,8 @@ describe Puppet::Util::Settings do end it "should support specifying the setting type" do - @settings.setdefaults(:section, :myvalue => {:default => "w", :desc => "b", :type => :element}) - @settings.element(:myvalue).should be_instance_of(Puppet::Util::Settings::CElement) + @settings.setdefaults(:section, :myvalue => {:default => "/w", :desc => "b", :type => :setting}) + @settings.setting(:myvalue).should be_instance_of(Puppet::Util::Settings::Setting) end it "should fail if an invalid setting type is specified" do @@ -161,7 +161,7 @@ describe Puppet::Util::Settings do values.should == %w{test/yay} end - it "should munge values using the element-specific methods" do + it "should munge values using the setting-specific methods" do @settings[:bool] = "false" @settings[:bool].should == false end @@ -602,7 +602,7 @@ describe Puppet::Util::Settings do it "should ignore files whose :to_resource method returns nil" do @settings.setdefaults :main, :maindir => ["/maindir", "a"] - @settings.element(:maindir).expects(:to_resource).returns nil + @settings.setting(:maindir).expects(:to_resource).returns nil Puppet::Resource::Catalog.any_instance.expects(:add_resource).never @settings.to_catalog @@ -708,8 +708,8 @@ describe Puppet::Util::Settings do main.expects(:to_manifest).returns "maindir" second = stub 'second_resource', :ref => "File[/seconddir]" second.expects(:to_manifest).returns "seconddir" - @settings.element(:maindir).expects(:to_resource).returns main - @settings.element(:seconddir).expects(:to_resource).returns second + @settings.setting(:maindir).expects(:to_resource).returns main + @settings.setting(:seconddir).expects(:to_resource).returns second @settings.to_manifest.split("\n\n").sort.should == %w{maindir seconddir} end @@ -967,113 +967,3 @@ describe Puppet::Util::Settings do end end end - -describe Puppet::Util::Settings::CFile do - it "should be able to be converted into a resource" do - Puppet::Util::Settings::CFile.new(:settings => mock("settings"), :desc => "eh").should respond_to(:to_resource) - end - - describe "when being converted to a resource" do - before do - @settings = mock 'settings' - @file = Puppet::Util::Settings::CFile.new(:settings => @settings, :desc => "eh", :name => :mydir, :section => "mysect") - @settings.stubs(:value).with(:mydir).returns "/my/file" - end - - it "should skip files that cannot determine their types" do - @file.expects(:type).returns nil - @file.to_resource.should be_nil - end - - it "should skip non-existent files if 'create_files' is not enabled" do - @file.expects(:create_files?).returns false - @file.expects(:type).returns :file - File.expects(:exist?).with("/my/file").returns false - @file.to_resource.should be_nil - end - - it "should manage existent files even if 'create_files' is not enabled" do - @file.expects(:create_files?).returns false - @file.expects(:type).returns :file - File.expects(:exist?).with("/my/file").returns true - @file.to_resource.should be_instance_of(Puppet::Resource) - end - - it "should skip files in /dev" do - @settings.stubs(:value).with(:mydir).returns "/dev/file" - @file.to_resource.should be_nil - end - - it "should skip files whose paths are not strings" do - @settings.stubs(:value).with(:mydir).returns :foo - @file.to_resource.should be_nil - end - - it "should return a file resource with the path set appropriately" do - resource = @file.to_resource - resource.type.should == "File" - resource.title.should == "/my/file" - end - - it "should fully qualified returned files if necessary (#795)" do - @settings.stubs(:value).with(:mydir).returns "myfile" - @file.to_resource.title.should == File.join(Dir.getwd, "myfile") - end - - it "should set the mode on the file if a mode is provided" do - @file.mode = 0755 - - @file.to_resource[:mode].should == 0755 - end - - it "should set the owner if running as root and the owner is provided" do - Puppet.features.expects(:root?).returns true - @file.stubs(:owner).returns "foo" - @file.to_resource[:owner].should == "foo" - end - - it "should set the group if running as root and the group is provided" do - Puppet.features.expects(:root?).returns true - @file.stubs(:group).returns "foo" - @file.to_resource[:group].should == "foo" - end - - it "should not set owner if not running as root" do - Puppet.features.expects(:root?).returns false - @file.stubs(:owner).returns "foo" - @file.to_resource[:owner].should be_nil - end - - it "should not set group if not running as root" do - Puppet.features.expects(:root?).returns false - @file.stubs(:group).returns "foo" - @file.to_resource[:group].should be_nil - end - - it "should set :ensure to the file type" do - @file.expects(:type).returns :directory - @file.to_resource[:ensure].should == :directory - end - - it "should set the loglevel to :debug" do - @file.to_resource[:loglevel].should == :debug - end - - it "should set the backup to false" do - @file.to_resource[:backup].should be_false - end - - it "should tag the resource with the settings section" do - @file.expects(:section).returns "mysect" - @file.to_resource.should be_tagged("mysect") - end - - it "should tag the resource with the setting name" do - @file.to_resource.should be_tagged("mydir") - end - - it "should tag the resource with 'settings'" do - @file.to_resource.should be_tagged("settings") - end - end -end diff --git a/spec/unit/util/settings/file_setting.rb b/spec/unit/util/settings/file_setting.rb new file mode 100755 index 000000000..2cae56fb7 --- /dev/null +++ b/spec/unit/util/settings/file_setting.rb @@ -0,0 +1,117 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +require 'puppet/util/settings' +require 'puppet/util/settings/file_setting' + +describe Puppet::Util::Settings::FileSetting do + it "should be able to be converted into a resource" do + Puppet::Util::Settings::FileSetting.new(:settings => mock("settings"), :desc => "eh").should respond_to(:to_resource) + end + + describe "when being converted to a resource" do + before do + @settings = mock 'settings' + @file = Puppet::Util::Settings::FileSetting.new(:settings => @settings, :desc => "eh", :name => :mydir, :section => "mysect") + @settings.stubs(:value).with(:mydir).returns "/my/file" + end + + it "should skip files that cannot determine their types" do + @file.expects(:type).returns nil + @file.to_resource.should be_nil + end + + it "should skip non-existent files if 'create_files' is not enabled" do + @file.expects(:create_files?).returns false + @file.expects(:type).returns :file + File.expects(:exist?).with("/my/file").returns false + @file.to_resource.should be_nil + end + + it "should manage existent files even if 'create_files' is not enabled" do + @file.expects(:create_files?).returns false + @file.expects(:type).returns :file + File.expects(:exist?).with("/my/file").returns true + @file.to_resource.should be_instance_of(Puppet::Resource) + end + + it "should skip files in /dev" do + @settings.stubs(:value).with(:mydir).returns "/dev/file" + @file.to_resource.should be_nil + end + + it "should skip files whose paths are not strings" do + @settings.stubs(:value).with(:mydir).returns :foo + @file.to_resource.should be_nil + end + + it "should return a file resource with the path set appropriately" do + resource = @file.to_resource + resource.type.should == "File" + resource.title.should == "/my/file" + end + + it "should fully qualified returned files if necessary (#795)" do + @settings.stubs(:value).with(:mydir).returns "myfile" + @file.to_resource.title.should == File.join(Dir.getwd, "myfile") + end + + it "should set the mode on the file if a mode is provided" do + @file.mode = 0755 + + @file.to_resource[:mode].should == 0755 + end + + it "should set the owner if running as root and the owner is provided" do + Puppet.features.expects(:root?).returns true + @file.stubs(:owner).returns "foo" + @file.to_resource[:owner].should == "foo" + end + + it "should set the group if running as root and the group is provided" do + Puppet.features.expects(:root?).returns true + @file.stubs(:group).returns "foo" + @file.to_resource[:group].should == "foo" + end + + it "should not set owner if not running as root" do + Puppet.features.expects(:root?).returns false + @file.stubs(:owner).returns "foo" + @file.to_resource[:owner].should be_nil + end + + it "should not set group if not running as root" do + Puppet.features.expects(:root?).returns false + @file.stubs(:group).returns "foo" + @file.to_resource[:group].should be_nil + end + + it "should set :ensure to the file type" do + @file.expects(:type).returns :directory + @file.to_resource[:ensure].should == :directory + end + + it "should set the loglevel to :debug" do + @file.to_resource[:loglevel].should == :debug + end + + it "should set the backup to false" do + @file.to_resource[:backup].should be_false + end + + it "should tag the resource with the settings section" do + @file.expects(:section).returns "mysect" + @file.to_resource.should be_tagged("mysect") + end + + it "should tag the resource with the setting name" do + @file.to_resource.should be_tagged("mydir") + end + + it "should tag the resource with 'settings'" do + @file.to_resource.should be_tagged("settings") + end + end +end + |