3 provider_class = Puppet::Type.type(:file_line).provider(:ruby)
4 # These tests fail on windows when run as part of the rake task. Individually they pass
5 describe provider_class, :unless => Puppet::Util::Platform.windows? do
6 include PuppetlabsSpec::Files
9 tmpfilename('file_line_test')
18 Puppet::Type::File_line.new({
25 provider_class.new(resource)
29 File.open(tmpfile, 'w') do |fh|
34 describe 'customer use cases - no lines' do
35 describe 'MODULES-5003' do
38 :line => "*\thard\tcore\t0",
39 :match => "^[ \t]*\\*[ \t]+hard[ \t]+core[ \t]+.*",
43 let(:content) { "* hard core 90\n* hard core 10\n" }
45 it 'requests changes' do
46 expect(provider).not_to be_exists
48 it 'replaces the matches' do
50 expect(File.read(tmpfile).chomp).to eq("* hard core 0\n* hard core 0")
54 describe 'MODULES-5003 - one match, one line - just ensure the line exists' do
57 :line => "*\thard\tcore\t0",
58 :match => "^[ \t]*\\*[ \t]+hard[ \t]+core[ \t]+.*",
62 let(:content) { "* hard core 90\n* hard core 0\n" }
64 it 'does not request changes' do
65 expect(provider).to be_exists
69 describe 'MODULES-5003 - one match, one line - replace all matches, even when line exists' do
72 :line => "*\thard\tcore\t0",
73 :match => "^[ \t]*\\*[ \t]+hard[ \t]+core[ \t]+.*",
76 }.merge(:replace_all_matches_not_matching_line => true)
78 let(:content) { "* hard core 90\n* hard core 0\n" }
80 it 'requests changes' do
81 expect(provider).not_to be_exists
83 it 'replaces the matches' do
85 expect(File.read(tmpfile).chomp).to eq("* hard core 0\n* hard core 0")
89 describe 'MODULES-5651 - match, no line' do
92 :line => 'LogLevel=notice',
93 :match => '^#LogLevel$',
96 let(:content) { "#LogLevel\nstuff" }
98 it 'requests changes' do
99 expect(provider).not_to be_exists
101 it 'replaces the match' do
103 expect(File.read(tmpfile).chomp).to eq("LogLevel=notice\nstuff")
107 describe 'MODULES-5651 - match, line' do
110 :line => 'LogLevel=notice',
111 :match => '^#LogLevel$',
114 let(:content) { "#Loglevel\nLogLevel=notice\nstuff" }
116 it 'does not request changes' do
117 expect(provider).to be_exists
121 describe 'MODULES-5651 - no match, line' do
124 :line => 'LogLevel=notice',
125 :match => '^#LogLevel$',
128 let(:content) { "LogLevel=notice\nstuff" }
130 it 'does not request changes' do
131 expect(provider).to be_exists