pairing with luke, nagios_command provider skeleton
[vinpup.git] / spec / unit / resource_reference.rb
blobef172d80ac47eece0e92ce51e7bdc66b75733779
1 #!/usr/bin/env ruby
3 require File.dirname(__FILE__) + '/../spec_helper'
5 require 'puppet/resource_reference'
7 describe Puppet::ResourceReference do
8     it "should have a :title attribute" do
9         Puppet::ResourceReference.new(:file, "foo").title.should == "foo"
10     end
12     it "should canonize types to capitalized strings" do
13         Puppet::ResourceReference.new(:file, "foo").type.should == "File"
14     end
16     it "should canonize qualified types so all strings are capitalized" do
17         Puppet::ResourceReference.new("foo::bar", "foo").type.should == "Foo::Bar"
18     end
20     it "should set its type to 'Class' and its title to the passed title if the passed type is :component and the title has no square brackets in it" do
21         ref = Puppet::ResourceReference.new(:component, "foo")
22         ref.type.should == "Class"
23         ref.title.should == "foo"
24     end
26     it "should interpret the title as a reference and assign appropriately if the type is :component and the title contains square brackets" do
27         ref = Puppet::ResourceReference.new(:component, "foo::bar[yay]")
28         ref.type.should == "Foo::Bar"
29         ref.title.should == "yay"
30     end
32     it "should set the type to 'Class' if it is nil and the title contains no square brackets" do
33         ref = Puppet::ResourceReference.new(nil, "yay")
34         ref.type.should == "Class"
35         ref.title.should == "yay"
36     end
38     it "should interpret the title as a reference and assign appropriately if the type is nil and the title contains square brackets" do
39         ref = Puppet::ResourceReference.new(nil, "foo::bar[yay]")
40         ref.type.should == "Foo::Bar"
41         ref.title.should == "yay"
42     end
43 end
45 describe Puppet::ResourceReference, "when resolving resources without a catalog" do
46     it "should be able to resolve builtin resources from their types" do
47         Puppet::Type.type(:file).expects(:[]).with("myfile").returns(:myfile)
48         Puppet::ResourceReference.new(:file, "myfile").resolve.should == :myfile
49     end
51     it "should be able to resolve defined resources from Components" do
52         Puppet::Type.type(:component).expects(:[]).with("Foo::Bar[yay]").returns(:mything)
53         Puppet::ResourceReference.new("foo::bar", "yay").resolve.should == :mything
54     end
55 end
57 describe Puppet::ResourceReference, "when resolving resources with a catalog" do
58     it "should resolve all resources using the catalog" do
59         config = mock 'catalog'
60         ref = Puppet::ResourceReference.new("foo::bar", "yay")
61         ref.catalog = config
63         config.expects(:resource).with("Foo::Bar[yay]").returns(:myresource)
65         ref.resolve.should == :myresource
66     end
67 end