diff options
author | Chris Price <chris@puppetlabs.com> | 2012-08-14 13:48:57 -0700 |
---|---|---|
committer | Chris Price <chris@puppetlabs.com> | 2012-08-14 13:48:57 -0700 |
commit | 1740608847714d5a1e500df20ba2df0ffdc07240 (patch) | |
tree | c595fff1d891d4660639448a832cf109c71f0f98 /spec | |
parent | e2954b26c191055fb084162a31d63058677d3026 (diff) | |
parent | 8d2a8c859d928700350d48965dcf01d279289393 (diff) | |
download | puppet-inifile-1740608847714d5a1e500df20ba2df0ffdc07240.tar.gz puppet-inifile-1740608847714d5a1e500df20ba2df0ffdc07240.tar.bz2 |
Merge pull request #4 from stephenrjohnson/miscfixes
Updated Section/ Setting regex, fixed bug with empty files and updated provider to not care about variable type
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/puppet/provider/ini_setting/ruby_spec.rb | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb index 91d3050..72a5da0 100644 --- a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb +++ b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb @@ -6,6 +6,7 @@ describe provider_class do include PuppetlabsSpec::Files let(:tmpfile) { tmpfilename("ini_setting_test") } + let(:emptyfile) { tmpfilename("ini_setting_test_empty") } let(:orig_content) { <<-EOS # This is a comment @@ -14,16 +15,18 @@ describe provider_class do foo=foovalue bar = barvalue +master = true [section2] foo= foovalue2 baz=bazvalue +url = http://192.168.1.1:8080 #another comment ; yet another comment EOS } - def validate_file(expected_content) + def validate_file(expected_content,tmpfile = tmpfile) File.read(tmpfile).should == expected_content end @@ -32,6 +35,9 @@ baz=bazvalue File.open(tmpfile, 'w') do |fh| fh.write(orig_content) end + File.open(emptyfile, 'w') do |fh| + fh.write("") + end end context "when ensuring that a setting is present" do @@ -54,10 +60,12 @@ baz=bazvalue foo=foovalue bar = barvalue +master = true [section2] foo= foovalue2 baz=bazvalue +url = http://192.168.1.1:8080 #another comment ; yet another comment yahoo = yippee @@ -78,16 +86,44 @@ yahoo = yippee foo=foovalue bar = barvalue +master = true [section2] foo= foovalue2 baz = bazvalue2 +url = http://192.168.1.1:8080 #another comment ; yet another comment EOS ) end + it "should be able to handle settings with non alphanumbering settings " do + resource = Puppet::Type::Ini_setting.new(common_params.merge( + :setting => 'url', :value => 'http://192.168.0.1:8080')) + provider = described_class.new(resource) + provider.exists?.should == false + provider.create + + validate_file( <<-EOS +# This is a comment +[section1] +; This is also a comment +foo=foovalue + +bar = barvalue +master = true +[section2] + +foo= foovalue2 +baz=bazvalue +url = http://192.168.0.1:8080 + #another comment + ; yet another comment + EOS + ) + end + it "should recognize an existing setting with the specified value" do resource = Puppet::Type::Ini_setting.new(common_params.merge( :setting => 'baz', :value => 'bazvalue')) @@ -108,10 +144,12 @@ baz = bazvalue2 foo=foovalue bar = barvalue +master = true [section2] foo= foovalue2 baz=bazvalue +url = http://192.168.1.1:8080 #another comment ; yet another comment @@ -120,5 +158,27 @@ huzzah = shazaam EOS ) end + + it "should add a new section if no sections exists" do + resource = Puppet::Type::Ini_setting.new(common_params.merge( + :section => "section1", :setting => 'setting1', :value => 'hellowworld', :path => emptyfile)) + provider = described_class.new(resource) + provider.exists?.should == false + provider.create + validate_file(" +[section1] +setting1 = hellowworld +", emptyfile) + end + + it "should be able to handle variables of any type" do + resource = Puppet::Type::Ini_setting.new(common_params.merge( + :section => "section1", :setting => 'master', :value => true)) + provider = described_class.new(resource) + provider.exists?.should == true + provider.create + end + + end end |