Skip to content

Commit

Permalink
fixed specs to cope with :type => :backend transition, made worker ap…
Browse files Browse the repository at this point in the history
…plication consistent
  • Loading branch information
auxesis committed Nov 27, 2009
1 parent 6f35637 commit dc61ccc
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 38 deletions.
6 changes: 3 additions & 3 deletions lib/flapjack/applications/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def setup_config
end

def setup_queues
defaults = { :type => :beanstalkd,
defaults = { :backend => :beanstalkd,
:host => 'localhost',
:port => '11300',
:log => @log }
Expand All @@ -50,8 +50,8 @@ def setup_queues

queue_config = config.merge(:queue_name => queue_name)

class_name = config[:type].to_s.camel_case
filename = File.join(basedir, "#{config[:type]}.rb")
class_name = config[:backend].to_s.camel_case
filename = File.join(basedir, "#{config[:backend]}.rb")

@log.info("Loading the #{class_name} transport for queue: #{queue_name}.")

Expand Down
34 changes: 17 additions & 17 deletions spec/notifier_application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
it "should have a simple interface to start the notifier" do
options = { :notifiers => {},
:log => MockLogger.new,
:persistence => {:type => :mock_persistence_backend,
:persistence => {:backend => :mock_persistence_backend,
:basedir => File.join(File.dirname(__FILE__), 'persistence')} }
app = Flapjack::Notifier::Application.run(options)
end
Expand All @@ -19,7 +19,7 @@
options = { :notifiers => {:testmailer => {}},
:log => MockLogger.new,
:notifier_directories => [File.join(File.dirname(__FILE__),'notifier-directories', 'spoons')],
:persistence => {:type => :mock_persistence_backend,
:persistence => {:backend => :mock_persistence_backend,
:basedir => File.join(File.dirname(__FILE__), 'persistence')} }
app = Flapjack::Notifier::Application.run(options)
app.log.messages.find {|msg| msg =~ /loading the testmailer notifier/i}.should_not be_nil
Expand All @@ -28,7 +28,7 @@
it "should warn if a specified notifier doesn't exist" do
options = { :notifiers => {:nonexistant => {}},
:log => MockLogger.new,
:persistence => {:type => :mock_persistence_backend,
:persistence => {:backend => :mock_persistence_backend,
:basedir => File.join(File.dirname(__FILE__), 'persistence')} }
app = Flapjack::Notifier::Application.run(options)
app.log.messages.find {|msg| msg =~ /Flapjack::Notifiers::Nonexistant doesn't exist/}.should_not be_nil
Expand All @@ -38,7 +38,7 @@
options = { :notifiers => {:testmailer => {}},
:log => MockLogger.new,
:notifier_directories => [File.join(File.dirname(__FILE__),'notifier-directories', 'spoons')],
:persistence => {:type => :mock_persistence_backend,
:persistence => {:backend => :mock_persistence_backend,
:basedir => File.join(File.dirname(__FILE__), 'persistence')} }
app = Flapjack::Notifier::Application.run(options)
app.log.messages.find {|msg| msg =~ /spoons/i}.should_not be_nil
Expand All @@ -53,7 +53,7 @@
:log => MockLogger.new,
:recipients => {:filename => File.join(File.dirname(__FILE__), 'fixtures', 'recipients.yaml'),
:list => [{:name => "Spoons McDoom"}]},
:persistence => {:type => :mock_persistence_backend,
:persistence => {:backend => :mock_persistence_backend,
:basedir => File.join(File.dirname(__FILE__), 'persistence')} }
app = Flapjack::Notifier::Application.run(options)
app.log.messages.find {|msg| msg =~ /fixtures\/recipients\.yaml/i}.should_not be_nil
Expand All @@ -68,7 +68,7 @@
it "should use beanstalkd as the default transport" do
options = { :notifiers => {},
:log => MockLogger.new,
:persistence => {:type => :mock_persistence_backend,
:persistence => {:backend => :mock_persistence_backend,
:basedir => File.join(File.dirname(__FILE__), 'persistence')} }
app = Flapjack::Notifier::Application.run(options)
app.log.messages.find {|msg| msg =~ /loading.+beanstalkd.+transport/i}.should_not be_nil
Expand All @@ -77,8 +77,8 @@
it "should use a transport as specified in options" do
options = { :notifiers => {},
:log => MockLogger.new,
:transport => {:type => :beanstalkd},
:persistence => {:type => :mock_persistence_backend,
:transport => {:backend => :beanstalkd},
:persistence => {:backend => :mock_persistence_backend,
:basedir => File.join(File.dirname(__FILE__), 'persistence')} }
app = Flapjack::Notifier::Application.run(options)
app.log.messages.find {|msg| msg =~ /loading.+beanstalkd.+transport/i}.should_not be_nil
Expand All @@ -87,7 +87,7 @@
it "should error if the specified transport doesn't exist" do
options = { :notifiers => {},
:log => MockLogger.new,
:transport => {:type => :nonexistant} }
:transport => {:backend => :nonexistant} }
lambda {
app = Flapjack::Notifier::Application.run(options)
#app.log.messages.find {|msg| msg =~ /attempted to load nonexistant/i}.should_not be_nil
Expand All @@ -103,9 +103,9 @@

options = { :notifiers => {},
:log => MockLogger.new,
:transport => {:type => :mock_transport,
:transport => {:backend => :mock_transport,
:basedir => File.join(File.dirname(__FILE__), 'transports')},
:persistence => {:type => :mock_persistence_backend,
:persistence => {:backend => :mock_persistence_backend,
:basedir => File.join(File.dirname(__FILE__), 'persistence')} }
app = Flapjack::Notifier::Application.run(options)

Expand All @@ -132,9 +132,9 @@

options = { :notifiers => {},
:log => MockLogger.new,
:transport => {:type => :mock_transport,
:transport => {:backend => :mock_transport,
:basedir => File.join(File.dirname(__FILE__), 'transports')},
:persistence => {:type => :mock_persistence_backend,
:persistence => {:backend => :mock_persistence_backend,
:basedir => File.join(File.dirname(__FILE__), 'persistence')} }
app = Flapjack::Notifier::Application.run(options)

Expand All @@ -161,9 +161,9 @@

options = { :notifiers => {},
:log => MockLogger.new,
:transport => {:type => :mock_transport,
:transport => {:backend => :mock_transport,
:basedir => File.join(File.dirname(__FILE__), 'transports')},
:persistence => {:type => :mock_persistence_backend,
:persistence => {:backend => :mock_persistence_backend,
:basedir => File.join(File.dirname(__FILE__), 'persistence')} }
app = Flapjack::Notifier::Application.run(options)

Expand Down Expand Up @@ -191,7 +191,7 @@
it "should load a persistence backend as specified in options" do
options = { :notifiers => {},
:log => MockLogger.new,
:persistence => {:type => :mock_persistence_backend,
:persistence => {:backend => :mock_persistence_backend,
:basedir => File.join(File.dirname(__FILE__), 'persistence')} }
app = Flapjack::Notifier::Application.run(options)
app.log.messages.find {|msg| msg =~ /loading.+MockPersistenceBackend.+backend/i}.should_not be_nil
Expand All @@ -200,7 +200,7 @@
it "should raise if the specified persistence backend doesn't exist" do
options = { :notifiers => {},
:log => MockLogger.new,
:persistence => {:type => :nonexistant} }
:persistence => {:backend => :nonexistant} }
lambda {
app = Flapjack::Notifier::Application.run(options)
}.should raise_error(LoadError)
Expand Down
26 changes: 14 additions & 12 deletions spec/notifier_options_multiplexer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require File.join(File.dirname(__FILE__), '..', 'lib', 'flapjack', 'cli', 'notifier')
require File.join(File.dirname(__FILE__), '..', 'lib', 'flapjack', 'patches')


describe "notifier options multiplexer" do

Expand All @@ -12,8 +14,8 @@
it "should setup notifier options from specified config file" do
args = ["-c", @config_filename, "-r", @recipients_filename]
config = Flapjack::Notifier::Options.parse(args)
config.notifiers.each do |notifier|
%w(mailer xmpp).include?(notifier.keys.first)
config.notifiers.each do |key, value|
%w(mailer xmpp).include?(key)
end

config.notifier_directories.each do |dir|
Expand All @@ -24,26 +26,26 @@
it "should setup beanstalkd transport options from specified config file" do
args = ["-c", @config_filename, "-r", @recipients_filename]
config = Flapjack::Notifier::Options.parse(args)
config.transport.backend.should == "beanstalkd"
config.transport.host.should == "localhost"
config.transport.port.should == "11300"
config.transport[:backend].should == "beanstalkd"
config.transport[:host].should == "localhost"
config.transport[:port].should == "11300"
end

it "should setup datamapper persistence options from specified config file" do
args = ["-c", @config_filename, "-r", @recipients_filename]
config = Flapjack::Notifier::Options.parse(args)
config.persistence.backend.should == "datamapper"
config.persistence.uri.should == "sqlite3:///tmp/flapjack.db"
config.persistence[:backend].should == "data_mapper"
config.persistence[:uri].should == "sqlite3:///tmp/flapjack.db"
end

it "should setup couchdb persistence backend from specified config file" do
args = [ "-c", @couchdb_config_filename, "-r", @recipients_filename ]
config = Flapjack::Notifier::Options.parse(args)
config.persistence.backend.should == "couchdb"
config.persistence.host.should == "localhost"
config.persistence.port.should == "5984"
config.persistence.username.should == "spoons"
config.persistence.password.should == "doom"
config.persistence[:backend].should == "couchdb"
config.persistence[:host].should == "localhost"
config.persistence[:port].should == "5984"
config.persistence[:username].should == "spoons"
config.persistence[:password].should == "doom"
end

it "should setup individual notifiers from a specified config file" do
Expand Down
2 changes: 1 addition & 1 deletion spec/persistence/datamapper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby

require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'flapjack', 'applications', 'notifier')
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'flapjack', 'persistence', 'datamapper')
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'flapjack', 'persistence', 'data_mapper')
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'flapjack', 'transports', 'result')
require File.join(File.dirname(__FILE__), '..', 'helpers')
require 'tmpdir'
Expand Down
4 changes: 2 additions & 2 deletions spec/transports/beanstalkd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

options = { :notifiers => {},
:log => MockLogger.new,
:transport => {:type => :beanstalkd},
:persistence => {:type => :mock_persistence_backend,
:transport => {:backend => :beanstalkd},
:persistence => {:backend => :mock_persistence_backend,
:basedir => File.join(File.dirname(__FILE__), '..', 'persistence')}}
app = Flapjack::Notifier::Application.run(options)

Expand Down
6 changes: 3 additions & 3 deletions spec/worker_application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
end

it "should load a transport as specified in options" do
options = {:log => MockLogger.new, :transport => {:type => :beanstalkd}}
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 => {:type => :nonexistant}}
options = {:log => MockLogger.new, :transport => {:backend => :nonexistant}}
lambda {
app = Flapjack::Worker::Application.run(options)
}.should raise_error
Expand All @@ -42,7 +42,7 @@

it "should use a limited interface for dealing with transports" do
options = { :log => MockLogger.new,
:transport => {:type => :mock_transport,
:transport => {:backend => :mock_transport,
:basedir => File.join(File.dirname(__FILE__), 'transports')} }
app = Flapjack::Worker::Application.run(options)
app.process_check
Expand Down

0 comments on commit dc61ccc

Please sign in to comment.