summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohnson Earls <johnson.earls@oracle.com>2016-03-28 20:59:27 +0000
committerJohnson Earls <johnson.earls@oracle.com>2016-03-28 21:26:01 +0000
commit7e408ca7970fd172822db02227935798f9ff282f (patch)
treee285363f922fc6b8f874249f3cbd8bf4c865f16e
parentb63849c7865e4191e9df5a7651c16c072facee3d (diff)
[MODULES-2370] file_line.rb: Fix `line` attribute validation
`file_line` type: During validation, do not require `line` attribute if: * `ensure` is `absent`, * `match` is not empty, * and `match_for_absence` is `true`. Also update `spec` tests to reflect this.
-rw-r--r--lib/puppet/type/file_line.rb9
-rwxr-xr-xspec/unit/puppet/type/file_line_spec.rb7
2 files changed, 12 insertions, 4 deletions
diff --git a/lib/puppet/type/file_line.rb b/lib/puppet/type/file_line.rb
index 77d3be2..f2c6937 100644
--- a/lib/puppet/type/file_line.rb
+++ b/lib/puppet/type/file_line.rb
@@ -111,8 +111,13 @@ Puppet::Type.newtype(:file_line) do
end
validate do
- unless self[:line] and self[:path]
- raise(Puppet::Error, "Both line and path are required attributes")
+ unless self[:line]
+ unless (self[:ensure].to_s == 'absent') and (self[:match_for_absence].to_s == 'true') and self[:match]
+ raise(Puppet::Error, "line is a required attribute")
+ end
+ end
+ unless self[:path]
+ raise(Puppet::Error, "path is a required attribute")
end
end
end
diff --git a/spec/unit/puppet/type/file_line_spec.rb b/spec/unit/puppet/type/file_line_spec.rb
index f1430f2..48e2670 100755
--- a/spec/unit/puppet/type/file_line_spec.rb
+++ b/spec/unit/puppet/type/file_line_spec.rb
@@ -41,10 +41,13 @@ describe Puppet::Type.type(:file_line) do
expect { file_line[:path] = 'file' }.to raise_error(Puppet::Error, /File paths must be fully qualified/)
end
it 'should require that a line is specified' do
- expect { Puppet::Type.type(:file_line).new(:name => 'foo', :path => '/tmp/file') }.to raise_error(Puppet::Error, /Both line and path are required attributes/)
+ expect { Puppet::Type.type(:file_line).new(:name => 'foo', :path => '/tmp/file') }.to raise_error(Puppet::Error, /line is a required attribute/)
+ end
+ it 'should not require that a line is specified when matching for absence' do
+ expect { Puppet::Type.type(:file_line).new(:name => 'foo', :path => '/tmp/file', :ensure => :absent, :match_for_absence => :true, :match => 'match') }.not_to raise_error
end
it 'should require that a file is specified' do
- expect { Puppet::Type.type(:file_line).new(:name => 'foo', :line => 'path') }.to raise_error(Puppet::Error, /Both line and path are required attributes/)
+ expect { Puppet::Type.type(:file_line).new(:name => 'foo', :line => 'path') }.to raise_error(Puppet::Error, /path is a required attribute/)
end
it 'should default to ensure => present' do
expect(file_line[:ensure]).to eq :present