summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/indirector/resource_type/parser.rb75
-rwxr-xr-xspec/unit/indirector/resource_type/rest.rb15
-rwxr-xr-xspec/unit/resource/type.rb41
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