summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorBryan Jen <bryan.jen@gmail.com>2015-07-30 13:34:26 -0700
committerBryan Jen <bryan.jen@gmail.com>2015-07-30 13:34:26 -0700
commitebf73482e55c827bcb46b7d6b479ae7afd3628af (patch)
tree0cbc3b9ca06e8057c220131ef5d06d95ae29c139 /spec
parent41a7297cb73e48a9548d7d0137f2ffe4108f248a (diff)
parent35e92645f727f02ef9ace8948154079bc0fff05a (diff)
Merge pull request #494 from CENGN/fix/master/file_line_replace
[#puppethack] Adding replace attribute to file_line
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/puppet/provider/file_line/ruby_spec.rb51
-rwxr-xr-xspec/unit/puppet/type/file_line_spec.rb3
2 files changed, 54 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
diff --git a/spec/unit/puppet/type/file_line_spec.rb b/spec/unit/puppet/type/file_line_spec.rb
index 410d0bf..58c88e3 100755
--- a/spec/unit/puppet/type/file_line_spec.rb
+++ b/spec/unit/puppet/type/file_line_spec.rb
@@ -49,6 +49,9 @@ describe Puppet::Type.type(:file_line) do
it 'should default to ensure => present' do
expect(file_line[:ensure]).to eq :present
end
+ it 'should default to replace => true' do
+ expect(file_line[:replace]).to eq true
+ end
it "should autorequire the file it manages" do
catalog = Puppet::Resource::Catalog.new