|
30 | 30 | File.open(tmpfile, 'w') do |fh| |
31 | 31 | fh.write('foo1') |
32 | 32 | end |
33 | | - expect(provider.exists?).to be_nil |
| 33 | + expect(provider.exists?).to eql (false) |
34 | 34 | end |
35 | 35 | it 'should append to an existing file when creating' do |
36 | 36 | provider.create |
|
70 | 70 | File.open(@tmpfile, 'w') do |fh| |
71 | 71 | fh.write("foo1\nfoo2") |
72 | 72 | end |
73 | | - expect(@provider.exists?).to be_nil |
| 73 | + expect(@provider.exists?).to eql (false) |
74 | 74 | @provider.create |
75 | 75 | expect(File.read(@tmpfile).chomp).to eql("foo1\nfoo2\nfoo = bar") |
76 | 76 | end |
|
113 | 113 | File.open(@tmpfile, 'w') do |fh| |
114 | 114 | fh.write("foo1\nfoo=blah\nfoo2\nfoo=baz") |
115 | 115 | end |
116 | | - expect(@provider.exists?).to be_nil |
| 116 | + expect(@provider.exists?).to eql(false) |
117 | 117 | expect { @provider.create }.to raise_error(Puppet::Error, /More than one line.*matches/) |
118 | 118 | expect(File.read(@tmpfile)).to eql("foo1\nfoo=blah\nfoo2\nfoo=baz") |
119 | 119 | end |
|
132 | 132 | File.open(@tmpfile, 'w') do |fh| |
133 | 133 | fh.write("foo1\nfoo=blah\nfoo2\nfoo=baz") |
134 | 134 | end |
135 | | - expect(@provider.exists?).to be_nil |
| 135 | + expect(@provider.exists?).to eql(false) |
136 | 136 | @provider.create |
137 | 137 | expect(File.read(@tmpfile).chomp).to eql("foo1\nfoo = bar\nfoo2\nfoo = bar") |
138 | 138 | end |
139 | 139 |
|
| 140 | + it 'should replace all lines that match, even when some lines are correct' do |
| 141 | + @resource = Puppet::Type::File_line.new( |
| 142 | + { |
| 143 | + :name => 'neil', |
| 144 | + :path => @tmpfile, |
| 145 | + :line => "\thard\tcore\t0\n", |
| 146 | + :match => '^[ \t]hard[ \t]+core[ \t]+.*', |
| 147 | + :multiple => true, |
| 148 | + } |
| 149 | + ) |
| 150 | + @provider = provider_class.new(@resource) |
| 151 | + File.open(@tmpfile, 'w') do |fh| |
| 152 | + fh.write("\thard\tcore\t90\n\thard\tcore\t0\n") |
| 153 | + end |
| 154 | + expect(@provider.exists?).to eql(false) |
| 155 | + @provider.create |
| 156 | + expect(File.read(@tmpfile).chomp).to eql("\thard\tcore\t0\n\thard\tcore\t0") |
| 157 | + end |
| 158 | + |
140 | 159 | it 'should raise an error with invalid values' do |
141 | 160 | expect { |
142 | 161 | @resource = Puppet::Type::File_line.new( |
|
155 | 174 | File.open(@tmpfile, 'w') do |fh| |
156 | 175 | fh.write("foo1\nfoo=blah\nfoo2") |
157 | 176 | end |
158 | | - expect(@provider.exists?).to be_nil |
| 177 | + expect(@provider.exists?).to eql(false) |
159 | 178 | @provider.create |
160 | 179 | expect(File.read(@tmpfile).chomp).to eql("foo1\nfoo = bar\nfoo2") |
161 | 180 | end |
162 | 181 | it 'should add a new line if no lines match' do |
163 | 182 | File.open(@tmpfile, 'w') do |fh| |
164 | 183 | fh.write("foo1\nfoo2") |
165 | 184 | end |
166 | | - expect(@provider.exists?).to be_nil |
| 185 | + expect(@provider.exists?).to eql(false) |
167 | 186 | @provider.create |
168 | 187 | expect(File.read(@tmpfile)).to eql("foo1\nfoo2\nfoo = bar\n") |
169 | 188 | end |
170 | 189 | it 'should do nothing if the exact line already exists' do |
171 | 190 | File.open(@tmpfile, 'w') do |fh| |
172 | 191 | fh.write("foo1\nfoo = bar\nfoo2") |
173 | 192 | end |
174 | | - expect(@provider.exists?).to be_truthy |
| 193 | + expect(@provider.exists?).to eql(false) |
175 | 194 | @provider.create |
176 | 195 | expect(File.read(@tmpfile).chomp).to eql("foo1\nfoo = bar\nfoo2") |
177 | 196 | end |
|
275 | 294 | } |
276 | 295 | ) |
277 | 296 | @provider = provider_class.new(@resource) |
278 | | - expect(@provider.exists?).to be_nil |
| 297 | + expect(@provider.exists?).to eql (false) |
279 | 298 | @provider.create |
280 | 299 | expect(File.read(@tmpfile).chomp).to eql("foo1\ninserted = line\nfoo = blah\nfoo2\nfoo1\ninserted = line\nfoo = baz") |
281 | 300 | end |
|
368 | 387 | File.open(@tmpfile, 'w') do |fh| |
369 | 388 | fh.write("foo1\nfoo\nfoo2") |
370 | 389 | end |
371 | | - expect(@provider.exists?).to be_truthy |
| 390 | + expect(@provider.exists?).to be_nil |
372 | 391 | end |
373 | 392 |
|
374 | 393 | it 'should remove one line if it matches' do |
|
0 commit comments