summaryrefslogtreecommitdiff
path: root/spec/unit/puppet/provider/file_line/ruby_spec.rb
diff options
context:
space:
mode:
authorRaymond Maika <rmaika@patientway.com>2015-07-30 14:05:39 -0400
committerRaymond Maika <raymond.maika@cengn.ca>2015-07-30 14:55:32 -0400
commit35e92645f727f02ef9ace8948154079bc0fff05a (patch)
tree1d9c42cc6ea5a89b159cdd1329aedd7c502bb699 /spec/unit/puppet/provider/file_line/ruby_spec.rb
parent4d889cbcb6f5eb2358eed940f2d40d1f73cc8f51 (diff)
(MODULES-2024) Adding replace attribute to file_line
Diffstat (limited to 'spec/unit/puppet/provider/file_line/ruby_spec.rb')
-rwxr-xr-xspec/unit/puppet/provider/file_line/ruby_spec.rb51
1 files changed, 51 insertions, 0 deletions
diff --git a/spec/unit/puppet/provider/file_line/ruby_spec.rb b/spec/unit/puppet/provider/file_line/ruby_spec.rb
index 8fe3932..5eff09a 100755
--- a/spec/unit/puppet/provider/file_line/ruby_spec.rb
+++ b/spec/unit/puppet/provider/file_line/ruby_spec.rb
@@ -36,7 +36,58 @@ describe provider_class do
expect(File.read(tmpfile).chomp).to eq('foo')
end
end
+ context 'when using replace' do
+ before :each do
+ # TODO: these should be ported over to use the PuppetLabs spec_helper
+ # file fixtures once the following pull request has been merged:
+ # https://github.com/puppetlabs/puppetlabs-stdlib/pull/73/files
+ tmp = Tempfile.new('tmp')
+ @tmpfile = tmp.path
+ tmp.close!
+ @resource = Puppet::Type::File_line.new(
+ {
+ :name => 'foo',
+ :path => @tmpfile,
+ :line => 'foo = bar',
+ :match => '^foo\s*=.*$',
+ :replace => false,
+ }
+ )
+ @provider = provider_class.new(@resource)
+ end
+ it 'should not replace the matching line' do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo=blah\nfoo2\nfoo3")
+ end
+ expect(@provider.exists?).to be_truthy
+ @provider.create
+ expect(File.read(@tmpfile).chomp).to eql("foo1\nfoo=blah\nfoo2\nfoo3")
+ end
+
+ it 'should append the line if no matches are found' do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo2")
+ end
+ expect(@provider.exists?).to be_nil
+ @provider.create
+ expect(File.read(@tmpfile).chomp).to eql("foo1\nfoo2\nfoo = bar")
+ end
+
+ it 'should raise an error with invalid values' do
+ expect {
+ @resource = Puppet::Type::File_line.new(
+ {
+ :name => 'foo',
+ :path => @tmpfile,
+ :line => 'foo = bar',
+ :match => '^foo\s*=.*$',
+ :replace => 'asgadga',
+ }
+ )
+ }.to raise_error(Puppet::Error, /Invalid value "asgadga"\. Valid values are true, false, yes, no\./)
+ end
+ end
context "when matching" do
before :each do
# TODO: these should be ported over to use the PuppetLabs spec_helper