summaryrefslogtreecommitdiff
path: root/spec/unit/puppet/provider/file_line/ruby_spec.rb
diff options
context:
space:
mode:
authorTP Honey <tphoney@users.noreply.github.com>2017-10-02 10:27:40 +0100
committerGitHub <noreply@github.com>2017-10-02 10:27:40 +0100
commit2339ea8db67ac7ef02d707c2a6011ae50f5d82b5 (patch)
tree4b601143c1d4e665e8a715596bfb5fbd87f17801 /spec/unit/puppet/provider/file_line/ruby_spec.rb
parent2b2b3870ec1737dc78ec402c2dccbb7b65a2ef8f (diff)
parentad5d92461596d8d0b1c001d49061d70b36761d59 (diff)
Merge pull request #820 from alexharv074/maint_clarify_docs
(maint) Clarify docs and add new tests
Diffstat (limited to 'spec/unit/puppet/provider/file_line/ruby_spec.rb')
-rwxr-xr-xspec/unit/puppet/provider/file_line/ruby_spec.rb91
1 files changed, 89 insertions, 2 deletions
diff --git a/spec/unit/puppet/provider/file_line/ruby_spec.rb b/spec/unit/puppet/provider/file_line/ruby_spec.rb
index dcca4a4..4ec9bae 100755
--- a/spec/unit/puppet/provider/file_line/ruby_spec.rb
+++ b/spec/unit/puppet/provider/file_line/ruby_spec.rb
@@ -337,7 +337,7 @@ describe provider_class, :unless => Puppet::Util::Platform.windows? do
end
end
- context "when removing" do
+ context "when removing with a line" 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:
@@ -378,6 +378,23 @@ describe provider_class, :unless => Puppet::Util::Platform.windows? do
@provider.destroy
expect(File.read(@tmpfile)).to eql("foo1\nfoo2\n")
end
+
+ it 'example in the docs' do
+ @resource = Puppet::Type::File_line.new(
+ {
+ :name => 'bashrc_proxy',
+ :ensure => 'absent',
+ :path => @tmpfile,
+ :line => 'export HTTP_PROXY=http://squid.puppetlabs.vm:3128',
+ }
+ )
+ @provider = provider_class.new(@resource)
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo2\nexport HTTP_PROXY=http://squid.puppetlabs.vm:3128\nfoo4\n")
+ end
+ @provider.destroy
+ expect(File.read(@tmpfile)).to eql("foo1\nfoo2\nfoo4\n")
+ end
end
context "when removing with a match" do
@@ -416,6 +433,41 @@ describe provider_class, :unless => Puppet::Util::Platform.windows? do
expect(File.read(@tmpfile)).to eql("foo1\nfoo2")
end
+ it 'the line parameter is actually not used at all but is silently ignored if here' do
+ @resource = Puppet::Type::File_line.new(
+ {
+ :name => 'foo',
+ :path => @tmpfile,
+ :line => 'supercalifragilisticexpialidocious',
+ :ensure => 'absent',
+ :match => 'o$',
+ :match_for_absence => true,
+ }
+ )
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo\nfoo2")
+ end
+ @provider.destroy
+ expect(File.read(@tmpfile)).to eql("foo1\nfoo2")
+ end
+
+ it 'and may not be here and does not need to be here' do
+ @resource = Puppet::Type::File_line.new(
+ {
+ :name => 'foo',
+ :path => @tmpfile,
+ :ensure => 'absent',
+ :match => 'o$',
+ :match_for_absence => true,
+ }
+ )
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo\nfoo2")
+ end
+ @provider.destroy
+ expect(File.read(@tmpfile)).to eql("foo1\nfoo2")
+ end
+
it 'should raise an error if more than one line matches' do
File.open(@tmpfile, 'w') do |fh|
fh.write("foo1\nfoo\nfoo2\nfoo\nfoo")
@@ -480,6 +532,41 @@ describe provider_class, :unless => Puppet::Util::Platform.windows? do
expect(File.read(@tmpfile)).to eql("foo1\nfoo\n")
end
- end
+ it 'example in the docs' do
+ @resource = Puppet::Type::File_line.new(
+ {
+ :name => 'bashrc_proxy',
+ :ensure => 'absent',
+ :path => @tmpfile,
+ :line => 'export HTTP_PROXY=http://squid.puppetlabs.vm:3128',
+ :match => '^export\ HTTP_PROXY\=',
+ :match_for_absence => true,
+ }
+ )
+ @provider = provider_class.new(@resource)
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo2\nexport HTTP_PROXY=foo\nfoo4\n")
+ end
+ @provider.destroy
+ expect(File.read(@tmpfile)).to eql("foo1\nfoo2\nfoo4\n")
+ end
+ it 'example in the docs showing line is redundant' do
+ @resource = Puppet::Type::File_line.new(
+ {
+ :name => 'bashrc_proxy',
+ :ensure => 'absent',
+ :path => @tmpfile,
+ :match => '^export\ HTTP_PROXY\=',
+ :match_for_absence => true,
+ }
+ )
+ @provider = provider_class.new(@resource)
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo2\nexport HTTP_PROXY=foo\nfoo4\n")
+ end
+ @provider.destroy
+ expect(File.read(@tmpfile)).to eql("foo1\nfoo2\nfoo4\n")
+ end
+ end
end