puppet 2.6.4 → 2.6.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (221) hide show
  1. data/CHANGELOG +147 -0
  2. data/LICENSE +2 -2
  3. data/Rakefile +3 -4
  4. data/lib/puppet.rb +1 -1
  5. data/lib/puppet/application.rb +22 -5
  6. data/lib/puppet/application/apply.rb +2 -18
  7. data/lib/puppet/application/doc.rb +1 -4
  8. data/lib/puppet/application/inspect.rb +178 -0
  9. data/lib/puppet/configurer.rb +9 -11
  10. data/lib/puppet/configurer/plugin_handler.rb +0 -2
  11. data/lib/puppet/defaults.rb +12 -3
  12. data/lib/puppet/external/pson/pure/generator.rb +1 -22
  13. data/lib/puppet/file_bucket/dipper.rb +9 -3
  14. data/lib/puppet/file_bucket/file.rb +14 -94
  15. data/lib/puppet/indirector.rb +4 -0
  16. data/lib/puppet/indirector/catalog/active_record.rb +1 -1
  17. data/lib/puppet/indirector/file_bucket_file/file.rb +64 -75
  18. data/lib/puppet/indirector/indirection.rb +18 -8
  19. data/lib/puppet/indirector/resource/ral.rb +7 -2
  20. data/lib/puppet/indirector/rest.rb +19 -2
  21. data/lib/puppet/network/http/api/v1.rb +3 -0
  22. data/lib/puppet/network/http/handler.rb +16 -1
  23. data/lib/puppet/network/http/rack/rest.rb +1 -3
  24. data/lib/puppet/network/rest_authconfig.rb +4 -12
  25. data/lib/puppet/network/rights.rb +28 -14
  26. data/lib/puppet/parser/ast.rb +4 -0
  27. data/lib/puppet/parser/compiler.rb +18 -3
  28. data/lib/puppet/parser/functions/defined.rb +28 -6
  29. data/lib/puppet/parser/functions/fqdn_rand.rb +6 -3
  30. data/lib/puppet/parser/templatewrapper.rb +1 -0
  31. data/lib/puppet/property.rb +16 -1
  32. data/lib/puppet/property/keyvalue.rb +0 -2
  33. data/lib/puppet/property/list.rb +0 -2
  34. data/lib/puppet/provider/file/posix.rb +1 -3
  35. data/lib/puppet/provider/file/win32.rb +1 -3
  36. data/lib/puppet/provider/maillist/mailman.rb +3 -5
  37. data/lib/puppet/provider/mount.rb +2 -0
  38. data/lib/puppet/provider/nameservice/directoryservice.rb +2 -2
  39. data/lib/puppet/provider/package/freebsd.rb +2 -2
  40. data/lib/puppet/provider/zone/solaris.rb +1 -1
  41. data/lib/puppet/reference/configuration.rb +2 -2
  42. data/lib/puppet/reference/function.rb +4 -0
  43. data/lib/puppet/relationship.rb +4 -0
  44. data/lib/puppet/reports/store.rb +1 -19
  45. data/lib/puppet/resource.rb +11 -2
  46. data/lib/puppet/resource/status.rb +24 -3
  47. data/lib/puppet/resource/type.rb +24 -16
  48. data/lib/puppet/resource/type_collection.rb +4 -1
  49. data/lib/puppet/simple_graph.rb +4 -0
  50. data/lib/puppet/transaction.rb +1 -28
  51. data/lib/puppet/transaction/event.rb +9 -4
  52. data/lib/puppet/transaction/report.rb +42 -22
  53. data/lib/puppet/transaction/resource_harness.rb +99 -71
  54. data/lib/puppet/type.rb +22 -9
  55. data/lib/puppet/type/cron.rb +1 -5
  56. data/lib/puppet/type/exec.rb +4 -34
  57. data/lib/puppet/type/file.rb +19 -26
  58. data/lib/puppet/type/file/checksum.rb +1 -1
  59. data/lib/puppet/type/file/content.rb +2 -1
  60. data/lib/puppet/type/file/ctime.rb +18 -0
  61. data/lib/puppet/type/file/ensure.rb +1 -1
  62. data/lib/puppet/type/file/mode.rb +10 -44
  63. data/lib/puppet/type/file/mtime.rb +17 -0
  64. data/lib/puppet/type/file/owner.rb +1 -1
  65. data/lib/puppet/type/file/source.rb +0 -1
  66. data/lib/puppet/type/file/target.rb +1 -1
  67. data/lib/puppet/type/file/type.rb +5 -12
  68. data/lib/puppet/type/host.rb +1 -1
  69. data/lib/puppet/type/mount.rb +2 -2
  70. data/lib/puppet/type/package.rb +0 -2
  71. data/lib/puppet/type/service.rb +11 -5
  72. data/lib/puppet/type/user.rb +7 -9
  73. data/lib/puppet/type/yumrepo.rb +2 -2
  74. data/lib/puppet/type/zpool.rb +0 -4
  75. data/lib/puppet/util/checksums.rb +24 -1
  76. data/lib/puppet/util/command_line.rb +6 -2
  77. data/lib/puppet/util/command_line/puppet +5 -1
  78. data/lib/puppet/util/command_line/puppetca +2 -2
  79. data/lib/puppet/util/command_line/puppetd +11 -9
  80. data/lib/puppet/util/command_line/puppetdoc +2 -2
  81. data/lib/puppet/util/command_line/puppetmasterd +5 -0
  82. data/lib/puppet/util/log.rb +15 -8
  83. data/lib/puppet/util/log/destinations.rb +2 -0
  84. data/lib/puppet/util/log_paths.rb +1 -1
  85. data/lib/puppet/util/logging.rb +1 -1
  86. data/lib/puppet/util/metric.rb +1 -0
  87. data/lib/puppet/util/reference.rb +1 -10
  88. data/lib/puppet/util/settings.rb +1 -1
  89. data/lib/puppet/util/zaml.rb +30 -31
  90. data/spec/fixtures/unit/provider/mount/mount-output.aix.txt +7 -0
  91. data/spec/integration/application/apply_spec.rb +1 -2
  92. data/spec/integration/defaults_spec.rb +1 -0
  93. data/spec/integration/indirector/catalog/queue_spec.rb +1 -4
  94. data/spec/integration/indirector/report/rest_spec.rb +13 -17
  95. data/spec/integration/network/formats_spec.rb +2 -5
  96. data/spec/integration/network/server/mongrel_spec.rb +1 -2
  97. data/spec/integration/provider/mailalias/aliases_spec.rb +0 -1
  98. data/spec/integration/provider/package_spec.rb +1 -3
  99. data/spec/integration/provider/service/init_spec.rb +3 -9
  100. data/spec/integration/reference/providers_spec.rb +2 -2
  101. data/spec/integration/resource/catalog_spec.rb +1 -2
  102. data/spec/integration/transaction/report_spec.rb +1 -1
  103. data/spec/monkey_patches/alias_should_to_must.rb +2 -0
  104. data/spec/shared_behaviours/file_server_terminus.rb +1 -1
  105. data/spec/shared_behaviours/file_serving.rb +1 -1
  106. data/spec/shared_behaviours/memory_terminus.rb +1 -1
  107. data/spec/spec_helper.rb +8 -6
  108. data/spec/unit/application/agent_spec.rb +1 -0
  109. data/spec/unit/application/apply_spec.rb +7 -7
  110. data/spec/unit/application/doc_spec.rb +2 -2
  111. data/spec/unit/application/filebucket_spec.rb +1 -0
  112. data/spec/unit/application/inspect_spec.rb +278 -0
  113. data/spec/unit/application/kick_spec.rb +1 -3
  114. data/spec/unit/application/master_spec.rb +1 -3
  115. data/spec/unit/application/queue_spec.rb +1 -0
  116. data/spec/unit/application_spec.rb +63 -5
  117. data/spec/unit/configurer/plugin_handler_spec.rb +5 -1
  118. data/spec/unit/configurer_spec.rb +33 -49
  119. data/spec/unit/file_bucket/dipper_spec.rb +69 -77
  120. data/spec/unit/file_bucket/file_spec.rb +12 -127
  121. data/spec/unit/file_serving/fileset_spec.rb +1 -0
  122. data/spec/unit/file_serving/metadata_spec.rb +4 -4
  123. data/spec/unit/indirector/active_record_spec.rb +1 -0
  124. data/spec/unit/indirector/catalog/active_record_spec.rb +29 -13
  125. data/spec/unit/indirector/facts/active_record_spec.rb +2 -3
  126. data/spec/unit/indirector/facts/couch_spec.rb +1 -2
  127. data/spec/unit/indirector/file_bucket_file/file_spec.rb +202 -218
  128. data/spec/unit/indirector/file_server_spec.rb +6 -7
  129. data/spec/unit/indirector/indirection_spec.rb +71 -2
  130. data/spec/unit/indirector/ldap_spec.rb +2 -6
  131. data/spec/unit/indirector/node/active_record_spec.rb +1 -3
  132. data/spec/unit/indirector/queue_spec.rb +1 -3
  133. data/spec/unit/indirector/rest_spec.rb +37 -1
  134. data/spec/unit/indirector/ssl_file_spec.rb +5 -5
  135. data/spec/unit/indirector_spec.rb +6 -1
  136. data/spec/unit/module_spec.rb +1 -3
  137. data/spec/unit/network/formats_spec.rb +2 -5
  138. data/spec/unit/network/http/api/v1_spec.rb +4 -0
  139. data/spec/unit/network/http/compression_spec.rb +1 -3
  140. data/spec/unit/network/http/handler_spec.rb +39 -0
  141. data/spec/unit/network/http/mongrel/rest_spec.rb +1 -2
  142. data/spec/unit/network/http/mongrel_spec.rb +3 -9
  143. data/spec/unit/network/http/rack/rest_spec.rb +1 -3
  144. data/spec/unit/network/http/rack/xmlrpc_spec.rb +2 -3
  145. data/spec/unit/network/http/rack_spec.rb +2 -3
  146. data/spec/unit/network/http/webrick_spec.rb +1 -0
  147. data/spec/unit/network/rest_authconfig_spec.rb +1 -1
  148. data/spec/unit/network/rights_spec.rb +43 -23
  149. data/spec/unit/network/xmlrpc/client_spec.rb +1 -0
  150. data/spec/unit/parameter_spec.rb +1 -2
  151. data/spec/unit/parser/collector_spec.rb +3 -6
  152. data/spec/unit/parser/compiler_spec.rb +90 -5
  153. data/spec/unit/parser/lexer_spec.rb +3 -2
  154. data/spec/unit/parser/templatewrapper_spec.rb +1 -0
  155. data/spec/unit/property/keyvalue_spec.rb +5 -5
  156. data/spec/unit/property/list_spec.rb +7 -7
  157. data/spec/unit/provider/mount/parsed_spec.rb +1 -2
  158. data/spec/unit/provider/mount_spec.rb +8 -0
  159. data/spec/unit/provider/nameservice/directoryservice_spec.rb +38 -0
  160. data/spec/unit/provider/package/freebsd_spec.rb +55 -0
  161. data/spec/unit/provider/service/init_spec.rb +2 -0
  162. data/spec/unit/rails/host_spec.rb +1 -3
  163. data/spec/unit/rails/param_value_spec.rb +2 -3
  164. data/spec/unit/rails/resource_spec.rb +2 -3
  165. data/spec/unit/rails_spec.rb +5 -15
  166. data/spec/unit/relationship_spec.rb +2 -6
  167. data/spec/unit/reports/http_spec.rb +1 -1
  168. data/spec/unit/reports/store_spec.rb +31 -0
  169. data/spec/unit/reports/tagmail_spec.rb +1 -1
  170. data/spec/unit/resource/catalog_spec.rb +2 -6
  171. data/spec/unit/resource/status_spec.rb +53 -3
  172. data/spec/unit/resource/type_collection_spec.rb +0 -8
  173. data/spec/unit/resource/type_spec.rb +50 -4
  174. data/spec/unit/resource_spec.rb +10 -6
  175. data/spec/unit/ssl/certificate_authority/interface_spec.rb +1 -1
  176. data/spec/unit/transaction/event_spec.rb +21 -2
  177. data/spec/unit/transaction/report_spec.rb +91 -35
  178. data/spec/unit/transaction/resource_harness_spec.rb +289 -208
  179. data/spec/unit/transaction_spec.rb +1 -6
  180. data/spec/unit/type/augeas_spec.rb +1 -3
  181. data/spec/unit/type/file/content_spec.rb +63 -10
  182. data/spec/unit/type/file/ctime.rb +35 -0
  183. data/spec/unit/type/file/ensure_spec.rb +8 -7
  184. data/spec/unit/type/file/group_spec.rb +5 -5
  185. data/spec/unit/type/file/mtime.rb +35 -0
  186. data/spec/unit/type/file/owner_spec.rb +7 -7
  187. data/spec/unit/type/file/selinux_spec.rb +2 -2
  188. data/spec/unit/type/file/source_spec.rb +3 -3
  189. data/spec/unit/type/file/type.rb +20 -0
  190. data/spec/unit/type/file_spec.rb +131 -8
  191. data/spec/unit/type/mount_spec.rb +4 -4
  192. data/spec/unit/type/package_spec.rb +3 -3
  193. data/spec/unit/type/ssh_authorized_key_spec.rb +1 -1
  194. data/spec/unit/type/user_spec.rb +31 -3
  195. data/spec/unit/type/zpool_spec.rb +12 -12
  196. data/spec/unit/type_spec.rb +2 -2
  197. data/spec/unit/util/checksums_spec.rb +9 -1
  198. data/spec/unit/util/command_line_spec.rb +29 -0
  199. data/spec/unit/util/log/destinations_spec.rb +13 -0
  200. data/spec/unit/util/log_spec.rb +24 -12
  201. data/spec/unit/util/logging_spec.rb +1 -1
  202. data/spec/unit/util/metric_spec.rb +7 -7
  203. data/spec/unit/util/pson_spec.rb +15 -0
  204. data/spec/unit/util/queue/stomp_spec.rb +2 -6
  205. data/spec/unit/util/settings/file_setting_spec.rb +1 -3
  206. data/spec/unit/util/zaml_spec.rb +51 -0
  207. data/test/language/snippets.rb +3 -0
  208. data/test/lib/puppettest/fileparsing.rb +2 -0
  209. data/test/lib/puppettest/reporttesting.rb +1 -1
  210. data/test/lib/puppettest/support/utils.rb +1 -1
  211. data/test/network/server/mongrel_test.rb +0 -6
  212. data/test/other/report.rb +1 -1
  213. data/test/ral/providers/cron/crontab.rb +4 -1
  214. data/test/ral/type/file.rb +1 -1
  215. data/test/ral/type/filesources.rb +1 -4
  216. metadata +1119 -1113
  217. data/lib/puppet/transaction/change.rb +0 -87
  218. data/spec/Rakefile +0 -91
  219. data/spec/monkey_patches/add_confine_and_runnable_to_rspec_dsl.rb +0 -46
  220. data/spec/spec_specs/runnable_spec.rb +0 -95
  221. data/spec/unit/transaction/change_spec.rb +0 -193
@@ -229,6 +229,12 @@ describe Puppet::Indirector::FileServer do
229
229
  describe "when checking authorization" do
230
230
  before do
231
231
  @request.method = :find
232
+
233
+ @mount = stub 'mount'
234
+ @configuration.stubs(:split_path).with(@request).returns([@mount, "rel/path"])
235
+ @request.stubs(:node).returns("mynode")
236
+ @request.stubs(:ip).returns("myip")
237
+ @mount.stubs(:allowed?).with("mynode", "myip").returns "something"
232
238
  end
233
239
 
234
240
  it "should return false when destroying" do
@@ -254,13 +260,6 @@ describe Puppet::Indirector::FileServer do
254
260
  end
255
261
 
256
262
  it "should return the results of asking the mount whether the node and IP are authorized" do
257
- @mount = stub 'mount'
258
- @configuration.expects(:split_path).with(@request).returns([@mount, "rel/path"])
259
-
260
- @request.stubs(:node).returns("mynode")
261
- @request.stubs(:ip).returns("myip")
262
- @mount.expects(:allowed?).with("mynode", "myip").returns "something"
263
-
264
263
  @file_server.authorized?(@request).should == "something"
265
264
  end
266
265
  end
@@ -4,7 +4,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
4
4
 
5
5
  require 'puppet/indirector/indirection'
6
6
 
7
- describe "Indirection Delegator", :shared => true do
7
+ shared_examples_for "Indirection Delegator" do
8
8
  it "should create a request object with the appropriate method name and all of the passed arguments" do
9
9
  request = Puppet::Indirector::Request.new(:indirection, :find, "me")
10
10
 
@@ -64,7 +64,7 @@ describe "Indirection Delegator", :shared => true do
64
64
  end
65
65
  end
66
66
 
67
- describe "Delegation Authorizer", :shared => true do
67
+ shared_examples_for "Delegation Authorizer" do
68
68
  before do
69
69
  # So the :respond_to? turns out correctly.
70
70
  class << @terminus
@@ -383,6 +383,75 @@ describe Puppet::Indirector::Indirection do
383
383
  end
384
384
  end
385
385
 
386
+ describe "and doing a head operation" do
387
+ before { @method = :head }
388
+
389
+ it_should_behave_like "Indirection Delegator"
390
+ it_should_behave_like "Delegation Authorizer"
391
+
392
+ it "should return true if the head method returned true" do
393
+ @terminus.expects(:head).returns(true)
394
+ @indirection.head("me").should == true
395
+ end
396
+
397
+ it "should return false if the head method returned false" do
398
+ @terminus.expects(:head).returns(false)
399
+ @indirection.head("me").should == false
400
+ end
401
+
402
+ describe "when caching is enabled" do
403
+ before do
404
+ @indirection.cache_class = :cache_terminus
405
+ @cache_class.stubs(:new).returns(@cache)
406
+
407
+ @instance.stubs(:expired?).returns false
408
+ end
409
+
410
+ it "should first look in the cache for an instance" do
411
+ @terminus.stubs(:find).never
412
+ @terminus.stubs(:head).never
413
+ @cache.expects(:find).returns @instance
414
+
415
+ @indirection.head("/my/key").should == true
416
+ end
417
+
418
+ it "should not save to the cache" do
419
+ @cache.expects(:find).returns nil
420
+ @cache.expects(:save).never
421
+ @terminus.expects(:head).returns true
422
+ @indirection.head("/my/key").should == true
423
+ end
424
+
425
+ it "should not fail if the cache fails" do
426
+ @terminus.stubs(:head).returns true
427
+
428
+ @cache.expects(:find).raises ArgumentError
429
+ lambda { @indirection.head("/my/key") }.should_not raise_error
430
+ end
431
+
432
+ it "should look in the main terminus if the cache fails" do
433
+ @terminus.expects(:head).returns true
434
+ @cache.expects(:find).raises ArgumentError
435
+ @indirection.head("/my/key").should == true
436
+ end
437
+
438
+ it "should send a debug log if it is using the cached object" do
439
+ Puppet.expects(:debug)
440
+ @cache.stubs(:find).returns @instance
441
+
442
+ @indirection.head("/my/key")
443
+ end
444
+
445
+ it "should not accept the cached object if it is expired" do
446
+ @instance.stubs(:expired?).returns true
447
+
448
+ @cache.stubs(:find).returns @instance
449
+ @terminus.stubs(:head).returns false
450
+ @indirection.head("/my/key").should == false
451
+ end
452
+ end
453
+ end
454
+
386
455
  describe "and storing a model instance" do
387
456
  before { @method = :save }
388
457
 
@@ -110,9 +110,7 @@ describe Puppet::Indirector::Ldap do
110
110
  end
111
111
  end
112
112
 
113
- describe "when connecting to ldap" do
114
- confine "LDAP is not available" => Puppet.features.ldap?
115
-
113
+ describe "when connecting to ldap", :if => Puppet.features.ldap? do
116
114
  it "should create and start a Util::Ldap::Connection instance" do
117
115
  conn = mock 'connection', :connection => "myconn", :start => nil
118
116
  Puppet::Util::Ldap::Connection.expects(:instance).returns conn
@@ -135,9 +133,7 @@ describe Puppet::Indirector::Ldap do
135
133
  end
136
134
  end
137
135
 
138
- describe "when reconnecting to ldap" do
139
- confine "Not running on culain as root" => (Puppet.features.root? and Facter.value("hostname") == "culain")
140
-
136
+ describe "when reconnecting to ldap", :if => (Puppet.features.root? and Facter.value("hostname") == "culain") do
141
137
  it "should reconnect to ldap when connections are lost"
142
138
  end
143
139
  end
@@ -4,11 +4,9 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
4
4
 
5
5
  require 'puppet/node'
6
6
 
7
- describe "Puppet::Node::ActiveRecord" do
7
+ describe "Puppet::Node::ActiveRecord", :if => Puppet.features.rails? && Puppet.features.sqlite? do
8
8
  include PuppetSpec::Files
9
9
 
10
- confine "Missing Rails" => Puppet.features.rails?
11
- confine "Missing sqlite" => Puppet.features.sqlite?
12
10
  before do
13
11
  require 'puppet/indirector/node/active_record'
14
12
  end
@@ -26,9 +26,7 @@ class FooExampleData
26
26
  end
27
27
  end
28
28
 
29
- describe Puppet::Indirector::Queue do
30
- confine "PSON library is missing; cannot test queueing" => Puppet.features.pson?
31
-
29
+ describe Puppet::Indirector::Queue, :if => Puppet.features.pson? do
32
30
  before :each do
33
31
  @model = mock 'model'
34
32
  @indirection = stub 'indirection', :name => :my_queue, :register_terminus_type => nil, :model => @model
@@ -3,7 +3,7 @@
3
3
  require File.dirname(__FILE__) + '/../../spec_helper'
4
4
  require 'puppet/indirector/rest'
5
5
 
6
- describe "a REST http call", :shared => true do
6
+ shared_examples_for "a REST http call" do
7
7
  it "should accept a path" do
8
8
  lambda { @search.send(@method, *@arguments) }.should_not raise_error(ArgumentError)
9
9
  end
@@ -282,6 +282,42 @@ describe Puppet::Indirector::REST do
282
282
  end
283
283
  end
284
284
 
285
+ describe "when doing a head" do
286
+ before :each do
287
+ @connection = stub('mock http connection', :head => @response)
288
+ @searcher.stubs(:network).returns(@connection)
289
+
290
+ # Use a key with spaces, so we can test escaping
291
+ @request = Puppet::Indirector::Request.new(:foo, :head, "foo bar")
292
+ end
293
+
294
+ it "should call the HEAD http method on a network connection" do
295
+ @searcher.expects(:network).returns @connection
296
+ @connection.expects(:head).returns @response
297
+ @searcher.head(@request)
298
+ end
299
+
300
+ it "should return true if there was a successful http response" do
301
+ @connection.expects(:head).returns @response
302
+ @response.stubs(:code).returns "200"
303
+
304
+ @searcher.head(@request).should == true
305
+ end
306
+
307
+ it "should return false if there was a successful http response" do
308
+ @connection.expects(:head).returns @response
309
+ @response.stubs(:code).returns "404"
310
+
311
+ @searcher.head(@request).should == false
312
+ end
313
+
314
+ it "should use the URI generated by the Handler module" do
315
+ @searcher.expects(:indirection2uri).with(@request).returns "/my/uri"
316
+ @connection.expects(:head).with { |path, args| path == "/my/uri" }.returns(@response)
317
+ @searcher.head(@request)
318
+ end
319
+ end
320
+
285
321
  describe "when doing a search" do
286
322
  before :each do
287
323
  @connection = stub('mock http connection', :get => @response)
@@ -18,12 +18,12 @@ describe Puppet::Indirector::SslFile do
18
18
  end
19
19
  end
20
20
 
21
- @setting = :mydir
21
+ @setting = :certdir
22
22
  @file_class.store_in @setting
23
- @path = "/my/directory"
24
- Puppet.settings.stubs(:value).with(:noop).returns(false)
25
- Puppet.settings.stubs(:value).with(@setting).returns(@path)
26
- Puppet.settings.stubs(:value).with(:trace).returns(false)
23
+ @path = "/tmp/my_directory"
24
+ Puppet[:noop] = false
25
+ Puppet[@setting] = @path
26
+ Puppet[:trace] = false
27
27
  end
28
28
 
29
29
  it "should use :main and :ssl upon initialization" do
@@ -64,7 +64,7 @@ describe Puppet::Indirector, "when registering an indirection" do
64
64
  end
65
65
  end
66
66
 
67
- describe "Delegated Indirection Method", :shared => true do
67
+ shared_examples_for "Delegated Indirection Method" do
68
68
  it "should delegate to the indirection" do
69
69
  @indirection.expects(@method)
70
70
  @thingie.send(@method, "me")
@@ -118,6 +118,11 @@ describe Puppet::Indirector, "when redirecting a model" do
118
118
  it_should_behave_like "Delegated Indirection Method"
119
119
  end
120
120
 
121
+ describe "when performing a head request" do
122
+ before { @method = :head }
123
+ it_should_behave_like "Delegated Indirection Method"
124
+ end
125
+
121
126
  # This is an instance method, so it behaves a bit differently.
122
127
  describe "when saving instances via the model" do
123
128
  before do
@@ -504,9 +504,7 @@ describe Puppet::Module do
504
504
  Puppet::Module.new("yay")
505
505
  end
506
506
 
507
- describe "when loading the medatada file" do
508
- confine "Cannot test module metadata without json" => Puppet.features.json?
509
-
507
+ describe "when loading the medatada file", :if => Puppet.features.json? do
510
508
  before do
511
509
  @data = {
512
510
  :license => "GPL2",
@@ -69,9 +69,8 @@ describe "Puppet Network Format" do
69
69
  end
70
70
  end
71
71
 
72
- describe "base64 compressed yaml" do
72
+ describe "base64 compressed yaml", :if => Puppet.features.zlib? do
73
73
  yaml = Puppet::Network::FormatHandler.format(:b64_zlib_yaml)
74
- confine "We must have zlib" => Puppet.features.zlib?
75
74
 
76
75
  before do
77
76
  @yaml = Puppet::Network::FormatHandler.format(:b64_zlib_yaml)
@@ -265,9 +264,7 @@ describe "Puppet Network Format" do
265
264
  Puppet::Network::FormatHandler.format(:pson).should_not be_nil
266
265
  end
267
266
 
268
- describe "pson" do
269
- confine "Missing 'pson' library" => Puppet.features.pson?
270
-
267
+ describe "pson", :if => Puppet.features.pson? do
271
268
  before do
272
269
  @pson = Puppet::Network::FormatHandler.format(:pson)
273
270
  end
@@ -68,6 +68,10 @@ describe Puppet::Network::HTTP::API::V1 do
68
68
  @tester.uri2indirection("GET", "/env/foo/bar", {}).method.should == :find
69
69
  end
70
70
 
71
+ it "should choose 'head' as the indirection method if the http method is a HEAD and the indirection name is singular" do
72
+ @tester.uri2indirection("HEAD", "/env/foo/bar", {}).method.should == :head
73
+ end
74
+
71
75
  it "should choose 'search' as the indirection method if the http method is a GET and the indirection name is plural" do
72
76
  @tester.uri2indirection("GET", "/env/foos/bar", {}).method.should == :search
73
77
  end
@@ -37,9 +37,7 @@ describe "http compression" do
37
37
  end
38
38
  end
39
39
 
40
- describe "when zlib is available" do
41
- confine "Zlib is missing" => Puppet.features.zlib?
42
-
40
+ describe "when zlib is available", :if => Puppet.features.zlib? do
43
41
  before(:each) do
44
42
  Puppet.features.stubs(:zlib?).returns true
45
43
 
@@ -209,6 +209,12 @@ describe Puppet::Network::HTTP::Handler do
209
209
  @handler.do_find(@irequest, @request, @response)
210
210
  end
211
211
 
212
+ it "should pass the result through without rendering it if the result is a string" do
213
+ @model_class.stubs(:find).returns "foo"
214
+ @handler.expects(:set_response).with(@response, "foo")
215
+ @handler.do_find(@irequest, @request, @response)
216
+ end
217
+
212
218
  it "should use the default status when a model find call succeeds" do
213
219
  @handler.expects(:set_response).with { |response, body, status| status.nil? }
214
220
  @handler.do_find(@irequest, @request, @response)
@@ -250,6 +256,39 @@ describe Puppet::Network::HTTP::Handler do
250
256
  end
251
257
  end
252
258
 
259
+ describe "when performing head operation" do
260
+ before do
261
+ @irequest = stub 'indirection_request', :method => :head, :indirection_name => "my_handler", :to_hash => {}, :key => "my_result", :model => @model_class
262
+
263
+ @model_class.stubs(:head).returns true
264
+ end
265
+
266
+ it "should use the indirection request to find the model class" do
267
+ @irequest.expects(:model).returns @model_class
268
+
269
+ @handler.do_head(@irequest, @request, @response)
270
+ end
271
+
272
+ it "should use the escaped request key" do
273
+ @model_class.expects(:head).with do |key, args|
274
+ key == "my_result"
275
+ end.returns true
276
+ @handler.do_head(@irequest, @request, @response)
277
+ end
278
+
279
+ it "should not generate a response when a model head call succeeds" do
280
+ @handler.expects(:set_response).never
281
+ @handler.do_head(@irequest, @request, @response)
282
+ end
283
+
284
+ it "should return a 404 when the model head call returns false" do
285
+ @model_class.stubs(:name).returns "my name"
286
+ @handler.expects(:set_response).with { |response, body, status| status == 404 }
287
+ @model_class.stubs(:head).returns(false)
288
+ @handler.do_head(@irequest, @request, @response)
289
+ end
290
+ end
291
+
253
292
  describe "when searching for model instances" do
254
293
  before do
255
294
  @irequest = stub 'indirection_request', :method => :find, :indirection_name => "my_handler", :to_hash => {}, :key => "key", :model => @model_class
@@ -4,8 +4,7 @@ require File.dirname(__FILE__) + '/../../../../spec_helper'
4
4
 
5
5
  require 'puppet/network/http'
6
6
 
7
- describe "Puppet::Network::HTTP::MongrelREST" do
8
- confine "Mongrel is not available" => Puppet.features.mongrel?
7
+ describe "Puppet::Network::HTTP::MongrelREST", :if => Puppet.features.mongrel? do
9
8
  before do
10
9
  require 'puppet/network/http/mongrel/rest'
11
10
  end
@@ -6,9 +6,7 @@
6
6
  require File.dirname(__FILE__) + '/../../../spec_helper'
7
7
  require 'puppet/network/http'
8
8
 
9
- describe "Puppet::Network::HTTP::Mongrel", "after initializing" do
10
- confine "Mongrel is not available" => Puppet.features.mongrel?
11
-
9
+ describe "Puppet::Network::HTTP::Mongrel", "after initializing", :if => Puppet.features.mongrel? do
12
10
  it "should not be listening" do
13
11
  require 'puppet/network/http/mongrel'
14
12
 
@@ -16,9 +14,7 @@ describe "Puppet::Network::HTTP::Mongrel", "after initializing" do
16
14
  end
17
15
  end
18
16
 
19
- describe "Puppet::Network::HTTP::Mongrel", "when turning on listening" do
20
- confine "Mongrel is not available" => Puppet.features.mongrel?
21
-
17
+ describe "Puppet::Network::HTTP::Mongrel", "when turning on listening", :if => Puppet.features.mongrel? do
22
18
  before do
23
19
  require 'puppet/network/http/mongrel'
24
20
 
@@ -100,9 +96,7 @@ describe "Puppet::Network::HTTP::Mongrel", "when turning on listening" do
100
96
  end
101
97
  end
102
98
 
103
- describe "Puppet::Network::HTTP::Mongrel", "when turning off listening" do
104
- confine "Mongrel is not available" => Puppet.features.mongrel?
105
-
99
+ describe "Puppet::Network::HTTP::Mongrel", "when turning off listening", :if => Puppet.features.mongrel? do
106
100
  before do
107
101
  @mock_mongrel = mock('mongrel httpserver')
108
102
  @mock_mongrel.stubs(:run)
@@ -4,9 +4,7 @@ require File.dirname(__FILE__) + '/../../../../spec_helper'
4
4
  require 'puppet/network/http/rack' if Puppet.features.rack?
5
5
  require 'puppet/network/http/rack/rest'
6
6
 
7
- describe "Puppet::Network::HTTP::RackREST" do
8
- confine "Rack is not available" => Puppet.features.rack?
9
-
7
+ describe "Puppet::Network::HTTP::RackREST", :if => Puppet.features.rack? do
10
8
  it "should include the Puppet::Network::HTTP::Handler module" do
11
9
  Puppet::Network::HTTP::RackREST.ancestors.should be_include(Puppet::Network::HTTP::Handler)
12
10
  end
@@ -1,12 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require File.dirname(__FILE__) + '/../../../../spec_helper'
4
+ require 'puppet/network/handler'
4
5
  require 'puppet/network/http/rack' if Puppet.features.rack?
5
6
  require 'puppet/network/http/rack/xmlrpc' if Puppet.features.rack?
6
7
 
7
- describe "Puppet::Network::HTTP::RackXMLRPC" do
8
- confine "Rack is not available" => Puppet.features.rack?
9
-
8
+ describe "Puppet::Network::HTTP::RackXMLRPC", :if => Puppet.features.rack? do
10
9
  describe "when initializing" do
11
10
  it "should create an Puppet::Network::XMLRPCServer" do
12
11
  Puppet::Network::XMLRPCServer.expects(:new).returns stub_everything
@@ -1,11 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require File.dirname(__FILE__) + '/../../../spec_helper'
4
+ require 'puppet/network/handler'
4
5
  require 'puppet/network/http/rack' if Puppet.features.rack?
5
6
 
6
- describe "Puppet::Network::HTTP::Rack" do
7
- confine "Rack is not available" => Puppet.features.rack?
8
-
7
+ describe "Puppet::Network::HTTP::Rack", :if => Puppet.features.rack? do
9
8
  describe "while initializing" do
10
9
 
11
10
  it "should require a protocol specification" do