summaryrefslogtreecommitdiff
path: root/spec/unit/puppet/provider/file_line
diff options
context:
space:
mode:
authortphoney <tp@puppet.com>2017-07-03 17:08:09 +0100
committertphoney <tp@puppet.com>2017-07-03 17:08:09 +0100
commit58131d8ff1886352e964aafef58ffeb65c5d2cdd (patch)
tree58fca90257dd2606c3fc006574134080b8929440 /spec/unit/puppet/provider/file_line
parent517a133209a0b0f8741029c247fea595b50d801e (diff)
(MODULES-5003) file_line fix all broken lines
Diffstat (limited to 'spec/unit/puppet/provider/file_line')
-rwxr-xr-xspec/unit/puppet/provider/file_line/ruby_spec.rb37
1 files changed, 28 insertions, 9 deletions
diff --git a/spec/unit/puppet/provider/file_line/ruby_spec.rb b/spec/unit/puppet/provider/file_line/ruby_spec.rb
index 1f41f62..0e12aa2 100755
--- a/spec/unit/puppet/provider/file_line/ruby_spec.rb
+++ b/spec/unit/puppet/provider/file_line/ruby_spec.rb
@@ -29,7 +29,7 @@ describe provider_class do
File.open(tmpfile, 'w') do |fh|
fh.write('foo1')
end
- expect(provider.exists?).to be_nil
+ expect(provider.exists?).to eql (false)
end
it 'should append to an existing file when creating' do
provider.create
@@ -69,7 +69,7 @@ describe provider_class do
File.open(@tmpfile, 'w') do |fh|
fh.write("foo1\nfoo2")
end
- expect(@provider.exists?).to be_nil
+ expect(@provider.exists?).to eql (false)
@provider.create
expect(File.read(@tmpfile).chomp).to eql("foo1\nfoo2\nfoo = bar")
end
@@ -112,7 +112,7 @@ describe provider_class do
File.open(@tmpfile, 'w') do |fh|
fh.write("foo1\nfoo=blah\nfoo2\nfoo=baz")
end
- expect(@provider.exists?).to be_nil
+ expect(@provider.exists?).to eql(false)
expect { @provider.create }.to raise_error(Puppet::Error, /More than one line.*matches/)
expect(File.read(@tmpfile)).to eql("foo1\nfoo=blah\nfoo2\nfoo=baz")
end
@@ -131,11 +131,30 @@ describe provider_class do
File.open(@tmpfile, 'w') do |fh|
fh.write("foo1\nfoo=blah\nfoo2\nfoo=baz")
end
- expect(@provider.exists?).to be_nil
+ expect(@provider.exists?).to eql(false)
@provider.create
expect(File.read(@tmpfile).chomp).to eql("foo1\nfoo = bar\nfoo2\nfoo = bar")
end
+ it 'should replace all lines that match, even when some lines are correct' do
+ @resource = Puppet::Type::File_line.new(
+ {
+ :name => 'neil',
+ :path => @tmpfile,
+ :line => "\thard\tcore\t0\n",
+ :match => '^[ \t]hard[ \t]+core[ \t]+.*',
+ :multiple => true,
+ }
+ )
+ @provider = provider_class.new(@resource)
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("\thard\tcore\t90\n\thard\tcore\t0\n")
+ end
+ expect(@provider.exists?).to eql(false)
+ @provider.create
+ expect(File.read(@tmpfile).chomp).to eql("\thard\tcore\t0\n\thard\tcore\t0")
+ end
+
it 'should raise an error with invalid values' do
expect {
@resource = Puppet::Type::File_line.new(
@@ -154,7 +173,7 @@ describe provider_class do
File.open(@tmpfile, 'w') do |fh|
fh.write("foo1\nfoo=blah\nfoo2")
end
- expect(@provider.exists?).to be_nil
+ expect(@provider.exists?).to eql(false)
@provider.create
expect(File.read(@tmpfile).chomp).to eql("foo1\nfoo = bar\nfoo2")
end
@@ -162,7 +181,7 @@ describe provider_class do
File.open(@tmpfile, 'w') do |fh|
fh.write("foo1\nfoo2")
end
- expect(@provider.exists?).to be_nil
+ expect(@provider.exists?).to eql(false)
@provider.create
expect(File.read(@tmpfile)).to eql("foo1\nfoo2\nfoo = bar\n")
end
@@ -170,7 +189,7 @@ describe provider_class do
File.open(@tmpfile, 'w') do |fh|
fh.write("foo1\nfoo = bar\nfoo2")
end
- expect(@provider.exists?).to be_truthy
+ expect(@provider.exists?).to eql(false)
@provider.create
expect(File.read(@tmpfile).chomp).to eql("foo1\nfoo = bar\nfoo2")
end
@@ -274,7 +293,7 @@ describe provider_class do
}
)
@provider = provider_class.new(@resource)
- expect(@provider.exists?).to be_nil
+ expect(@provider.exists?).to eql (false)
@provider.create
expect(File.read(@tmpfile).chomp).to eql("foo1\ninserted = line\nfoo = blah\nfoo2\nfoo1\ninserted = line\nfoo = baz")
end
@@ -367,7 +386,7 @@ describe provider_class do
File.open(@tmpfile, 'w') do |fh|
fh.write("foo1\nfoo\nfoo2")
end
- expect(@provider.exists?).to be_truthy
+ expect(@provider.exists?).to be_nil
end
it 'should remove one line if it matches' do