~ubuntu-branches/ubuntu/lucid/puppet/lucid-security

« 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::Resource::Reference do
 
8
    it "should have a :title attribute" do
 
9
        Puppet::Resource::Reference.new(:file, "foo").title.should == "foo"
 
10
    end
 
11
 
 
12
    it "should canonize types to capitalized strings" do
 
13
        Puppet::Resource::Reference.new(:file, "foo").type.should == "File"
 
14
    end
 
15
 
 
16
    it "should canonize qualified types so all strings are capitalized" do
 
17
        Puppet::Resource::Reference.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::Resource::Reference.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::Resource::Reference.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::Resource::Reference.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::Resource::Reference.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::Resource::Reference.new(nil, "foo::bar[baz[yay]]")
 
46
        ref.type.should == "Foo::Bar"
 
47
        ref.title.should =="baz[yay]"
 
48
    end
 
49
 
 
50
    it "should interpret the type as a reference and assign appropriately if the title is nil and the type contains square brackets" do
 
51
        ref = Puppet::Resource::Reference.new("foo::bar[baz]")
 
52
        ref.type.should == "Foo::Bar"
 
53
        ref.title.should =="baz"
 
54
    end
 
55
 
 
56
    it "should be able to extract its information from a Puppet::Type instance" do
 
57
        ral = Puppet::Type.type(:file).new :path => "/foo"
 
58
        ref = Puppet::Resource::Reference.new(ral)
 
59
        ref.type.should == "File"
 
60
        ref.title.should == "/foo"
 
61
    end
 
62
 
 
63
 
 
64
    it "should fail if the title is nil and the type is not a valid resource reference string" do
 
65
        lambda { Puppet::Resource::Reference.new("foo") }.should raise_error(ArgumentError)
 
66
    end
 
67
 
 
68
    it "should be considered builtin if an existing resource type matches the type" do
 
69
        Puppet::Resource::Reference.new("file", "/f").should be_builtin_type
 
70
    end
 
71
 
 
72
    it "should be not considered builtin if an existing resource type does not match the type" do
 
73
        Puppet::Resource::Reference.new("foobar", "/f").should_not be_builtin_type
 
74
    end
 
75
 
 
76
    it "should be able to produce a backward-compatible reference array" do
 
77
        Puppet::Resource::Reference.new("foobar", "/f").to_trans_ref.should == %w{Foobar /f}
 
78
    end
 
79
 
 
80
    it "should downcase resource types when producing a backward-compatible reference array for builtin resource types" do
 
81
        Puppet::Resource::Reference.new("file", "/f").to_trans_ref.should == %w{file /f}
 
82
    end
 
83
 
 
84
    it "should be considered equivalent to another reference if their type and title match" do
 
85
        Puppet::Resource::Reference.new("file", "/f").should == Puppet::Resource::Reference.new("file", "/f")
 
86
    end
 
87
 
 
88
    it "should not be considered equivalent to a non-reference" do
 
89
        Puppet::Resource::Reference.new("file", "/f").should_not == "foo"
 
90
    end
 
91
 
 
92
    it "should not be considered equivalent to another reference if their types do not match" do
 
93
        Puppet::Resource::Reference.new("file", "/f").should_not == Puppet::Resource::Reference.new("exec", "/f")
 
94
    end
 
95
 
 
96
    it "should not be considered equivalent to another reference if their titles do not match" do
 
97
        Puppet::Resource::Reference.new("file", "/foo").should_not == Puppet::Resource::Reference.new("file", "/f")
 
98
    end
 
99
end
 
100
 
 
101
describe Puppet::Resource::Reference, "when resolving resources with a catalog" do
 
102
    it "should resolve all resources using the catalog" do
 
103
        config = mock 'catalog'
 
104
        ref = Puppet::Resource::Reference.new("foo::bar", "yay")
 
105
        ref.catalog = config
 
106
 
 
107
        config.expects(:resource).with("Foo::Bar[yay]").returns(:myresource)
 
108
 
 
109
        ref.resolve.should == :myresource
 
110
    end
 
111
end