forked from flapjack/flapjack
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathworker_application_spec.rb
62 lines (47 loc) · 2.35 KB
/
worker_application_spec.rb
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
require File.join(File.dirname(__FILE__), '..', 'lib', 'flapjack', 'applications', 'worker')
require File.join(File.dirname(__FILE__), 'helpers')
describe "worker application" do
it "should have a simple booting interface " do
options = {:log => MockLogger.new}
app = Flapjack::Worker::Application.run(options)
end
it "should load beanstalkd as the default transport" do
options = {:log => MockLogger.new}
app = Flapjack::Worker::Application.run(options)
app.log.messages.find {|msg| msg =~ /loading.+beanstalkd.+transport/i}.should_not be_nil
end
it "should setup two transports (checks + results)" do
options = {:log => MockLogger.new}
app = Flapjack::Worker::Application.run(options)
app.log.messages.find_all {|msg| msg =~ /loading.+beanstalkd.+transport/i}.size.should == 2
app.log.messages.find {|msg| msg =~ /loading.+beanstalkd.+transport.+checks/i}.should be_true
app.log.messages.find {|msg| msg =~ /loading.+beanstalkd.+transport.+results/i}.should be_true
end
it "should load a transport as specified in options" do
options = {:log => MockLogger.new, :transport => {:backend => :beanstalkd}}
app = Flapjack::Worker::Application.run(options)
app.log.messages.find {|msg| msg =~ /loading.+beanstalkd.+transport/i}.should_not be_nil
end
it "should error if the specified transport dosen't exist" do
options = {:log => MockLogger.new, :transport => {:backend => :nonexistant}}
lambda {
app = Flapjack::Worker::Application.run(options)
}.should raise_error
end
it "should execute checks in a sandbox"
it "should use a limited interface for dealing with transports" do
options = { :log => MockLogger.new,
:transport => {:backend => :mock_transport,
:basedir => File.join(File.dirname(__FILE__), 'transports')} }
app = Flapjack::Worker::Application.run(options)
app.process_check
# check allowed methods were called
allowed_methods = %w(next)
allowed_methods.each do |method|
app.log.messages.find {|msg| msg =~ /#{method} was called/}.should_not be_nil
end
# check no other methods were called
called_methods = app.log.messages.find_all {|msg| msg =~ /^method .+ was called on MockTransport$/i }.map {|msg| msg.split(' ')[1]}
(allowed_methods - called_methods).size.should == 0
end
end