diff options
| author | Luke Kanies <luke@madstop.com> | 2007-09-21 19:28:01 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2007-09-21 19:28:01 -0500 |
| commit | b9dc6cb22f087f419b328cafa945c9604043b22f (patch) | |
| tree | ac7eabff6140018f860c85105941c564eb3dd5b2 /spec | |
| parent | 02275f0b29cee70e3f02d6d8f911eaaf3fad579d (diff) | |
It looks like the new indirection setup is complete.
I only need to port the node indirection termini over.
Diffstat (limited to 'spec')
| -rwxr-xr-x | spec/unit/indirector/facts/yaml.rb | 62 | ||||
| -rwxr-xr-x | spec/unit/indirector/indirection.rb | 10 | ||||
| -rwxr-xr-x | spec/unit/indirector/indirector.rb | 31 | ||||
| -rwxr-xr-x | spec/unit/indirector/terminus.rb | 159 | ||||
| -rwxr-xr-x | spec/unit/indirector/yaml.rb | 25 | ||||
| -rwxr-xr-x | spec/unit/indirector/yaml/facts.rb | 26 |
6 files changed, 164 insertions, 149 deletions
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 |
