~ubuntu-branches/ubuntu/trusty/puppet/trusty

« back to all changes in this revision

Viewing changes to spec/unit/interface/face_collection_spec.rb

  • Committer: Package Import Robot
  • Author(s): Stig Sandbeck Mathisen
  • Date: 2011-10-22 14:08:22 UTC
  • mfrom: (1.1.25) (3.1.32 sid)
  • Revision ID: package-import@ubuntu.com-20111022140822-odxde5lohc45yhuz
Tags: 2.7.6-1
* New upstream release (CVE-2011-3872)
* Remove cherry-picked "groupadd_aix_warning" patch
* Install all new manpages

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
    @original_required.each {|f| $".push f unless $".include? f }
26
26
  end
27
27
 
28
 
  describe "::prefix_match?" do
29
 
    #   want     have
30
 
    { ['1.0.0', '1.0.0'] => true,
31
 
      ['1.0',   '1.0.0'] => true,
32
 
      ['1',     '1.0.0'] => true,
33
 
      ['1.0.0', '1.1.0'] => false,
34
 
      ['1.0',   '1.1.0'] => false,
35
 
      ['1',     '1.1.0'] => true,
36
 
      ['1.0.1', '1.0.0'] => false,
37
 
    }.each do |data, result|
38
 
      it "should return #{result.inspect} for prefix_match?(#{data.join(', ')})" do
39
 
        subject.prefix_match?(*data).should == result
40
 
      end
41
 
    end
42
 
  end
43
 
 
44
 
  describe "::validate_version" do
45
 
    { '10.10.10'     => true,
46
 
      '1.2.3.4'      => false,
47
 
      '10.10.10beta' => true,
48
 
      '10.10'        => false,
49
 
      '123'          => false,
50
 
      'v1.1.1'       => false,
51
 
    }.each do |input, result|
52
 
      it "should#{result ? '' : ' not'} permit #{input.inspect}" do
53
 
        subject.validate_version(input).should(result ? be_true : be_false)
54
 
      end
55
 
    end
56
 
  end
57
 
 
58
28
  describe "::[]" do
59
29
    before :each do
60
 
      subject.instance_variable_get("@faces")[:foo]['0.0.1'] = 10
 
30
      subject.instance_variable_get("@faces")[:foo][SemVer.new('0.0.1')] = 10
61
31
    end
62
32
 
63
33
    it "should return the face with the given name" do
65
35
    end
66
36
 
67
37
    it "should attempt to load the face if it isn't found" do
68
 
      subject.expects(:require).with('puppet/face/bar')
 
38
      subject.expects(:require).once.with('puppet/face/bar')
 
39
      subject.expects(:require).once.with('puppet/face/0.0.1/bar')
69
40
      subject["bar", '0.0.1']
70
41
    end
71
42
 
75
46
    end
76
47
 
77
48
    it "should return true if the face specified is registered" do
78
 
      subject.instance_variable_get("@faces")[:foo]['0.0.1'] = 10
 
49
      subject.instance_variable_get("@faces")[:foo][SemVer.new('0.0.1')] = 10
79
50
      subject["foo", '0.0.1'].should == 10
80
51
    end
81
52
 
82
53
    it "should attempt to require the face if it is not registered" do
83
54
      subject.expects(:require).with do |file|
84
 
        subject.instance_variable_get("@faces")[:bar]['0.0.1'] = true
 
55
        subject.instance_variable_get("@faces")[:bar][SemVer.new('0.0.1')] = true
85
56
        file == 'puppet/face/bar'
86
57
      end
87
58
      subject["bar", '0.0.1'].should be_true
94
65
 
95
66
    it "should return false if the face file itself is missing" do
96
67
      subject.stubs(:require).
97
 
        raises(LoadError, 'no such file to load -- puppet/face/bar')
 
68
        raises(LoadError, 'no such file to load -- puppet/face/bar').then.
 
69
        raises(LoadError, 'no such file to load -- puppet/face/0.0.1/bar')
98
70
      subject["bar", '0.0.1'].should be_false
99
71
    end
100
72
 
127
99
    end
128
100
  end
129
101
 
 
102
  describe "::get_action_for_face" do
 
103
    it "should return an action on the current face" do
 
104
      Puppet::Face::FaceCollection.get_action_for_face(:huzzah, :bar, :current).
 
105
        should be_an_instance_of Puppet::Interface::Action
 
106
    end
 
107
 
 
108
    it "should return an action on an older version of a face" do
 
109
      action = Puppet::Face::FaceCollection.
 
110
        get_action_for_face(:huzzah, :obsolete, :current)
 
111
 
 
112
      action.should be_an_instance_of Puppet::Interface::Action
 
113
      action.face.version.should == SemVer.new('1.0.0')
 
114
    end
 
115
 
 
116
    it "should load the full older version of a face" do
 
117
      action = Puppet::Face::FaceCollection.
 
118
        get_action_for_face(:huzzah, :obsolete, :current)
 
119
 
 
120
      action.face.version.should == SemVer.new('1.0.0')
 
121
      action.face.should be_action :obsolete_in_core
 
122
    end
 
123
 
 
124
    it "should not add obsolete actions to the current version" do
 
125
      action = Puppet::Face::FaceCollection.
 
126
        get_action_for_face(:huzzah, :obsolete, :current)
 
127
 
 
128
      action.face.version.should == SemVer.new('1.0.0')
 
129
      action.face.should be_action :obsolete_in_core
 
130
 
 
131
      current = Puppet::Face[:huzzah, :current]
 
132
      current.version.should == SemVer.new('2.0.1')
 
133
      current.should_not be_action :obsolete_in_core
 
134
      current.should_not be_action :obsolete
 
135
    end
 
136
  end
 
137
 
130
138
  describe "::register" do
131
139
    it "should store the face by name" do
132
140
      face = Puppet::Face.new(:my_face, '0.0.1')
133
141
      subject.register(face)
134
 
      subject.instance_variable_get("@faces").should == {:my_face => {'0.0.1' => face}}
 
142
      subject.instance_variable_get("@faces").should == {
 
143
        :my_face => { face.version => face }
 
144
      }
135
145
    end
136
146
  end
137
147