]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/inifile/spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb
add puppetlabs/inifile to 3rdparty
[dsa-puppet.git] / 3rdparty / modules / inifile / spec / unit / puppet / provider / ini_subsetting / ruby_spec.rb
1 require 'spec_helper'
2 require 'puppet'
3
4 provider_class = Puppet::Type.type(:ini_subsetting).provider(:ruby)
5 describe provider_class do
6   include PuppetlabsSpec::Files
7
8   let(:tmpfile) { tmpfilename("ini_setting_test") }
9
10   def validate_file(expected_content,tmpfile = tmpfile)
11     File.read(tmpfile).should == expected_content
12   end
13
14
15   before :each do
16     File.open(tmpfile, 'w') do |fh|
17       fh.write(orig_content)
18     end
19   end
20
21   context "when ensuring that a subsetting is present" do
22     let(:common_params) { {
23         :title    => 'ini_setting_ensure_present_test',
24         :path     => tmpfile,
25         :section  => '',
26         :key_val_separator => '=',
27         :setting => 'JAVA_ARGS',
28     } }
29
30     let(:orig_content) {
31       <<-EOS
32 JAVA_ARGS="-Xmx192m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/pe-puppetdb/puppetdb-oom.hprof"
33       EOS
34     }
35
36     it "should add a missing subsetting" do
37       resource = Puppet::Type::Ini_subsetting.new(common_params.merge(
38          :subsetting => '-Xms', :value => '128m'))
39       provider = described_class.new(resource)
40       provider.exists?.should be_nil
41       provider.create
42       validate_file(<<-EOS
43 JAVA_ARGS="-Xmx192m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/pe-puppetdb/puppetdb-oom.hprof -Xms128m"
44       EOS
45 )
46     end
47
48     it "should remove an existing subsetting" do
49       resource = Puppet::Type::Ini_subsetting.new(common_params.merge(
50           :subsetting => '-Xmx'))
51       provider = described_class.new(resource)
52       provider.exists?.should == "192m"
53       provider.destroy
54       validate_file(<<-EOS
55 JAVA_ARGS="-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/pe-puppetdb/puppetdb-oom.hprof"
56       EOS
57 )
58     end
59     
60     it "should modify an existing subsetting" do
61       resource = Puppet::Type::Ini_subsetting.new(common_params.merge(
62           :subsetting => '-Xmx', :value => '256m'))
63       provider = described_class.new(resource)
64       provider.exists?.should == "192m"
65       provider.value=('256m')
66       validate_file(<<-EOS
67 JAVA_ARGS="-Xmx256m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/pe-puppetdb/puppetdb-oom.hprof"
68       EOS
69 )
70     end
71   end
72
73   context "when working with subsettings in files with unquoted settings values" do
74     let(:common_params) { {
75         :title    => 'ini_setting_ensure_present_test',
76         :path     => tmpfile,
77         :section  => 'master',
78         :setting => 'reports',
79     } }
80
81     let(:orig_content) {
82       <<-EOS
83 [master]
84
85 reports = http,foo
86       EOS
87     }
88
89     it "should remove an existing subsetting" do
90       resource = Puppet::Type::Ini_subsetting.new(common_params.merge(
91           :subsetting => 'http', :subsetting_separator => ','))
92       provider = described_class.new(resource)
93       provider.exists?.should == ""
94       provider.destroy
95       validate_file(<<-EOS
96 [master]
97
98 reports = foo
99       EOS
100       )
101     end
102
103     it "should add a new subsetting when the 'parent' setting already exists" do
104       resource = Puppet::Type::Ini_subsetting.new(common_params.merge(
105           :subsetting => 'puppetdb', :subsetting_separator => ','))
106       provider = described_class.new(resource)
107       provider.exists?.should be_nil
108       provider.value=('')
109       validate_file(<<-EOS
110 [master]
111
112 reports = http,foo,puppetdb
113       EOS
114       )
115     end
116
117     it "should add a new subsetting when the 'parent' setting does not already exist" do
118       resource = Puppet::Type::Ini_subsetting.new(common_params.merge(
119           :setting => 'somenewsetting',
120           :subsetting => 'puppetdb',
121           :subsetting_separator => ','))
122       provider = described_class.new(resource)
123       provider.exists?.should be_nil
124       provider.value=('')
125       validate_file(<<-EOS
126 [master]
127
128 reports = http,foo
129 somenewsetting = puppetdb
130       EOS
131       )
132     end
133
134   end
135 end