1 #! /usr/bin/env ruby -S rspec
4 describe Puppet::Type.type(:file_line) do
6 Puppet::Type.type(:file_line).new(:name => 'foo', :line => 'line', :path => '/tmp/path')
8 it 'should accept a line and path' do
9 file_line[:line] = 'my_line'
10 expect(file_line[:line]).to eq('my_line')
11 file_line[:path] = '/my/path'
12 expect(file_line[:path]).to eq('/my/path')
14 it 'should accept a match regex' do
15 file_line[:match] = '^foo.*$'
16 expect(file_line[:match]).to eq('^foo.*$')
18 it 'should accept a match regex that does not match the specified line' do
20 Puppet::Type.type(:file_line).new(
24 :match => '^bar=blah$'
27 it 'should accept a match regex that does match the specified line' do
29 Puppet::Type.type(:file_line).new(
33 :match => '^\s*foo=.*$'
36 it 'should accept posix filenames' do
37 file_line[:path] = '/tmp/path'
38 expect(file_line[:path]).to eq('/tmp/path')
40 it 'should not accept unqualified path' do
41 expect { file_line[:path] = 'file' }.to raise_error(Puppet::Error, /File paths must be fully qualified/)
43 it 'should require that a line is specified' do
44 expect { Puppet::Type.type(:file_line).new(:name => 'foo', :path => '/tmp/file') }.to raise_error(Puppet::Error, /Both line and path are required attributes/)
46 it 'should require that a file is specified' do
47 expect { Puppet::Type.type(:file_line).new(:name => 'foo', :line => 'path') }.to raise_error(Puppet::Error, /Both line and path are required attributes/)
49 it 'should default to ensure => present' do
50 expect(file_line[:ensure]).to eq :present
53 it "should autorequire the file it manages" do
54 catalog = Puppet::Resource::Catalog.new
55 file = Puppet::Type.type(:file).new(:name => "/tmp/path")
56 catalog.add_resource file
57 catalog.add_resource file_line
59 relationship = file_line.autorequire.find do |rel|
60 (rel.source.to_s == "File[/tmp/path]") and (rel.target.to_s == file_line.to_s)
62 expect(relationship).to be_a Puppet::Relationship
65 it "should not autorequire the file it manages if it is not managed" do
66 catalog = Puppet::Resource::Catalog.new
67 catalog.add_resource file_line
68 expect(file_line.autorequire).to be_empty