blob: 3c99f3db5f2aad98af3b51c56672ac6103be1982 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#! /usr/bin/env ruby
require 'spec_helper'
require 'puppet/agent'
require 'puppet/agent/locker'
class DisablerTester
include Puppet::Agent::Disabler
end
describe Puppet::Agent::Disabler do
before do
@disabler = DisablerTester.new
end
## These tests are currently very implementation-specific, and they rely heavily on
## having access to the "disable_lockfile" method. However, I've made this method private
## because it really shouldn't be exposed outside of our implementation... therefore
## these tests have to use a lot of ".send" calls. They should probably be cleaned up
## but for the moment I wanted to make sure not to lose any of the functionality of
## the tests. --cprice 2012-04-16
it "should use an JsonLockfile instance as its disable_lockfile" do
@disabler.send(:disable_lockfile).should be_instance_of(Puppet::Util::JsonLockfile)
end
it "should use puppet's :agent_disabled_lockfile' setting to determine its lockfile path" do
lockfile = File.expand_path("/my/lock.disabled")
Puppet[:agent_disabled_lockfile] = lockfile
lock = Puppet::Util::JsonLockfile.new(lockfile)
Puppet::Util::JsonLockfile.expects(:new).with(lockfile).returns lock
@disabler.send(:disable_lockfile)
end
it "should reuse the same lock file each time" do
@disabler.send(:disable_lockfile).should equal(@disabler.send(:disable_lockfile))
end
it "should lock the file when disabled" do
@disabler.send(:disable_lockfile).expects(:lock)
@disabler.disable
end
it "should unlock the file when enabled" do
@disabler.send(:disable_lockfile).expects(:unlock)
@disabler.enable
end
it "should check the lock if it is disabled" do
@disabler.send(:disable_lockfile).expects(:locked?)
@disabler.disabled?
end
it "should report the disable message when disabled" do
Puppet[:agent_disabled_lockfile] = PuppetSpec::Files.tmpfile("lock")
msg = "I'm busy, go away"
@disabler.disable(msg)
@disabler.disable_message.should == msg
end
end
|