diff options
| author | Luke Kanies <luke@puppetlabs.com> | 2010-04-17 19:46:23 -0700 |
|---|---|---|
| committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
| commit | 8b99367ccedefe0e341a79487ccea2a95f2720a3 (patch) | |
| tree | 4dca9eeeda8be43006eda6acf0d66aa7a874560e /spec/unit | |
| parent | 748aed9a4fe70cc2ecc0c782b694114356d9eb25 (diff) | |
| download | puppet-8b99367ccedefe0e341a79487ccea2a95f2720a3.tar.gz puppet-8b99367ccedefe0e341a79487ccea2a95f2720a3.tar.xz puppet-8b99367ccedefe0e341a79487ccea2a95f2720a3.zip | |
Adding indirector support to Resource Types
Also adding JSON support.
This is so that we can remotely retrieve information
about resource types and classes, such as what arguments
are required.
Signed-off-by: Luke Kanies <luke@puppetlabs.com>
Diffstat (limited to 'spec/unit')
| -rwxr-xr-x | spec/unit/indirector/resource_type/parser.rb | 75 | ||||
| -rwxr-xr-x | spec/unit/indirector/resource_type/rest.rb | 15 | ||||
| -rwxr-xr-x | spec/unit/resource/type.rb | 41 |
3 files changed, 131 insertions, 0 deletions
diff --git a/spec/unit/indirector/resource_type/parser.rb b/spec/unit/indirector/resource_type/parser.rb new file mode 100755 index 000000000..331ca1c9b --- /dev/null +++ b/spec/unit/indirector/resource_type/parser.rb @@ -0,0 +1,75 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +require 'puppet/indirector/resource_type/parser' + +describe Puppet::Indirector::ResourceType::Parser do + before do + @terminus = Puppet::Indirector::ResourceType::Parser.new + @request = Puppet::Indirector::Request.new(:resource_type, :find, "foo") + @krt = Puppet::Resource::TypeCollection.new(@request.environment) + @request.environment.stubs(:known_resource_types).returns @krt + end + + it "should be registered with the resource_type indirection" do + Puppet::Indirector::Terminus.terminus_class(:resource_type, :parser).should equal(Puppet::Indirector::ResourceType::Parser) + end + + describe "when finding" do + it "should use the request's environment's list of known resource types" do + @request.environment.known_resource_types.expects(:hostclass).returns nil + + @terminus.find(@request) + end + + it "should return any found type" do + type = @krt.add(Puppet::Resource::Type.new(:hostclass, "foo")) + + @terminus.find(@request).should == type + end + + it "should return nil if no type can be found" do + @terminus.find(@request).should be_nil + end + + it "should prefer definitions to nodes" do + type = @krt.add(Puppet::Resource::Type.new(:hostclass, "foo")) + node = @krt.add(Puppet::Resource::Type.new(:node, "foo")) + + @terminus.find(@request).should == type + end + end + + describe "when searching" do + before do + @request.key = "*" + end + + it "should use the request's environment's list of known resource types" do + @request.environment.known_resource_types.expects(:hostclasses).returns({}) + + @terminus.search(@request) + end + + it "should fail if anyther other than '*' was provided as the search key" do + @request.key = "foo*" + lambda { @terminus.search(@request) }.should raise_error(ArgumentError) + end + + it "should return all known types" do + type = @krt.add(Puppet::Resource::Type.new(:hostclass, "foo")) + node = @krt.add(Puppet::Resource::Type.new(:node, "bar")) + define = @krt.add(Puppet::Resource::Type.new(:definition, "baz")) + + result = @terminus.search(@request) + result.should be_include(type) + result.should be_include(node) + result.should be_include(define) + end + + it "should return nil if no types can be found" do + @terminus.search(@request).should be_nil + end + end +end diff --git a/spec/unit/indirector/resource_type/rest.rb b/spec/unit/indirector/resource_type/rest.rb new file mode 100755 index 000000000..28196d53a --- /dev/null +++ b/spec/unit/indirector/resource_type/rest.rb @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +require 'puppet/indirector/resource_type/rest' + +describe Puppet::Indirector::ResourceType::Rest do + it "should be registered with the resource_type indirection" do + Puppet::Indirector::Terminus.terminus_class(:resource_type, :rest).should equal(Puppet::Indirector::ResourceType::Rest) + end + + it "should be a subclass of Puppet::Indirector::Rest" do + Puppet::Indirector::ResourceType::Rest.superclass.should == Puppet::Indirector::REST + end +end diff --git a/spec/unit/resource/type.rb b/spec/unit/resource/type.rb index bbf2f736d..8c024d7e4 100755 --- a/spec/unit/resource/type.rb +++ b/spec/unit/resource/type.rb @@ -23,6 +23,47 @@ describe Puppet::Resource::Type do end end + it "should indirect 'resource_type'" do + Puppet::Resource::Type.indirection.name.should == :resource_type + end + + it "should default to 'parser' for its terminus class" do + Puppet::Resource::Type.indirection.terminus_class.should == :parser + end + + describe "when converting to json" do + before do + @type = Puppet::Resource::Type.new(:hostclass, "foo") + end + + def from_json(json) + Puppet::Resource::Type.from_pson(json) + end + + def double_convert + Puppet::Resource::Type.from_pson(PSON.parse(@type.to_pson)) + end + + it "should include the name and type" do + double_convert.name.should == @type.name + double_convert.type.should == @type.type + end + + it "should include any arguments" do + @type.set_arguments("one" => nil, "two" => "foo") + + double_convert.arguments.should == {"one" => nil, "two" => "foo"} + end + + it "should include any extra attributes" do + @type.file = "/my/file" + @type.line = 50 + + double_convert.file.should == "/my/file" + double_convert.line.should == 50 + end + end + describe "when a node" do it "should allow a regex as its name" do lambda { Puppet::Resource::Type.new(:node, /foo/) }.should_not raise_error |
