|
36 | 36 | expect(File.read(tmpfile).chomp).to eq('foo') |
37 | 37 | end |
38 | 38 | end |
| 39 | + context 'when using replace' do |
| 40 | + before :each do |
| 41 | + # TODO: these should be ported over to use the PuppetLabs spec_helper |
| 42 | + # file fixtures once the following pull request has been merged: |
| 43 | + # https://github.com/puppetlabs/puppetlabs-stdlib/pull/73/files |
| 44 | + tmp = Tempfile.new('tmp') |
| 45 | + @tmpfile = tmp.path |
| 46 | + tmp.close! |
| 47 | + @resource = Puppet::Type::File_line.new( |
| 48 | + { |
| 49 | + :name => 'foo', |
| 50 | + :path => @tmpfile, |
| 51 | + :line => 'foo = bar', |
| 52 | + :match => '^foo\s*=.*$', |
| 53 | + :replace => false, |
| 54 | + } |
| 55 | + ) |
| 56 | + @provider = provider_class.new(@resource) |
| 57 | + end |
39 | 58 |
|
| 59 | + it 'should not replace the matching line' do |
| 60 | + File.open(@tmpfile, 'w') do |fh| |
| 61 | + fh.write("foo1\nfoo=blah\nfoo2\nfoo3") |
| 62 | + end |
| 63 | + expect(@provider.exists?).to be_truthy |
| 64 | + @provider.create |
| 65 | + expect(File.read(@tmpfile).chomp).to eql("foo1\nfoo=blah\nfoo2\nfoo3") |
| 66 | + end |
| 67 | + |
| 68 | + it 'should append the line if no matches are found' do |
| 69 | + File.open(@tmpfile, 'w') do |fh| |
| 70 | + fh.write("foo1\nfoo2") |
| 71 | + end |
| 72 | + expect(@provider.exists?).to be_nil |
| 73 | + @provider.create |
| 74 | + expect(File.read(@tmpfile).chomp).to eql("foo1\nfoo2\nfoo = bar") |
| 75 | + end |
| 76 | + |
| 77 | + it 'should raise an error with invalid values' do |
| 78 | + expect { |
| 79 | + @resource = Puppet::Type::File_line.new( |
| 80 | + { |
| 81 | + :name => 'foo', |
| 82 | + :path => @tmpfile, |
| 83 | + :line => 'foo = bar', |
| 84 | + :match => '^foo\s*=.*$', |
| 85 | + :replace => 'asgadga', |
| 86 | + } |
| 87 | + ) |
| 88 | + }.to raise_error(Puppet::Error, /Invalid value "asgadga"\. Valid values are true, false, yes, no\./) |
| 89 | + end |
| 90 | + end |
40 | 91 | context "when matching" do |
41 | 92 | before :each do |
42 | 93 | # TODO: these should be ported over to use the PuppetLabs spec_helper |
|
0 commit comments