339
342
provider.stubs(:get_augeas_version).returns("0.3.5")
340
343
provider.need_to_run?.should == false
346
# Ticket 2728 (diff files)
347
describe "and Puppet[:show_diff] is set", :if => Puppet.features.augeas? do
349
Puppet[:show_diff] = true
351
@resource = Puppet::Type.type(:augeas).new(:name => "test")
352
@provider = provider_class.new(@resource)
353
@augeas_stub = stub("augeas")
354
@provider.aug = @augeas_stub
356
@augeas_stub.stubs("get").with("/augeas/version").returns("0.7.2")
357
@augeas_stub.stubs(:set).returns(true)
358
@augeas_stub.stubs(:save).returns(true)
361
it "should call diff when a file is shown to have been changed" do
364
@resource[:context] = "/files"
365
@resource[:changes] = ["set #{file}/foo bar"]
367
@augeas_stub.stubs(:match).with("/augeas/events/saved").returns(["/augeas/events/saved"])
368
@augeas_stub.stubs(:get).with("/augeas/events/saved").returns(["/files#{file}"])
369
@augeas_stub.expects(:set).with("/augeas/save", "newfile")
370
@augeas_stub.expects(:close).never()
372
@provider.expects("diff").with("#{file}", "#{file}.augnew").returns("")
373
@provider.should be_need_to_run
376
it "should call diff for each file thats changed" do
378
file2 = "/etc/resolv.conf"
380
@resource[:context] = "/files"
381
@resource[:changes] = ["set #{file1}/foo bar", "set #{file2}/baz biz"]
383
@augeas_stub.stubs(:match).with("/augeas/events/saved").returns(["/augeas/events/saved[1]", "/augeas/events/saved[2]"])
384
@augeas_stub.stubs(:get).with("/augeas/events/saved[1]").returns(["/files#{file1}"])
385
@augeas_stub.stubs(:get).with("/augeas/events/saved[2]").returns(["/files#{file2}"])
386
@augeas_stub.expects(:set).with("/augeas/save", "newfile")
387
@augeas_stub.expects(:close).never()
389
@provider.expects(:diff).with("#{file1}", "#{file1}.augnew").returns("")
390
@provider.expects(:diff).with("#{file2}", "#{file2}.augnew").returns("")
391
@provider.should be_need_to_run
394
describe "and resource[:root] is set" do
395
it "should call diff when a file is shown to have been changed" do
399
@resource[:context] = "/files"
400
@resource[:changes] = ["set #{file}/foo bar"]
401
@resource[:root] = root
403
@augeas_stub.stubs(:match).with("/augeas/events/saved").returns(["/augeas/events/saved"])
404
@augeas_stub.stubs(:get).with("/augeas/events/saved").returns(["/files#{file}"])
405
@augeas_stub.expects(:set).with("/augeas/save", "newfile")
406
@augeas_stub.expects(:close).never()
408
@provider.expects(:diff).with("#{root}#{file}", "#{root}#{file}.augnew").returns("")
409
@provider.should be_need_to_run
413
it "should not call diff if no files change" do
416
@resource[:context] = "/files"
417
@resource[:changes] = ["set #{file}/foo bar"]
419
@augeas_stub.stubs(:match).with("/augeas/events/saved").returns([])
420
@augeas_stub.expects(:set).with("/augeas/save", "newfile")
421
@augeas_stub.expects(:get).with("/augeas/events/saved").never()
422
@augeas_stub.expects(:close)
424
@provider.expects(:diff).never()
425
@provider.should_not be_need_to_run
428
it "should cleanup when in noop mode" do
431
@resource[:noop] = true
432
@resource[:context] = "/files"
433
@resource[:changes] = ["set #{file}/foo bar"]
435
@augeas_stub.stubs(:match).with("/augeas/events/saved").returns(["/augeas/events/saved"])
436
@augeas_stub.stubs(:get).with("/augeas/events/saved").returns(["/files#{file}"])
437
@augeas_stub.expects(:set).with("/augeas/save", "newfile")
438
@augeas_stub.expects(:close)
440
File.expects(:delete).with(file + ".augnew")
442
@provider.expects(:diff).with("#{file}", "#{file}.augnew").returns("")
443
@provider.should be_need_to_run
446
it "should fail with an error if saving fails" do
449
@resource[:context] = "/files"
450
@resource[:changes] = ["set #{file}/foo bar"]
452
@augeas_stub.stubs(:save).returns(false)
453
@augeas_stub.stubs(:match).with("/augeas/events/saved").returns([])
454
@augeas_stub.expects(:close)
456
@provider.expects(:diff).never()
457
lambda { @provider.need_to_run? }.should raise_error
344
462
describe "augeas execution integration" do