~bkerensa/ubuntu/raring/puppet/new-upstream-release

« back to all changes in this revision

Viewing changes to spec/unit/application/resource_spec.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-07-25 01:00:37 UTC
  • mfrom: (1.1.24 upstream) (3.1.25 sid)
  • Revision ID: james.westby@ubuntu.com-20110725010037-875vuxs10eboqgw3
Tags: 2.7.1-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - debian/puppetmaster-passenger.postinst: Use cacrl instead of hostcrl to
    set the location of the CRL in apache2 configuration. Fix apache2
    configuration on upgrade as well (LP: #641001)
  - move all puppet dependencies to puppet-common since all the code
    actually located in puppet-common.
  - move libagueas from a recommend to a dependency.

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'
 
1
#!/usr/bin/env rspec
 
2
require 'spec_helper'
4
3
 
5
4
require 'puppet/application/resource'
6
5
 
8
7
  before :each do
9
8
    @resource = Puppet::Application[:resource]
10
9
    Puppet::Util::Log.stubs(:newdestination)
11
 
    Puppet::Util::Log.stubs(:level=)
12
10
    Puppet::Resource.indirection.stubs(:terminus_class=)
13
11
  end
14
12
 
37
35
  end
38
36
 
39
37
  describe "in preinit" do
40
 
    it "should set hosts to nil" do
 
38
    it "should set hosts to nil", :'fails_on_ruby_1.9.2' => true do
41
39
      @resource.preinit
42
40
 
43
41
      @resource.host.should be_nil
44
42
    end
45
43
 
46
 
    it "should init extra_params to empty array" do
 
44
    it "should init extra_params to empty array", :'fails_on_ruby_1.9.2' => true do
47
45
      @resource.preinit
48
46
 
49
47
      @resource.extra_params.should == []
79
77
      type2 = stub_everything 'type2', :name => :type2
80
78
      Puppet::Type.stubs(:loadall)
81
79
      Puppet::Type.stubs(:eachtype).multiple_yields(type1,type2)
82
 
      @resource.stubs(:exit)
83
 
 
84
80
      @resource.expects(:puts).with(['type1','type2'])
85
 
      @resource.handle_types(nil)
 
81
      expect { @resource.handle_types(nil) }.to exit_with 0
86
82
    end
87
83
 
88
84
    it "should add param to extra_params list" do
96
92
  describe "during setup" do
97
93
    before :each do
98
94
      Puppet::Log.stubs(:newdestination)
99
 
      Puppet::Log.stubs(:level=)
100
95
      Puppet.stubs(:parse_config)
101
96
    end
102
97
 
109
104
 
110
105
    it "should set log level to debug if --debug was passed" do
111
106
      @resource.options.stubs(:[]).with(:debug).returns(true)
112
 
 
113
 
      Puppet::Log.expects(:level=).with(:debug)
114
 
 
115
107
      @resource.setup
 
108
      Puppet::Log.level.should == :debug
116
109
    end
117
110
 
118
111
    it "should set log level to info if --verbose was passed" do
119
112
      @resource.options.stubs(:[]).with(:debug).returns(false)
120
113
      @resource.options.stubs(:[]).with(:verbose).returns(true)
121
 
 
122
 
      Puppet::Log.expects(:level=).with(:info)
123
 
 
124
114
      @resource.setup
 
115
      Puppet::Log.level.should == :info
125
116
    end
126
117
 
127
118
    it "should Parse puppet config" do
162
153
        @resource.stubs(:puts)
163
154
        @resource.host = 'host'
164
155
 
165
 
        Puppet::Resource.stubs(:find  ).never
166
 
        Puppet::Resource.stubs(:search).never
167
 
        Puppet::Resource.stubs(:save  ).never
 
156
        Puppet::Resource.indirection.stubs(:find  ).never
 
157
        Puppet::Resource.indirection.stubs(:search).never
 
158
        Puppet::Resource.indirection.stubs(:save  ).never
168
159
      end
169
160
 
170
161
      it "should search for resources" do
171
162
        @resource.command_line.stubs(:args).returns(['type'])
172
 
        Puppet::Resource.expects(:search).with('https://host:8139/production/resources/type/', {}).returns([])
 
163
        Puppet::Resource.indirection.expects(:search).with('https://host:8139/production/resources/type/', {}).returns([])
173
164
        @resource.main
174
165
      end
175
166
 
176
167
      it "should describe the given resource" do
177
168
        @resource.command_line.stubs(:args).returns(['type', 'name'])
178
169
        x = stub_everything 'resource'
179
 
        Puppet::Resource.expects(:find).with('https://host:8139/production/resources/type/name').returns(x)
 
170
        Puppet::Resource.indirection.expects(:find).with('https://host:8139/production/resources/type/name').returns(x)
180
171
        @resource.main
181
172
      end
182
173
 
184
175
        @resource.command_line.stubs(:args).returns(['type','name','param=temp'])
185
176
 
186
177
        res = stub "resource"
187
 
        res.expects(:save).with('https://host:8139/production/resources/type/name').returns(res)
 
178
        Puppet::Resource.indirection.expects(:save).with(res, 'https://host:8139/production/resources/type/name').returns(res)
188
179
        res.expects(:collect)
189
180
        res.expects(:to_manifest)
190
181
        Puppet::Resource.expects(:new).with('type', 'name', :parameters => {'param' => 'temp'}).returns(res)
199
190
        @resource.stubs(:puts)
200
191
        @resource.host = nil
201
192
 
202
 
        Puppet::Resource.stubs(:find  ).never
203
 
        Puppet::Resource.stubs(:search).never
204
 
        Puppet::Resource.stubs(:save  ).never
 
193
        Puppet::Resource.indirection.stubs(:find  ).never
 
194
        Puppet::Resource.indirection.stubs(:search).never
 
195
        Puppet::Resource.indirection.stubs(:save  ).never
205
196
      end
206
197
 
207
198
      it "should search for resources" do
208
 
        Puppet::Resource.expects(:search).with('type/', {}).returns([])
 
199
        Puppet::Resource.indirection.expects(:search).with('type/', {}).returns([])
209
200
        @resource.main
210
201
      end
211
202
 
212
203
      it "should describe the given resource" do
213
204
        @resource.command_line.stubs(:args).returns(['type','name'])
214
205
        x = stub_everything 'resource'
215
 
        Puppet::Resource.expects(:find).with('type/name').returns(x)
 
206
        Puppet::Resource.indirection.expects(:find).with('type/name').returns(x)
216
207
        @resource.main
217
208
      end
218
209
 
220
211
        @resource.command_line.stubs(:args).returns(['type','name','param=temp'])
221
212
 
222
213
        res = stub "resource"
223
 
        res.expects(:save).with('type/name').returns(res)
 
214
        Puppet::Resource.indirection.expects(:save).with(res, 'type/name').returns(res)
224
215
        res.expects(:collect)
225
216
        res.expects(:to_manifest)
226
217
        Puppet::Resource.expects(:new).with('type', 'name', :parameters => {'param' => 'temp'}).returns(res)