|
337 | 337 | end
|
338 | 338 | end
|
339 | 339 |
|
340 |
| - context "when removing" do |
| 340 | + context "when removing with a line" do |
341 | 341 | before :each do
|
342 | 342 | # TODO: these should be ported over to use the PuppetLabs spec_helper
|
343 | 343 | # file fixtures once the following pull request has been merged:
|
|
378 | 378 | @provider.destroy
|
379 | 379 | expect(File.read(@tmpfile)).to eql("foo1\nfoo2\n")
|
380 | 380 | end
|
| 381 | + |
| 382 | + it 'example in the docs' do |
| 383 | + @resource = Puppet::Type::File_line.new( |
| 384 | + { |
| 385 | + :name => 'bashrc_proxy', |
| 386 | + :ensure => 'absent', |
| 387 | + :path => @tmpfile, |
| 388 | + :line => 'export HTTP_PROXY=http://squid.puppetlabs.vm:3128', |
| 389 | + } |
| 390 | + ) |
| 391 | + @provider = provider_class.new(@resource) |
| 392 | + File.open(@tmpfile, 'w') do |fh| |
| 393 | + fh.write("foo1\nfoo2\nexport HTTP_PROXY=http://squid.puppetlabs.vm:3128\nfoo4\n") |
| 394 | + end |
| 395 | + @provider.destroy |
| 396 | + expect(File.read(@tmpfile)).to eql("foo1\nfoo2\nfoo4\n") |
| 397 | + end |
381 | 398 | end
|
382 | 399 |
|
383 | 400 | context "when removing with a match" do
|
|
416 | 433 | expect(File.read(@tmpfile)).to eql("foo1\nfoo2")
|
417 | 434 | end
|
418 | 435 |
|
| 436 | + it 'the line parameter is actually not used at all but is silently ignored if here' do |
| 437 | + @resource = Puppet::Type::File_line.new( |
| 438 | + { |
| 439 | + :name => 'foo', |
| 440 | + :path => @tmpfile, |
| 441 | + :line => 'supercalifragilisticexpialidocious', |
| 442 | + :ensure => 'absent', |
| 443 | + :match => 'o$', |
| 444 | + :match_for_absence => true, |
| 445 | + } |
| 446 | + ) |
| 447 | + File.open(@tmpfile, 'w') do |fh| |
| 448 | + fh.write("foo1\nfoo\nfoo2") |
| 449 | + end |
| 450 | + @provider.destroy |
| 451 | + expect(File.read(@tmpfile)).to eql("foo1\nfoo2") |
| 452 | + end |
| 453 | + |
| 454 | + it 'and may not be here and does not need to be here' do |
| 455 | + @resource = Puppet::Type::File_line.new( |
| 456 | + { |
| 457 | + :name => 'foo', |
| 458 | + :path => @tmpfile, |
| 459 | + :ensure => 'absent', |
| 460 | + :match => 'o$', |
| 461 | + :match_for_absence => true, |
| 462 | + } |
| 463 | + ) |
| 464 | + File.open(@tmpfile, 'w') do |fh| |
| 465 | + fh.write("foo1\nfoo\nfoo2") |
| 466 | + end |
| 467 | + @provider.destroy |
| 468 | + expect(File.read(@tmpfile)).to eql("foo1\nfoo2") |
| 469 | + end |
| 470 | + |
419 | 471 | it 'should raise an error if more than one line matches' do
|
420 | 472 | File.open(@tmpfile, 'w') do |fh|
|
421 | 473 | fh.write("foo1\nfoo\nfoo2\nfoo\nfoo")
|
|
480 | 532 | expect(File.read(@tmpfile)).to eql("foo1\nfoo\n")
|
481 | 533 | end
|
482 | 534 |
|
483 |
| - end |
| 535 | + it 'example in the docs' do |
| 536 | + @resource = Puppet::Type::File_line.new( |
| 537 | + { |
| 538 | + :name => 'bashrc_proxy', |
| 539 | + :ensure => 'absent', |
| 540 | + :path => @tmpfile, |
| 541 | + :line => 'export HTTP_PROXY=http://squid.puppetlabs.vm:3128', |
| 542 | + :match => '^export\ HTTP_PROXY\=', |
| 543 | + :match_for_absence => true, |
| 544 | + } |
| 545 | + ) |
| 546 | + @provider = provider_class.new(@resource) |
| 547 | + File.open(@tmpfile, 'w') do |fh| |
| 548 | + fh.write("foo1\nfoo2\nexport HTTP_PROXY=foo\nfoo4\n") |
| 549 | + end |
| 550 | + @provider.destroy |
| 551 | + expect(File.read(@tmpfile)).to eql("foo1\nfoo2\nfoo4\n") |
| 552 | + end |
484 | 553 |
|
| 554 | + it 'example in the docs showing line is redundant' do |
| 555 | + @resource = Puppet::Type::File_line.new( |
| 556 | + { |
| 557 | + :name => 'bashrc_proxy', |
| 558 | + :ensure => 'absent', |
| 559 | + :path => @tmpfile, |
| 560 | + :match => '^export\ HTTP_PROXY\=', |
| 561 | + :match_for_absence => true, |
| 562 | + } |
| 563 | + ) |
| 564 | + @provider = provider_class.new(@resource) |
| 565 | + File.open(@tmpfile, 'w') do |fh| |
| 566 | + fh.write("foo1\nfoo2\nexport HTTP_PROXY=foo\nfoo4\n") |
| 567 | + end |
| 568 | + @provider.destroy |
| 569 | + expect(File.read(@tmpfile)).to eql("foo1\nfoo2\nfoo4\n") |
| 570 | + end |
| 571 | + end |
485 | 572 | end
|
0 commit comments