diff options
author | Ethan Rowe <ethan@endpoint.com> | 2009-04-13 07:33:11 -0400 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-04-22 14:39:37 +1000 |
commit | 7947f100a9d9d60d1038e220aa41d44cf59d5af0 (patch) | |
tree | f9c71a5783ad85d17b7e702b1ff706dc34a7dff6 /spec/unit/util/queue.rb | |
parent | 80dc83715190335ec0aac142e383d60ca28ea3b3 (diff) | |
download | puppet-7947f100a9d9d60d1038e220aa41d44cf59d5af0.tar.gz puppet-7947f100a9d9d60d1038e220aa41d44cf59d5af0.tar.xz puppet-7947f100a9d9d60d1038e220aa41d44cf59d5af0.zip |
Introduce queue client "plugin" namespace and interface, with a Stomp client implementation.
Puppet::Util::Queue provides queue client mix-in behaviors that enable easy queue client management for consumer classes. Some relevant behaviors include:
* standard Puppet instance loader behavior for loading queue client modules on-demand based on the client module specified by symbolic name
* singleton registry of known queue client types (based on symbol-to-class mappings from the instance loading behavior)
* simple interface for working with an actual queue client instance
Puppet::Util::Queue::Stomp wraps the Stomp::Client class to provide an initial queue client option supporting the Stomp messaging protocol. This defines the interface for all Puppet queue client plugins going forward.
Diffstat (limited to 'spec/unit/util/queue.rb')
-rwxr-xr-x | spec/unit/util/queue.rb | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/spec/unit/util/queue.rb b/spec/unit/util/queue.rb new file mode 100755 index 000000000..525e6239f --- /dev/null +++ b/spec/unit/util/queue.rb @@ -0,0 +1,95 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' +require 'puppet/util/queue' +require 'spec/mocks' + +def make_test_client_class(n) + c = Class.new do + class <<self + attr_accessor :name + def to_s + name + end + end + end + c.name = n + c +end + +mod = Puppet::Util::Queue +client_classes = { :default => make_test_client_class('Bogus::Default'), :setup => make_test_client_class('Bogus::Setup') } +mod.register_queue_type(client_classes[:default], :default) +mod.register_queue_type(client_classes[:setup], :setup) + +describe Puppet::Util::Queue do + before :each do + @class = Class.new do + extend mod + self.queue_type_default = :default + end + end + + context 'when determining a type name from a class' do + it 'should handle a simple one-word class name' do + mod.queue_type_from_class(make_test_client_class('Foo')).should == :foo + end + + it 'should handle a simple two-word class name' do + mod.queue_type_from_class(make_test_client_class('FooBar')).should == :foo_bar + end + + it 'should handle a two-part class name with one terminating word' do + mod.queue_type_from_class(make_test_client_class('Foo::Bar')).should == :bar + end + + it 'should handle a two-part class name with two terminating words' do + mod.queue_type_from_class(make_test_client_class('Foo::BarBah')).should == :bar_bah + end + end + + context 'when registering a queue client class' do + c = make_test_client_class('Foo::Bogus') + it 'uses the proper default name logic when type is unspecified' do + mod.register_queue_type(c) + mod.queue_type_to_class(:bogus).should == c + end + + it 'uses an explicit type name when provided' do + mod.register_queue_type(c, :aardvark) + mod.queue_type_to_class(:aardvark).should == c + end + + it 'throws an exception when type names conflict' do + mod.register_queue_type( make_test_client_class('Conflict') ) + lambda { mod.register_queue_type( c, :conflict) }.should raise_error + end + + it 'handle multiple, non-conflicting registrations' do + a = make_test_client_class('TestA') + b = make_test_client_class('TestB') + mod.register_queue_type(a) + mod.register_queue_type(b) + mod.queue_type_to_class(:test_a).should == a + mod.queue_type_to_class(:test_b).should == b + end + + it 'throws an exception when type name is unknown' do + lambda { mod.queue_type_to_class(:nope) }.should raise_error + end + end + + context 'when determining client type' do + it 'returns client class based on queue_type_default' do + Puppet.settings.stubs(:value).returns(nil) + @class.client_class.should == client_classes[:default] + @class.client.class.should == client_classes[:default] + end + + it 'prefers settings variable for client class when specified' do + Puppet.settings.stubs(:value).with(:queue_client).returns(:setup) + @class.client_class.should == client_classes[:setup] + @class.client.class.should == client_classes[:setup] + end + end +end |