summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/indirector.rb48
-rw-r--r--lib/puppet/indirector/indirection.rb3
-rw-r--r--lib/puppet/indirector/terminus.rb74
-rw-r--r--lib/puppet/indirector/yaml.rb4
-rw-r--r--lib/puppet/indirector/yaml/facts.rb2
-rwxr-xr-xlib/puppet/util/instance_loader.rb8
-rwxr-xr-xspec/unit/indirector/facts/yaml.rb62
-rwxr-xr-xspec/unit/indirector/indirection.rb10
-rwxr-xr-xspec/unit/indirector/indirector.rb31
-rwxr-xr-xspec/unit/indirector/terminus.rb159
-rwxr-xr-xspec/unit/indirector/yaml.rb25
-rwxr-xr-xspec/unit/indirector/yaml/facts.rb26
12 files changed, 235 insertions, 217 deletions
diff --git a/lib/puppet/indirector.rb b/lib/puppet/indirector.rb
index 4d7d9d92d..b89017c9a 100644
--- a/lib/puppet/indirector.rb
+++ b/lib/puppet/indirector.rb
@@ -10,53 +10,6 @@ module Puppet::Indirector
require 'puppet/indirector/indirection'
require 'puppet/indirector/terminus'
- # This handles creating the terminus classes.
- require 'puppet/util/classgen'
- extend Puppet::Util::ClassGen
-
- # This manages reading in all of our files for us and then retrieving
- # loaded instances. We still have to define the 'newX' method, but this
- # does all of the rest -- loading, storing, and retrieving by name.
- require 'puppet/util/instance_loader'
- extend Puppet::Util::InstanceLoader
-
- # Register a given indirection type. The classes including this module
- # handle creating terminus instances, but the module itself handles
- # loading them and managing the classes.
- def self.enable_autoloading_indirection(indirection)
- # Set up autoloading of the appropriate termini.
- instance_load indirection, "puppet/indirector/%s" % indirection
- end
-
-# JRB:TODO -- where did this come from, re: the specs? also, any way to make this protected/private?
-
- # Define a new indirection terminus. This method is used by the individual
- # termini in their separate files. Again, the autoloader takes care of
- # actually loading these files.
- # Note that the termini are being registered on the Indirector module, not
- # on the classes including the module. This allows a given indirection to
- # be used in multiple classes.
- def self.register_terminus(indirection, terminus, options = {}, &block)
- klass = genclass(terminus,
- :prefix => indirection.to_s.capitalize,
- :hash => instance_hash(indirection),
- :attributes => options,
- :block => block,
- :parent => options[:parent] || Terminus,
-# JRB:FIXME -- why do I have to use overwrite here?
- :overwrite => 'please do motherfucker'
- )
- klass.indirection = indirection
- klass.name = terminus
- end
-
-# JRB:TODO where did this come from, re: the specs? also, shouldn't this be protected/private?
- # Retrieve a terminus class by indirection and name.
-# JRB:FIXME -- should be protected/private
- def self.terminus(indirection, terminus)
- loaded_instance(indirection, terminus)
- end
-
# Declare that the including class indirects its methods to
# this terminus. The terminus name must be the name of a Puppet
# default, not the value -- if it's the value, then it gets
@@ -70,7 +23,6 @@ module Puppet::Indirector
# instantiate the actual Terminus for that type and this name (:ldap, w/ args :node)
# & hook the instantiated Terminus into this class (Node: @indirection = terminus)
- Puppet::Indirector.enable_autoloading_indirection indirection
@indirection = Puppet::Indirector::Indirection.new(indirection)
end
diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb
index 0cf8c7a27..31b9d68a5 100644
--- a/lib/puppet/indirector/indirection.rb
+++ b/lib/puppet/indirector/indirection.rb
@@ -36,6 +36,7 @@ class Puppet::Indirector::Indirection
end
end
@termini = {}
+ @terminus_types = {}
raise(ArgumentError, "Indirection %s is already defined" % @name) if @@indirections.find { |i| i.name == @name }
@@indirections << self
end
@@ -81,7 +82,7 @@ class Puppet::Indirector::Indirection
# Create a new terminus instance.
def make_terminus(name)
# Load our terminus class.
- unless klass = Puppet::Indirector.terminus(self.name, name)
+ unless klass = Puppet::Indirector::Terminus.terminus_class(self.name, name)
raise ArgumentError, "Could not find terminus %s for indirection %s" % [name, self.name]
end
return klass.new
diff --git a/lib/puppet/indirector/terminus.rb b/lib/puppet/indirector/terminus.rb
index a98f6dff0..f3797f471 100644
--- a/lib/puppet/indirector/terminus.rb
+++ b/lib/puppet/indirector/terminus.rb
@@ -1,14 +1,23 @@
require 'puppet/indirector'
require 'puppet/indirector/indirection'
+require 'puppet/util/instance_loader'
# A simple class that can function as the base class for indirected types.
class Puppet::Indirector::Terminus
require 'puppet/util/docs'
extend Puppet::Util::Docs
-
+
class << self
- attr_accessor :name
- attr_reader :indirection
+ include Puppet::Util::InstanceLoader
+
+ attr_accessor :name, :terminus_type
+ attr_reader :abstract_terminus, :indirection
+
+ # Are we an abstract terminus type, rather than an instance with an
+ # associated indirection?
+ def abstract_terminus?
+ abstract_terminus
+ end
# Look up the indirection if we were only provided a name.
def indirection=(name)
@@ -30,27 +39,66 @@ class Puppet::Indirector::Terminus
raise ArgumentError, "Terminus subclasses must have associated constants"
end
names = longname.split("::")
+ name = names.pop.downcase.intern
- # First figure out the indirection
- shortname = names.pop.downcase.intern
- subclass.indirection = shortname
+ subclass.name = name
- if names.empty?
- raise ArgumentError, "Terminus subclasses need to have their constants include the parent class for setting the terminus name"
+ # Short-circuit the abstract types, which are those that directly subclass
+ # the Terminus class.
+ if self == Puppet::Indirector::Terminus
+ subclass.mark_as_abstract_terminus
+ return
end
- # And then the name (e.g., ldap or yaml)
- termtype = names.pop.downcase.intern
- subclass.name = termtype
+ # Set the terminus type to be the name of the abstract terminus type.
+ # Yay, class/instance confusion.
+ subclass.terminus_type = self.name
+
+ # This will throw an exception if the indirection instance cannot be found.
+ # Do this last, because it also registers the terminus type with the indirection,
+ # which needs the above information.
+ subclass.indirection = name
+
+ # And add this instance to the instance hash.
+ Puppet::Indirector::Terminus.register_terminus_class(subclass)
+ end
+
+ # Mark that this instance is abstract.
+ def mark_as_abstract_terminus
+ @abstract_terminus = true
+ end
+
+ # Register a class, probably autoloaded.
+ def register_terminus_class(klass)
+ setup_instance_loading klass.terminus_type
+ instance_hash(klass.terminus_type)[klass.name] = klass
+ end
+
+ # Return a terminus by name, using the autoloader.
+ def terminus_class(type, name)
+ setup_instance_loading type
+ loaded_instance(type, name)
+ end
+
+ private
+
+ def setup_instance_loading(type)
+ unless instance_loading?(type)
+ instance_load type, "puppet/indirector/%s" % type
+ end
end
end
def initialize
- unless indirection
- raise Puppet::DevError, "Indirection termini cannot be used without an associated indirection"
+ if self.class.abstract_terminus?
+ raise Puppet::DevError, "Cannot create instances of abstract terminus types"
end
end
+ def terminus_type
+ self.class.terminus_type
+ end
+
def name
self.class.name
end
diff --git a/lib/puppet/indirector/yaml.rb b/lib/puppet/indirector/yaml.rb
index f7f7d290f..42f1bb703 100644
--- a/lib/puppet/indirector/yaml.rb
+++ b/lib/puppet/indirector/yaml.rb
@@ -3,8 +3,6 @@ require 'puppet/indirector/terminus'
# The base class for YAML indirection termini.
class Puppet::Indirector::Yaml < Puppet::Indirector::Terminus
def initialize
- super
-
# Make sure our base directory exists.
Puppet.config.use(:yaml)
end
@@ -42,6 +40,6 @@ class Puppet::Indirector::Yaml < Puppet::Indirector::Terminus
# Return the path to a given node's file.
def path(name)
- File.join(Puppet[:yamldir], indirection.name.to_s, name.to_s + ".yaml")
+ File.join(Puppet[:yamldir], self.name.to_s, name.to_s + ".yaml")
end
end
diff --git a/lib/puppet/indirector/yaml/facts.rb b/lib/puppet/indirector/yaml/facts.rb
index c09eaeab1..754b0d5a6 100644
--- a/lib/puppet/indirector/yaml/facts.rb
+++ b/lib/puppet/indirector/yaml/facts.rb
@@ -2,6 +2,4 @@ require 'puppet/indirector/yaml'
class Puppet::Indirector::Yaml::Facts < Puppet::Indirector::Yaml
desc "Store client facts as flat files, serialized using YAML."
-
- register_terminus
end
diff --git a/lib/puppet/util/instance_loader.rb b/lib/puppet/util/instance_loader.rb
index bc0567866..f280014eb 100755
--- a/lib/puppet/util/instance_loader.rb
+++ b/lib/puppet/util/instance_loader.rb
@@ -5,6 +5,12 @@ require 'puppet/util'
# of Puppet::Util::Autoload
module Puppet::Util::InstanceLoader
include Puppet::Util
+
+ # Are we instance-loading this type?
+ def instance_loading?(type)
+ defined?(@autoloaders) and @autoloaders.include?(symbolize(type))
+ end
+
# Define a new type of autoloading.
def instance_load(type, path, options = {})
@autoloaders ||= {}
@@ -54,7 +60,7 @@ module Puppet::Util::InstanceLoader
# Retrieve an alread-loaded instance, or attempt to load our instance.
def loaded_instance(type, name)
name = symbolize(name)
- instances = instance_hash(type)
+ return nil unless instances = instance_hash(type)
unless instances.include? name
if instance_loader(type).load(name)
unless instances.include? name
diff --git a/spec/unit/indirector/facts/yaml.rb b/spec/unit/indirector/facts/yaml.rb
deleted file mode 100755
index 49b361a95..000000000
--- a/spec/unit/indirector/facts/yaml.rb
+++ /dev/null
@@ -1,62 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.dirname(__FILE__) + '/../../../spec_helper'
-
-require 'puppet/indirector'
-require 'puppet/node/facts'
-require 'puppettest'
-
-describe Puppet::Indirector.terminus(:facts, :yaml), " when managing facts" do
- # For cleanup mechanisms.
- include PuppetTest
-
- # LAK:FIXME It seems like I really do have to hit the filesystem
- # here, since, like, that's what I'm testing. Is there another/better
- # way to do this?
- before do
- @store = Puppet::Indirector.terminus(:facts, :yaml).new
- setup # Grr, stupid rspec
- Puppet[:yamlfactdir] = tempfile
- Dir.mkdir(Puppet[:yamlfactdir])
- end
-
- it "should store facts in YAML in the yamlfactdir" do
- values = {"one" => "two", "three" => "four"}
- facts = Puppet::Node::Facts.new("node", values)
- @store.save(facts)
-
- # Make sure the file exists
- path = File.join(Puppet[:yamlfactdir], facts.name) + ".yaml"
- File.exists?(path).should be_true
-
- # And make sure it's right
- newvals = YAML.load(File.read(path))
-
- # We iterate over them, because the store might add extra values.
- values.each do |name, value|
- newvals[name].should == value
- end
- end
-
- it "should retrieve values from disk" do
- values = {"one" => "two", "three" => "four"}
-
- # Create the file.
- path = File.join(Puppet[:yamlfactdir], "node") + ".yaml"
- File.open(path, "w") do |f|
- f.print values.to_yaml
- end
-
- facts = Puppet::Node::Facts.find('node')
- facts.should be_instance_of(Puppet::Node::Facts)
-
- # We iterate over them, because the store might add extra values.
- values.each do |name, value|
- facts.values[name].should == value
- end
- end
-
- after do
- teardown
- end
-end
diff --git a/spec/unit/indirector/indirection.rb b/spec/unit/indirector/indirection.rb
index cd5379ee6..5866f2d5f 100755
--- a/spec/unit/indirector/indirection.rb
+++ b/spec/unit/indirector/indirection.rb
@@ -45,7 +45,7 @@ describe Puppet::Indirector::Indirection, " when choosing terminus types" do
it "should follow a convention on using per-model configuration parameters to determine the terminus class" do
Puppet.config.expects(:valid?).with('test_terminus').returns(true)
Puppet.config.expects(:value).with('test_terminus').returns(:foo)
- Puppet::Indirector.expects(:terminus).with(:test, :foo).returns(@terminus_class)
+ Puppet::Indirector::Terminus.expects(:terminus_class).with(:test, :foo).returns(@terminus_class)
@indirection.terminus.should equal(@terminus)
end
@@ -53,12 +53,12 @@ describe Puppet::Indirector::Indirection, " when choosing terminus types" do
per-model configuration parameter is available" do
Puppet.config.expects(:valid?).with('test_terminus').returns(false)
Puppet.config.expects(:value).with(:default_terminus).returns(:foo)
- Puppet::Indirector.expects(:terminus).with(:test, :foo).returns(@terminus_class)
+ Puppet::Indirector::Terminus.expects(:terminus_class).with(:test, :foo).returns(@terminus_class)
@indirection.terminus.should equal(@terminus)
end
it "should select the specified terminus class if a name is provided" do
- Puppet::Indirector.expects(:terminus).with(:test, :foo).returns(@terminus_class)
+ Puppet::Indirector::Terminus.expects(:terminus_class).with(:test, :foo).returns(@terminus_class)
@indirection.terminus(:foo).should equal(@terminus)
end
@@ -71,7 +71,7 @@ describe Puppet::Indirector::Indirection, " when choosing terminus types" do
end
it "should fail when the specified terminus class cannot be found" do
- Puppet::Indirector.expects(:terminus).with(:test, :foo).returns(nil)
+ Puppet::Indirector::Terminus.expects(:terminus_class).with(:test, :foo).returns(nil)
proc { @indirection.terminus(:foo) }.should raise_error(ArgumentError)
end
@@ -85,7 +85,7 @@ describe Puppet::Indirector::Indirection, " when managing terminus instances" do
@indirection = Puppet::Indirector::Indirection.new(:test)
@terminus = mock 'terminus'
@terminus_class = mock 'terminus class'
- Puppet::Indirector.stubs(:terminus).with(:test, :foo).returns(@terminus_class)
+ Puppet::Indirector::Terminus.stubs(:terminus_class).with(:test, :foo).returns(@terminus_class)
end
it "should create an instance of the chosen terminus class" do
diff --git a/spec/unit/indirector/indirector.rb b/spec/unit/indirector/indirector.rb
index 23637ec7c..47e93cbaa 100755
--- a/spec/unit/indirector/indirector.rb
+++ b/spec/unit/indirector/indirector.rb
@@ -36,16 +36,9 @@ describe Puppet::Indirector, "when registering an indirection" do
Proc.new { @thingie.indirects :second }.should raise_error(ArgumentError)
end
- it "should set up instance loading for the indirection" do
- Puppet::Indirector.expects(:instance_load).with(:test, "puppet/indirector/test")
- @indirection = @thingie.indirects(:test)
- end
-
after do
@indirection.delete if @indirection
end
-
-# TODO: node lookup retries/searching
end
describe Puppet::Indirector, " when redirecting model" do
@@ -83,27 +76,3 @@ describe Puppet::Indirector, " when redirecting model" do
@indirection.delete
end
end
-
-describe Puppet::Indirector, " when retrieving terminus classes" do
- it "should allow terminus classes to register themselves"
-
- it "should provide a method to retrieve a terminus class by name and indirection" do
- Puppet::Indirector.expects(:loaded_instance).with(:indirection, :terminus)
- Puppet::Indirector.terminus(:indirection, :terminus)
- end
-end
-
-
-# describe Puppet::Indirector::Terminus do
-# it "should register itself" # ???
-#
-# it "should allow for finding an object from a collection"
-# it "should allow for finding matching objects from a collection"
-# it "should allow for destroying an object in a collection"
-# it "should allow an object to be saved to a collection"
-# it "should allow an object class to pre-process its arguments"
-# it "should allow an object class to be in a read-only collection"
-#
-# it "should look up the appropriate decorator for the class"
-# it "should call "
-# end
diff --git a/spec/unit/indirector/terminus.rb b/spec/unit/indirector/terminus.rb
index c5f5c064a..08e7e6ccb 100755
--- a/spec/unit/indirector/terminus.rb
+++ b/spec/unit/indirector/terminus.rb
@@ -4,33 +4,40 @@ require 'puppet/indirector'
describe Puppet::Indirector::Terminus do
before do
- @indirection = stub 'indirection', :name => :mystuff
+ Puppet::Indirector::Terminus.stubs(:register_terminus_class)
+
+ @indirection = stub 'indirection', :name => :mystuff, :register_terminus_type => nil
Puppet::Indirector::Indirection.stubs(:instance).with(:mystuff).returns(@indirection)
- @terminus = Class.new(Puppet::Indirector::Terminus) do
+ @abstract_terminus = Class.new(Puppet::Indirector::Terminus) do
+ def self.to_s
+ "Abstract"
+ end
+ end
+ @terminus = Class.new(@abstract_terminus) do
def self.to_s
"Terminus::Type::MyStuff"
end
end
end
- it "should support the documentation methods" do
+ it "should provide a method for setting terminus class documentation" do
@terminus.should respond_to(:desc)
end
- # LAK:FIXME I don't really know the best way to test this kind of
- # requirement.
it "should support a class-level name attribute" do
@terminus.should respond_to(:name)
- @terminus.should respond_to(:name=)
end
it "should support a class-level indirection attribute" do
@terminus.should respond_to(:indirection)
- @terminus.should respond_to(:indirection=)
+ end
+
+ it "should support a class-level terminus-type attribute" do
+ @terminus.should respond_to(:terminus_type)
end
it "should accept indirection instances as its indirection" do
- indirection = stub 'indirection', :is_a? => true
+ indirection = stub 'indirection', :is_a? => true, :register_terminus_type => nil
proc { @terminus.indirection = indirection }.should_not raise_error
@terminus.indirection.should equal(indirection)
end
@@ -52,26 +59,43 @@ describe Puppet::Indirector::Terminus do
end
end
-describe Puppet::Indirector::Terminus, " when being subclassed" do
- it "should associate the subclass with an indirection based on the subclass constant" do
- indirection = mock 'indirection'
- Puppet::Indirector::Indirection.expects(:instance).with(:myindirection).returns(indirection)
+# LAK: This could reasonably be in the Indirection instances, too. It doesn't make
+# a whole heckuva lot of difference, except that with the instance loading in
+# the Terminus base class, we have to have a check to see if we're already
+# instance-loading a given terminus class type.
+describe Puppet::Indirector::Terminus, " when managing terminus classes" do
+ it "should provide a method for registering terminus classes" do
+ Puppet::Indirector::Terminus.should respond_to(:register_terminus_class)
+ end
- klass = Class.new(Puppet::Indirector::Terminus) do
- def self.to_s
- "Puppet::Indirector::Terminus::MyIndirection"
- end
- end
+ it "should provide a method for returning terminus classes by name and type" do
+ terminus = stub 'terminus_type', :terminus_type => :abstract, :name => :whatever
+ Puppet::Indirector::Terminus.register_terminus_class(terminus)
+ Puppet::Indirector::Terminus.terminus_class(:abstract, :whatever).should equal(terminus)
+ end
- klass.indirection.should equal(indirection)
+ it "should set up autoloading for any terminus class types requested" do
+ Puppet::Indirector::Terminus.expects(:instance_load).with(:test2, "puppet/indirector/test2")
+ Puppet::Indirector::Terminus.terminus_class(:test2, :whatever)
end
- it "should fail when the terminus subclass does not include its parent class in the constant path" do
- indirection = mock 'indirection'
- Puppet::Indirector::Indirection.expects(:instance).with(:myindirection).returns(indirection)
+ it "should load terminus classes that are not found" do
+ # Set up instance loading; it would normally happen automatically
+ Puppet::Indirector::Terminus.instance_load :test1, "puppet/indirector/test1"
+ Puppet::Indirector::Terminus.instance_loader(:test1).expects(:load).with(:yay)
+ Puppet::Indirector::Terminus.terminus_class(:test1, :yay)
+ end
+
+ it "should fail when no indirection can be found" do
+ Puppet::Indirector::Indirection.expects(:instance).with(:myindirection).returns(nil)
+ @abstract_terminus = Class.new(Puppet::Indirector::Terminus) do
+ def self.to_s
+ "Abstract"
+ end
+ end
proc {
- klass = Class.new(Puppet::Indirector::Terminus) do
+ @terminus = Class.new(@abstract_terminus) do
def self.to_s
"MyIndirection"
end
@@ -79,27 +103,95 @@ describe Puppet::Indirector::Terminus, " when being subclassed" do
}.should raise_error(ArgumentError)
end
- it "should set the subclass's name to the terminus type" do
- indirection = mock 'indirection'
- Puppet::Indirector::Indirection.expects(:instance).with(:myindirection).returns(indirection)
+ it "should register the terminus class with the terminus base class" do
+ Puppet::Indirector::Terminus.expects(:register_terminus_class).with do |type|
+ type.terminus_type == :abstract and type.name == :myindirection
+ end
+ @indirection = stub 'indirection', :name => :myind, :register_terminus_type => nil
+ Puppet::Indirector::Indirection.expects(:instance).with(:myindirection).returns(@indirection)
- klass = Class.new(Puppet::Indirector::Terminus) do
+ @abstract_terminus = Class.new(Puppet::Indirector::Terminus) do
def self.to_s
- "Puppet::Indirector::Terminus::Yaml::MyIndirection"
+ "Abstract"
end
end
- klass.name.should == :yaml
+ @terminus = Class.new(@abstract_terminus) do
+ def self.to_s
+ "MyIndirection"
+ end
+ end
+ end
+end
+
+describe Puppet::Indirector::Terminus, " when creating terminus class types" do
+ before do
+ Puppet::Indirector::Terminus.stubs(:register_terminus_class)
+ @subclass = Class.new(Puppet::Indirector::Terminus) do
+ def self.to_s
+ "Puppet::Indirector::Terminus::MyTermType"
+ end
+ end
+ end
+
+ it "should set the name of the abstract subclass to be its class constant" do
+ @subclass.name.should equal(:mytermtype)
+ end
+
+ it "should mark abstract terminus types as such" do
+ @subclass.should be_abstract_terminus
+ end
+
+ it "should not allow instances of abstract subclasses to be created" do
+ proc { @subclass.new }.should raise_error(Puppet::DevError)
+ end
+end
+
+describe Puppet::Indirector::Terminus, " when creating terminus classes" do
+ before do
+ Puppet::Indirector::Terminus.stubs(:register_terminus_class)
+
+ @indirection = stub 'indirection', :name => :myind, :register_terminus_type => nil
+ Puppet::Indirector::Indirection.expects(:instance).with(:myindirection).returns(@indirection)
+
+ @abstract_terminus = Class.new(Puppet::Indirector::Terminus) do
+ def self.to_s
+ "Abstract"
+ end
+ end
+ @terminus = Class.new(@abstract_terminus) do
+ def self.to_s
+ "MyIndirection"
+ end
+ end
+ end
+
+ it "should associate the subclass with an indirection based on the subclass constant" do
+ @terminus.indirection.should equal(@indirection)
+ end
+
+ it "should set the subclass's type to the abstract terminus name" do
+ @terminus.terminus_type.should == :abstract
+ end
+
+ it "should set the subclass's name to the indirection name" do
+ @terminus.name.should == :myindirection
end
end
describe Puppet::Indirector::Terminus, " when a terminus instance" do
before do
- @indirection = stub 'indirection', :name => :myyaml
+ Puppet::Indirector::Terminus.stubs(:register_terminus_class)
+ @indirection = stub 'indirection', :name => :myyaml, :register_terminus_type => nil
Puppet::Indirector::Indirection.stubs(:instance).with(:mystuff).returns(@indirection)
- @terminus_class = Class.new(Puppet::Indirector::Terminus) do
+ @abstract_terminus = Class.new(Puppet::Indirector::Terminus) do
def self.to_s
- "Terminus::Type::MyStuff"
+ "Abstract"
+ end
+ end
+ @terminus_class = Class.new(@abstract_terminus) do
+ def self.to_s
+ "MyStuff"
end
end
@terminus_class.name = :test
@@ -114,8 +206,7 @@ describe Puppet::Indirector::Terminus, " when a terminus instance" do
@terminus.indirection.should equal(@indirection)
end
- it "should require an associated indirection" do
- @terminus_class.expects(:indirection).returns(nil)
- proc { @terminus_class.new }.should raise_error(Puppet::DevError)
+ it "should set the instances's type to the abstract terminus type's name" do
+ @terminus.terminus_type.should == :abstract
end
end
diff --git a/spec/unit/indirector/yaml.rb b/spec/unit/indirector/yaml.rb
index 93af048f9..339a2acfb 100755
--- a/spec/unit/indirector/yaml.rb
+++ b/spec/unit/indirector/yaml.rb
@@ -6,9 +6,13 @@ require 'puppet/indirector/yaml'
module YamlTesting
def setup
- @store_class = Class.new(Puppet::Indirector::Yaml)
- @indirection = stub 'indirection', :name => :myyaml
- @store_class.stubs(:indirection).returns(@indirection)
+ @indirection = stub 'indirection', :name => :myyaml, :register_terminus_type => nil
+ Puppet::Indirector::Indirection.stubs(:instance).with(:myyaml).returns(@indirection)
+ @store_class = Class.new(Puppet::Indirector::Yaml) do
+ def self.to_s
+ "MyYaml"
+ end
+ end
@store = @store_class.new
@subject = Object.new
@@ -21,19 +25,6 @@ module YamlTesting
end
end
-describe Puppet::Indirector::Yaml, " when initializing" do
- before do
- @store_class = Class.new(Puppet::Indirector::Yaml)
- end
-
- # The superclass tests for the same thing, but it doesn't hurt to
- # leave this in the spec.
- it "should require an associated indirection" do
- @store_class.expects(:indirection).returns(nil)
- proc { @store_class.new }.should raise_error(Puppet::DevError)
- end
-end
-
describe Puppet::Indirector::Yaml, " when choosing file location" do
include YamlTesting
@@ -41,7 +32,7 @@ describe Puppet::Indirector::Yaml, " when choosing file location" do
@store.send(:path, :me).should =~ %r{^#{@dir}}
end
- it "should use the indirection name for choosing the subdirectory" do
+ it "should use the terminus name for choosing the subdirectory" do
@store.send(:path, :me).should =~ %r{^#{@dir}/myyaml}
end
diff --git a/spec/unit/indirector/yaml/facts.rb b/spec/unit/indirector/yaml/facts.rb
new file mode 100755
index 000000000..f1256cfa4
--- /dev/null
+++ b/spec/unit/indirector/yaml/facts.rb
@@ -0,0 +1,26 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+require 'puppet/node/facts'
+require 'puppet/indirector/yaml/facts'
+
+describe Puppet::Indirector::Yaml::Facts do
+ it "should be a subclass of the Yaml terminus" do
+ Puppet::Indirector::Yaml::Facts.superclass.should equal(Puppet::Indirector::Yaml)
+ end
+
+
+ it "should have documentation" do
+ Puppet::Indirector::Yaml::Facts.doc.should_not be_nil
+ end
+
+ it "should be registered with the facts indirection" do
+ indirection = Puppet::Indirector::Indirection.instance(:facts)
+ Puppet::Indirector::Yaml::Facts.indirection.should equal(indirection)
+ end
+
+ it "should have its name set to :facts" do
+ Puppet::Indirector::Yaml::Facts.name.should == :facts
+ end
+end