summaryrefslogtreecommitdiff
path: root/spec/unit/puppet
diff options
context:
space:
mode:
authorDan Prince <dprince@redhat.com>2013-08-29 12:19:16 -0400
committerJeff McCune <jeff@puppetlabs.com>2013-08-29 15:07:29 -0700
commit221277e8522b42bf170fded6ea23dfc526703b07 (patch)
tree51abab0793eb3ef67431889330c2e7b28383f1d1 /spec/unit/puppet
parent806430224ad0da860be3761ab83f1e574b64fc60 (diff)
downloadpuppet-stdlib-221277e8522b42bf170fded6ea23dfc526703b07.tar.gz
puppet-stdlib-221277e8522b42bf170fded6ea23dfc526703b07.tar.bz2
Update file_line resource to support 'after'.
When adding new lines to a file the 'after' option can be useful when you need to insert file lines into the middle of a file. This is particularly helpful when using file_line with sectioned config files. NOTE: the after option only works when adding new lines. If you are updating an existing (matched) line it will simply modify it in place. This assumes it was in the right place to begin with.
Diffstat (limited to 'spec/unit/puppet')
-rw-r--r--spec/unit/puppet/provider/file_line/ruby_spec.rb18
1 files changed, 18 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 648c05b..c8575ab 100644
--- a/spec/unit/puppet/provider/file_line/ruby_spec.rb
+++ b/spec/unit/puppet/provider/file_line/ruby_spec.rb
@@ -80,6 +80,24 @@ describe provider_class do
File.read(@tmpfile).chomp.should eql("foo1\nfoo = bar\nfoo2\nfoo = bar")
end
+ it 'should replace all lines that matches with after' do
+ @resource = Puppet::Type::File_line.new(
+ {
+ :name => 'foo',
+ :path => @tmpfile,
+ :line => 'inserted = line',
+ :after => '^foo1',
+ }
+ )
+ @provider = provider_class.new(@resource)
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo = blah\nfoo2\nfoo = baz")
+ end
+ @provider.exists?.should be_nil
+ @provider.create
+ File.read(@tmpfile).chomp.should eql("foo1\ninserted = line\nfoo = blah\nfoo2\nfoo = baz")
+ end
+
it 'should raise an error with invalid values' do
expect {
@resource = Puppet::Type::File_line.new(