summaryrefslogtreecommitdiff
path: root/spec/unit/puppet/provider/ini_setting/ruby_spec.rb
diff options
context:
space:
mode:
authorChris Price <chris@puppetlabs.com>2013-03-11 13:08:01 -0700
committerChris Price <chris@puppetlabs.com>2013-03-11 13:08:01 -0700
commit5fdca54f6e96c861502d6fcff85a563be9d36fa0 (patch)
tree11e92ce0a2028596b1606a004b55811944a523a7 /spec/unit/puppet/provider/ini_setting/ruby_spec.rb
parent2008179ebea70d296f65a1809c961951884a7b11 (diff)
parent2f22483c87dbaee9b45d121a65f2a09dbe638eaa (diff)
downloadpuppet-inifile-5fdca54f6e96c861502d6fcff85a563be9d36fa0.tar.gz
puppet-inifile-5fdca54f6e96c861502d6fcff85a563be9d36fa0.tar.bz2
Merge pull request #25 from bodepd/add_purging_support
Add purging support to ini file
Diffstat (limited to 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb')
-rw-r--r--spec/unit/puppet/provider/ini_setting/ruby_spec.rb78
1 files changed, 78 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 4f8bdc1..7204f88 100644
--- a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb
+++ b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb
@@ -28,6 +28,84 @@ describe provider_class do
end
end
+ context 'when calling instances' do
+
+ let :orig_content do
+ ''
+ end
+
+ it 'should fail when file path is not set' do
+ expect {
+ described_class.instances
+ }.to raise_error(Puppet::Error, 'Ini_settings only support collecting instances when a file path is hard coded')
+ end
+
+ context 'when file path is set' do
+ it 'should return [] when file is empty' do
+ provider_class.stubs(:file_path).returns(emptyfile)
+ provider_class.instances.should == []
+ end
+ it 'should override the provider instances file_path' do
+ provider_class.stubs(:file_path).returns('/some/file/path')
+ resource = Puppet::Type::Ini_setting.new(common_params)
+ provider = provider_class.new(resource)
+ provider.file_path.should == '/some/file/path'
+ end
+ context 'when file has contecnts' do
+ let(:orig_content) {
+ <<-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.1.1:8080
+[section:sub]
+subby=bar
+ #another comment
+ ; yet another comment
+ EOS
+ }
+
+ it 'should be able to parse the results' do
+ provider_class.stubs(:file_path).returns(tmpfile)
+ provider_class.instances.size == 7
+ expected_array = [
+ {:name => 'section1/foo', :value => 'foovalue' },
+ {:name => 'section1/bar', :value => 'barvalue' },
+ {:name => 'section1/master', :value => 'true' },
+ {:name => 'section2/foo', :value => 'foovalue2' },
+ {:name => 'section2/baz', :value => 'bazvalue' },
+ {:name => 'section2/url', :value => 'http://192.168.1.1:8080' },
+ {:name => 'section:sub/subby', :value => 'bar' }
+ ]
+ real_array = []
+ ensure_array = []
+ provider_class.instances.each do |x|
+ prop_hash = x.instance_variable_get(:@property_hash)
+ ensure_value = prop_hash.delete(:ensure)
+ ensure_array.push(ensure_value)
+ real_array.push(prop_hash)
+ end
+ puts ensure_array.inspect
+ puts real_array.inspect
+ ensure_array.uniq.should == [:present]
+ ((real_array - expected_array) && (expected_array - real_array)).should == []
+
+ end
+
+ end
+
+ end
+
+ end
+
context "when ensuring that a setting is present" do
let(:orig_content) {
<<-EOS