spec/unit/provider/service/launchd_spec.rb in puppet-3.0.2.rc1 vs spec/unit/provider/service/launchd_spec.rb in puppet-3.0.2.rc2
- old
+ new
@@ -58,24 +58,27 @@
describe "when checking whether the service is enabled on OS X 10.6" do
it "should return true if the job plist says disabled is true and the global overrides says disabled is false" do
provider.expects(:get_macosx_version_major).returns("10.6")
subject.expects(:plist_from_label).returns([joblabel, {"Disabled" => true}])
provider.expects(:read_plist).returns({joblabel => {"Disabled" => false}})
+ provider.stubs(:launchd_overrides).returns(launchd_overrides)
FileTest.expects(:file?).with(launchd_overrides).returns(true)
subject.enabled?.should == :true
end
it "should return false if the job plist says disabled is false and the global overrides says disabled is true" do
provider.expects(:get_macosx_version_major).returns("10.6")
subject.expects(:plist_from_label).returns([joblabel, {"Disabled" => false}])
provider.expects(:read_plist).returns({joblabel => {"Disabled" => true}})
+ provider.stubs(:launchd_overrides).returns(launchd_overrides)
FileTest.expects(:file?).with(launchd_overrides).returns(true)
subject.enabled?.should == :false
end
it "should return true if the job plist and the global overrides have no disabled keys" do
provider.expects(:get_macosx_version_major).returns("10.6")
subject.expects(:plist_from_label).returns([joblabel, {}])
provider.expects(:read_plist).returns({})
+ provider.stubs(:launchd_overrides).returns(launchd_overrides)
FileTest.expects(:file?).with(launchd_overrides).returns(true)
subject.enabled?.should == :true
end
end
@@ -90,11 +93,11 @@
subject.expects(:plist_from_label).returns([joblabel, {}]).once
subject.expects(:enabled?).returns :true
subject.expects(:execute).with([:launchctl, :load, joblabel])
subject.start
end
- it "should execute 'launchctl load' once without writing to the plist if the job is enabled" do
+ it "should execute 'launchctl load' once without writing to the plist if the job is enabled" do
subject.expects(:plist_from_label).returns([joblabel, {}])
subject.expects(:enabled?).returns :true
subject.expects(:execute).with([:launchctl, :load, joblabel]).once
subject.start
end
@@ -186,20 +189,48 @@
describe "when enabling the service on OS X 10.6" do
it "should write to the global launchd overrides file once" do
resource[:enable] = true
provider.expects(:get_macosx_version_major).returns("10.6")
provider.expects(:read_plist).returns({})
+ provider.stubs(:launchd_overrides).returns(launchd_overrides)
Plist::Emit.expects(:save_plist).once
subject.enable
end
end
describe "when disabling the service on OS X 10.6" do
it "should write to the global launchd overrides file once" do
resource[:enable] = false
provider.stubs(:get_macosx_version_major).returns("10.6")
provider.stubs(:read_plist).returns({})
+ provider.stubs(:launchd_overrides).returns(launchd_overrides)
Plist::Emit.expects(:save_plist).once
subject.enable
+ end
+ end
+
+ describe "when encountering malformed plists" do
+ let(:plist_without_label) do
+ {
+ 'LimitLoadToSessionType' => 'Aqua'
+ }
+ end
+ let(:busted_plist_path) { '/Library/LaunchAgents/org.busted.plist' }
+
+ it "[17624] should warn that the plist in question is being skipped" do
+ provider.expects(:launchd_paths).returns(['/Library/LaunchAgents'])
+ provider.expects(:return_globbed_list_of_file_paths).with('/Library/LaunchAgents').returns([busted_plist_path])
+ provider.expects(:read_plist).with(busted_plist_path).returns(plist_without_label)
+ Puppet.expects(:warning).with("The #{busted_plist_path} plist does not contain a 'label' key; Puppet is skipping it")
+ provider.jobsearch
+ end
+
+ it "[15929] should skip plists that plutil cannot read" do
+ provider.expects(:plutil).with('-convert', 'xml1', '-o', '/dev/stdout',
+ busted_plist_path).raises(Puppet::ExecutionFailure, 'boom')
+ Puppet.expects(:warning).with("Cannot read file #{busted_plist_path}; " +
+ "Puppet is skipping it. \n" +
+ "Details: boom")
+ provider.read_plist(busted_plist_path)
end
end
end