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