From dc61ccc24d22a103ca80bbfd2e0aff6c3a669e1f Mon Sep 17 00:00:00 2001 From: Lindsay Holmwood Date: Fri, 27 Nov 2009 15:01:37 +0100 Subject: [PATCH] fixed specs to cope with :type => :backend transition, made worker application consistent --- lib/flapjack/applications/worker.rb | 6 ++-- spec/notifier_application_spec.rb | 34 +++++++++++------------ spec/notifier_options_multiplexer_spec.rb | 26 +++++++++-------- spec/persistence/datamapper_spec.rb | 2 +- spec/transports/beanstalkd_spec.rb | 4 +-- spec/worker_application_spec.rb | 6 ++-- 6 files changed, 40 insertions(+), 38 deletions(-) diff --git a/lib/flapjack/applications/worker.rb b/lib/flapjack/applications/worker.rb index baee7724b..cba28e85b 100644 --- a/lib/flapjack/applications/worker.rb +++ b/lib/flapjack/applications/worker.rb @@ -39,7 +39,7 @@ def setup_config end def setup_queues - defaults = { :type => :beanstalkd, + defaults = { :backend => :beanstalkd, :host => 'localhost', :port => '11300', :log => @log } @@ -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}.") diff --git a/spec/notifier_application_spec.rb b/spec/notifier_application_spec.rb index b373deb31..c99f36bba 100644 --- a/spec/notifier_application_spec.rb +++ b/spec/notifier_application_spec.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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) @@ -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) @@ -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) @@ -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 @@ -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) diff --git a/spec/notifier_options_multiplexer_spec.rb b/spec/notifier_options_multiplexer_spec.rb index c7cd40689..b798950e1 100644 --- a/spec/notifier_options_multiplexer_spec.rb +++ b/spec/notifier_options_multiplexer_spec.rb @@ -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 @@ -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| @@ -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 diff --git a/spec/persistence/datamapper_spec.rb b/spec/persistence/datamapper_spec.rb index 4e5fe6373..5e7afae7e 100644 --- a/spec/persistence/datamapper_spec.rb +++ b/spec/persistence/datamapper_spec.rb @@ -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' diff --git a/spec/transports/beanstalkd_spec.rb b/spec/transports/beanstalkd_spec.rb index b7bdd90d6..2fd7a2dee 100644 --- a/spec/transports/beanstalkd_spec.rb +++ b/spec/transports/beanstalkd_spec.rb @@ -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) diff --git a/spec/worker_application_spec.rb b/spec/worker_application_spec.rb index c0663f16f..83c7e1fe0 100644 --- a/spec/worker_application_spec.rb +++ b/spec/worker_application_spec.rb @@ -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 @@ -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