~nvalcarcel/ubuntu/lucid/puppet/fix-546677

« back to all changes in this revision

Viewing changes to spec/unit/resource_reference.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-12-23 00:48:10 UTC
  • mfrom: (1.1.10 upstream) (3.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091223004810-3i4oryds922g5n59
Tags: 0.25.1-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - debian/rules:
    + Don't start puppet when first installing puppet.
  - debian/puppet.conf, lib/puppet/defaults.rb:
    + Move templates to /etc/puppet
  - lib/puppet/defaults.rb:
    + Fix /var/lib/puppet/state ownership.
  - man/man8/puppet.conf.8: 
    + Fix broken URL in manpage.
  - debian/control:
    + Update maintainer accordint to spec.
    + Puppetmaster Recommends -> Suggests
    + Created puppet-testsuite as a seperate. Allow the users to run puppet's 
      testsuite.
  - tests/Rakefile: Fix rakefile so that the testsuite can acutally be ran.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env ruby
2
 
 
3
 
require File.dirname(__FILE__) + '/../spec_helper'
4
 
 
5
 
require 'puppet/resource_reference'
6
 
 
7
 
describe Puppet::ResourceReference do
8
 
    it "should have a :title attribute" do
9
 
        Puppet::ResourceReference.new(:file, "foo").title.should == "foo"
10
 
    end
11
 
 
12
 
    it "should canonize types to capitalized strings" do
13
 
        Puppet::ResourceReference.new(:file, "foo").type.should == "File"
14
 
    end
15
 
 
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
19
 
 
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
25
 
 
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
31
 
 
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
37
 
 
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
 
 
44
 
    it "should interpret the title as a reference and assign appropriately if the type is nil and the title contains nested square brackets" do
45
 
        ref = Puppet::ResourceReference.new(nil, "foo::bar[baz[yay]]")
46
 
        ref.type.should == "Foo::Bar"
47
 
        ref.title.should =="baz[yay]"
48
 
    end
49
 
end
50
 
 
51
 
describe Puppet::ResourceReference, "when resolving resources without a catalog" do
52
 
    it "should be able to resolve builtin resources from their types" do
53
 
        Puppet::Type.type(:file).expects(:[]).with("myfile").returns(:myfile)
54
 
        Puppet::ResourceReference.new(:file, "myfile").resolve.should == :myfile
55
 
    end
56
 
 
57
 
    it "should be able to resolve defined resources from Components" do
58
 
        Puppet::Type.type(:component).expects(:[]).with("Foo::Bar[yay]").returns(:mything)
59
 
        Puppet::ResourceReference.new("foo::bar", "yay").resolve.should == :mything
60
 
    end
61
 
end
62
 
 
63
 
describe Puppet::ResourceReference, "when resolving resources with a catalog" do
64
 
    it "should resolve all resources using the catalog" do
65
 
        config = mock 'catalog'
66
 
        ref = Puppet::ResourceReference.new("foo::bar", "yay")
67
 
        ref.catalog = config
68
 
 
69
 
        config.expects(:resource).with("Foo::Bar[yay]").returns(:myresource)
70
 
 
71
 
        ref.resolve.should == :myresource
72
 
    end
73
 
end