diff options
Diffstat (limited to 'spec/unit')
-rw-r--r-- | spec/unit/puppet/provider/ini_setting/ruby_spec.rb | 40 | ||||
-rw-r--r-- | spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb | 73 | ||||
-rw-r--r-- | spec/unit/puppet/util/setting_value_spec.rb | 69 |
3 files changed, 182 insertions, 0 deletions
diff --git a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb index 2ad64b8..ea24968 100644 --- a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb +++ b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb @@ -899,6 +899,46 @@ blah = blah ) end + context 'when a section only contains comments' do + let(:orig_content) { + <<-EOS +[section1] +# foo=foovalue +# bar=bar2 +EOS + } + it 'should be able to add a new setting when a section contains only comments' do + resource = Puppet::Type::Ini_setting.new( + common_params.merge(:section => 'section1', :setting => 'foo', :value => 'foovalue2') + ) + provider = described_class.new(resource) + provider.exists?.should be_false + provider.create + validate_file(<<-EOS +[section1] +# foo=foovalue +foo=foovalue2 +# bar=bar2 + EOS + ) + end + it 'should be able to add a new setting when it matches a commented out line other than the first one' do + resource = Puppet::Type::Ini_setting.new( + common_params.merge(:section => 'section1', :setting => 'bar', :value => 'barvalue2') + ) + provider = described_class.new(resource) + provider.exists?.should be_false + provider.create + validate_file(<<-EOS +[section1] +# foo=foovalue +# bar=bar2 +bar=barvalue2 + EOS + ) + end + end + end end diff --git a/spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb b/spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb new file mode 100644 index 0000000..9d12d61 --- /dev/null +++ b/spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb @@ -0,0 +1,73 @@ +require 'spec_helper' +require 'puppet' + +provider_class = Puppet::Type.type(:ini_subsetting).provider(:ruby) +describe provider_class do + include PuppetlabsSpec::Files + + let(:tmpfile) { tmpfilename("ini_setting_test") } + + let(:common_params) { { + :title => 'ini_setting_ensure_present_test', + :path => tmpfile, + :section => '', + :key_val_separator => '=', + :setting => 'JAVA_ARGS', + } } + + def validate_file(expected_content,tmpfile = tmpfile) + File.read(tmpfile).should == expected_content + end + + + before :each do + File.open(tmpfile, 'w') do |fh| + fh.write(orig_content) + end + end + + context "when ensuring that a subsetting is present" do + let(:orig_content) { + <<-EOS +JAVA_ARGS="-Xmx192m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/pe-puppetdb/puppetdb-oom.hprof" + EOS + } + + it "should add a missing subsetting" do + resource = Puppet::Type::Ini_subsetting.new(common_params.merge( + :subsetting => '-Xms', :value => '128m')) + provider = described_class.new(resource) + provider.exists?.should be_nil + provider.create + validate_file(<<-EOS +JAVA_ARGS="-Xmx192m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/pe-puppetdb/puppetdb-oom.hprof -Xms128m" + EOS +) + end + + it "should remove an existing subsetting" do + resource = Puppet::Type::Ini_subsetting.new(common_params.merge( + :subsetting => '-Xmx')) + provider = described_class.new(resource) + provider.exists?.should == "192m" + provider.destroy + validate_file(<<-EOS +JAVA_ARGS="-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/pe-puppetdb/puppetdb-oom.hprof" + EOS +) + end + + it "should modify an existing subsetting" do + resource = Puppet::Type::Ini_subsetting.new(common_params.merge( + :subsetting => '-Xmx', :value => '256m')) + provider = described_class.new(resource) + provider.exists?.should == "192m" + provider.value=('256m') + validate_file(<<-EOS +JAVA_ARGS="-Xmx256m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/pe-puppetdb/puppetdb-oom.hprof" + EOS +) + end + + end +end diff --git a/spec/unit/puppet/util/setting_value_spec.rb b/spec/unit/puppet/util/setting_value_spec.rb new file mode 100644 index 0000000..6148396 --- /dev/null +++ b/spec/unit/puppet/util/setting_value_spec.rb @@ -0,0 +1,69 @@ +require 'spec_helper' +require 'puppet/util/setting_value' + +describe Puppet::Util::SettingValue do + + describe "space subsetting separator" do + INIT_VALUE_SPACE = "\"-Xmx192m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/pe-puppetdb/puppetdb-oom.hprof\"" + + before :each do + @setting_value = Puppet::Util::SettingValue.new(INIT_VALUE_SPACE, " ") + end + + it "should get the original value" do + @setting_value.get_value.should == INIT_VALUE_SPACE + end + + it "should get the correct value" do + @setting_value.get_subsetting_value("-Xmx").should == "192m" + end + + it "should add a new value" do + @setting_value.add_subsetting("-Xms", "256m") + @setting_value.get_subsetting_value("-Xms").should == "256m" + @setting_value.get_value.should == INIT_VALUE_SPACE[0, INIT_VALUE_SPACE.length - 1] + " -Xms256m\"" + end + + it "should change existing value" do + @setting_value.add_subsetting("-Xmx", "512m") + @setting_value.get_subsetting_value("-Xmx").should == "512m" + end + + it "should remove existing value" do + @setting_value.remove_subsetting("-Xmx") + @setting_value.get_subsetting_value("-Xmx").should == nil + end + end + + describe "comma subsetting separator" do + INIT_VALUE_COMMA = "\"-Xmx192m,-XX:+HeapDumpOnOutOfMemoryError,-XX:HeapDumpPath=/var/log/pe-puppetdb/puppetdb-oom.hprof\"" + + before :each do + @setting_value = Puppet::Util::SettingValue.new(INIT_VALUE_COMMA, ",") + end + + it "should get the original value" do + @setting_value.get_value.should == INIT_VALUE_COMMA + end + + it "should get the correct value" do + @setting_value.get_subsetting_value("-Xmx").should == "192m" + end + + it "should add a new value" do + @setting_value.add_subsetting("-Xms", "256m") + @setting_value.get_subsetting_value("-Xms").should == "256m" + @setting_value.get_value.should == INIT_VALUE_COMMA[0, INIT_VALUE_COMMA.length - 1] + ",-Xms256m\"" + end + + it "should change existing value" do + @setting_value.add_subsetting("-Xmx", "512m") + @setting_value.get_subsetting_value("-Xmx").should == "512m" + end + + it "should remove existing value" do + @setting_value.remove_subsetting("-Xmx") + @setting_value.get_subsetting_value("-Xmx").should == nil + end + end +end |