From 4351d8b9c8dac40f0f733fd7622d655241f113ba Mon Sep 17 00:00:00 2001 From: Karel Brezina Date: Fri, 15 Feb 2013 10:56:44 +0100 Subject: Added 'ini_subsetting' custom resource type --- .../puppet/provider/ini_subsetting/ruby_spec.rb | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb (limited to 'spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb') 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 -- cgit v1.2.3