puppet 3.5.1-x86-mingw32 → 3.6.0.rc1-x86-mingw32

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 (342) hide show
  1. data/CONTRIBUTING.md +5 -0
  2. data/Gemfile +17 -9
  3. data/README.md +1 -0
  4. data/conf/fileserver.conf +4 -3
  5. data/ext/README.environment +8 -0
  6. data/ext/build_defaults.yaml +1 -1
  7. data/ext/debian/control +2 -2
  8. data/ext/debian/puppet-common.dirs +4 -0
  9. data/ext/debian/rules +4 -0
  10. data/ext/emacs/puppet-mode-init.el +1 -1
  11. data/ext/emacs/puppet-mode.el +36 -17
  12. data/ext/redhat/client.init +3 -3
  13. data/ext/redhat/puppet.spec.erb +9 -0
  14. data/ext/systemd/puppet.service +3 -4
  15. data/ext/systemd/puppetmaster.service +1 -3
  16. data/install.rb +1 -1
  17. data/lib/puppet.rb +2 -1
  18. data/lib/puppet/agent.rb +1 -1
  19. data/lib/puppet/application.rb +17 -17
  20. data/lib/puppet/application/doc.rb +1 -1
  21. data/lib/puppet/configurer.rb +4 -1
  22. data/lib/puppet/configurer/downloader.rb +13 -12
  23. data/lib/puppet/configurer/plugin_handler.rb +3 -3
  24. data/lib/puppet/context.rb +6 -1
  25. data/lib/puppet/defaults.rb +82 -12
  26. data/lib/puppet/environments.rb +169 -13
  27. data/lib/puppet/external/nagios/grammar.ry +2 -0
  28. data/lib/puppet/external/nagios/parser.rb +28 -19
  29. data/lib/puppet/face/config.rb +19 -6
  30. data/lib/puppet/face/module/generate.rb +209 -7
  31. data/lib/puppet/face/module/install.rb +17 -16
  32. data/lib/puppet/face/module/list.rb +83 -82
  33. data/lib/puppet/face/module/search.rb +1 -1
  34. data/lib/puppet/face/module/upgrade.rb +10 -9
  35. data/lib/puppet/face/parser.rb +3 -2
  36. data/lib/puppet/face/plugin.rb +8 -4
  37. data/lib/puppet/file_bucket/dipper.rb +6 -3
  38. data/lib/puppet/file_bucket/file.rb +4 -2
  39. data/lib/puppet/file_serving/metadata.rb +1 -1
  40. data/lib/puppet/file_system/memory_file.rb +27 -1
  41. data/lib/puppet/file_system/memory_impl.rb +15 -1
  42. data/lib/puppet/forge.rb +148 -52
  43. data/lib/puppet/forge/cache.rb +5 -1
  44. data/lib/puppet/forge/errors.rb +10 -0
  45. data/lib/puppet/forge/repository.rb +61 -26
  46. data/lib/puppet/functions.rb +548 -0
  47. data/lib/puppet/functions/assert_type.rb +42 -0
  48. data/lib/puppet/functions/import.rb +7 -0
  49. data/lib/puppet/indirector/facts/facter.rb +1 -1
  50. data/lib/puppet/indirector/file_bucket_file/file.rb +3 -2
  51. data/lib/puppet/indirector/rest.rb +18 -0
  52. data/lib/puppet/loaders.rb +20 -0
  53. data/lib/puppet/module.rb +2 -2
  54. data/lib/puppet/module_tool.rb +40 -14
  55. data/lib/puppet/module_tool/applications.rb +0 -1
  56. data/lib/puppet/module_tool/applications/application.rb +35 -26
  57. data/lib/puppet/module_tool/applications/builder.rb +16 -6
  58. data/lib/puppet/module_tool/applications/checksummer.rb +25 -19
  59. data/lib/puppet/module_tool/applications/installer.rb +196 -35
  60. data/lib/puppet/module_tool/applications/searcher.rb +1 -0
  61. data/lib/puppet/module_tool/applications/uninstaller.rb +7 -1
  62. data/lib/puppet/module_tool/applications/unpacker.rb +57 -31
  63. data/lib/puppet/module_tool/applications/upgrader.rb +221 -65
  64. data/lib/puppet/module_tool/checksums.rb +5 -8
  65. data/lib/puppet/module_tool/errors/installer.rb +12 -44
  66. data/lib/puppet/module_tool/errors/shared.rb +84 -11
  67. data/lib/puppet/module_tool/errors/upgrader.rb +16 -45
  68. data/lib/puppet/module_tool/install_directory.rb +7 -6
  69. data/lib/puppet/module_tool/installed_modules.rb +92 -0
  70. data/lib/puppet/module_tool/local_tarball.rb +91 -0
  71. data/lib/puppet/module_tool/metadata.rb +119 -115
  72. data/lib/puppet/module_tool/modulefile.rb +9 -9
  73. data/lib/puppet/module_tool/shared_behaviors.rb +19 -7
  74. data/lib/puppet/module_tool/skeleton/templates/generator/README.md.erb +79 -0
  75. data/lib/puppet/module_tool/skeleton/templates/generator/Rakefile +18 -0
  76. data/lib/puppet/module_tool/skeleton/templates/generator/metadata.json.erb +1 -0
  77. data/lib/puppet/module_tool/skeleton/templates/generator/spec/classes/init_spec.rb.erb +7 -0
  78. data/lib/puppet/module_tool/tar.rb +3 -7
  79. data/lib/puppet/module_tool/tar/gnu.rb +21 -9
  80. data/lib/puppet/module_tool/tar/mini.rb +2 -8
  81. data/lib/puppet/network/http/api/v1.rb +1 -1
  82. data/lib/puppet/network/http/api/v2/authorization.rb +4 -2
  83. data/lib/puppet/network/http/issues.rb +1 -0
  84. data/lib/puppet/network/http_pool.rb +15 -6
  85. data/lib/puppet/node/environment.rb +91 -20
  86. data/lib/puppet/parser/ast/pops_bridge.rb +44 -3
  87. data/lib/puppet/parser/collector.rb +1 -1
  88. data/lib/puppet/parser/compiler.rb +50 -7
  89. data/lib/puppet/parser/functions.rb +6 -0
  90. data/lib/puppet/parser/functions/generate.rb +1 -1
  91. data/lib/puppet/parser/resource.rb +1 -1
  92. data/lib/puppet/pops.rb +22 -1
  93. data/lib/puppet/pops/adapters.rb +8 -1
  94. data/lib/puppet/pops/binder/bindings_composer.rb +1 -1
  95. data/lib/puppet/pops/binder/bindings_factory.rb +1 -1
  96. data/lib/puppet/pops/binder/config/binder_config_checker.rb +1 -1
  97. data/lib/puppet/pops/binder/producers.rb +2 -2
  98. data/lib/puppet/pops/evaluator/access_operator.rb +65 -25
  99. data/lib/puppet/pops/evaluator/callable_signature.rb +101 -0
  100. data/lib/puppet/pops/evaluator/closure.rb +57 -2
  101. data/lib/puppet/pops/evaluator/compare_operator.rb +1 -1
  102. data/lib/puppet/pops/evaluator/evaluator_impl.rb +9 -11
  103. data/lib/puppet/pops/evaluator/runtime3_support.rb +72 -21
  104. data/lib/puppet/pops/functions/dispatch.rb +71 -0
  105. data/lib/puppet/pops/functions/dispatcher.rb +237 -0
  106. data/lib/puppet/pops/functions/function.rb +77 -0
  107. data/lib/puppet/pops/issues.rb +12 -0
  108. data/lib/puppet/pops/loader/base_loader.rb +102 -0
  109. data/lib/puppet/pops/loader/dependency_loader.rb +60 -0
  110. data/lib/puppet/pops/loader/gem_support.rb +49 -0
  111. data/lib/puppet/pops/loader/loader.rb +180 -0
  112. data/lib/puppet/pops/loader/loader_paths.rb +137 -0
  113. data/lib/puppet/pops/loader/module_loaders.rb +242 -0
  114. data/lib/puppet/pops/loader/null_loader.rb +44 -0
  115. data/lib/puppet/pops/loader/ruby_function_instantiator.rb +34 -0
  116. data/lib/puppet/pops/loader/ruby_legacy_function_instantiator.rb +109 -0
  117. data/lib/puppet/pops/loader/simple_environment_loader.rb +20 -0
  118. data/lib/puppet/pops/loader/static_loader.rb +69 -0
  119. data/lib/puppet/pops/loader/uri_helper.rb +22 -0
  120. data/lib/puppet/pops/loaders.rb +240 -0
  121. data/lib/puppet/pops/model/factory.rb +13 -5
  122. data/lib/puppet/pops/model/model_tree_dumper.rb +12 -4
  123. data/lib/puppet/pops/parser/egrammar.ra +31 -18
  124. data/lib/puppet/pops/parser/eparser.rb +1137 -1106
  125. data/lib/puppet/pops/parser/lexer2.rb +17 -16
  126. data/lib/puppet/pops/semantic_error.rb +17 -0
  127. data/lib/puppet/pops/types/type_calculator.rb +150 -15
  128. data/lib/puppet/pops/types/type_factory.rb +69 -0
  129. data/lib/puppet/pops/types/type_parser.rb +9 -0
  130. data/lib/puppet/pops/types/types.rb +65 -4
  131. data/lib/puppet/pops/validation/checker4_0.rb +1 -1
  132. data/lib/puppet/pops/validation/validator_factory_4_0.rb +1 -1
  133. data/lib/puppet/property/list.rb +1 -1
  134. data/lib/puppet/provider/augeas/augeas.rb +2 -2
  135. data/lib/puppet/provider/cron/crontab.rb +13 -2
  136. data/lib/puppet/provider/package.rb +24 -0
  137. data/lib/puppet/provider/package/apt.rb +6 -1
  138. data/lib/puppet/provider/package/gem.rb +8 -2
  139. data/lib/puppet/provider/package/msi.rb +0 -15
  140. data/lib/puppet/provider/package/openbsd.rb +0 -24
  141. data/lib/puppet/provider/package/rpm.rb +3 -29
  142. data/lib/puppet/provider/package/windows.rb +0 -15
  143. data/lib/puppet/provider/package/yum.rb +101 -24
  144. data/lib/puppet/provider/package/yumhelper.py +31 -1
  145. data/lib/puppet/provider/package/zypper.rb +10 -28
  146. data/lib/puppet/provider/service/debian.rb +1 -1
  147. data/lib/puppet/provider/service/init.rb +3 -0
  148. data/lib/puppet/provider/service/openbsd.rb +318 -0
  149. data/lib/puppet/provider/service/redhat.rb +6 -3
  150. data/lib/puppet/provider/service/systemd.rb +2 -2
  151. data/lib/puppet/provider/yumrepo/inifile.rb +115 -42
  152. data/lib/puppet/resource.rb +13 -9
  153. data/lib/puppet/resource/catalog.rb +12 -6
  154. data/lib/puppet/resource/type_collection.rb +3 -3
  155. data/lib/puppet/settings.rb +57 -36
  156. data/lib/puppet/settings/config_file.rb +5 -0
  157. data/lib/puppet/settings/environment_conf.rb +147 -0
  158. data/lib/puppet/settings/ttl_setting.rb +48 -0
  159. data/lib/puppet/ssl/certificate_authority.rb +2 -3
  160. data/lib/puppet/ssl/certificate_authority/autosign_command.rb +1 -1
  161. data/lib/puppet/ssl/certificate_request.rb +4 -4
  162. data/lib/puppet/ssl/validator/default_validator.rb +2 -2
  163. data/lib/puppet/status.rb +1 -1
  164. data/lib/puppet/test/test_helper.rb +1 -0
  165. data/lib/puppet/type/augeas.rb +13 -1
  166. data/lib/puppet/type/cron.rb +32 -18
  167. data/lib/puppet/type/file.rb +4 -2
  168. data/lib/puppet/type/file/checksum.rb +15 -5
  169. data/lib/puppet/type/file/content.rb +3 -1
  170. data/lib/puppet/type/file/source.rb +5 -5
  171. data/lib/puppet/type/package.rb +12 -17
  172. data/lib/puppet/type/resources.rb +3 -1
  173. data/lib/puppet/type/scheduled_task.rb +4 -5
  174. data/lib/puppet/type/service.rb +12 -2
  175. data/lib/puppet/type/user.rb +106 -0
  176. data/lib/puppet/type/yumrepo.rb +9 -1
  177. data/lib/puppet/util/checksums.rb +60 -1
  178. data/lib/puppet/util/diff.rb +3 -1
  179. data/lib/puppet/util/execution.rb +20 -16
  180. data/lib/puppet/util/feature.rb +3 -0
  181. data/lib/puppet/util/logging.rb +19 -12
  182. data/lib/puppet/util/rubygems.rb +10 -0
  183. data/lib/puppet/util/watched_file.rb +1 -1
  184. data/lib/puppet/util/windows/security.rb +5 -3
  185. data/lib/puppet/vendor/load_semantic.rb +1 -0
  186. data/lib/puppet/vendor/require_vendored.rb +2 -0
  187. data/lib/puppet/vendor/semantic/Gemfile +20 -0
  188. data/lib/puppet/vendor/semantic/Rakefile +69 -0
  189. data/lib/puppet/vendor/semantic/lib/semantic.rb +7 -0
  190. data/lib/puppet/vendor/semantic/lib/semantic/dependency.rb +181 -0
  191. data/lib/puppet/vendor/semantic/lib/semantic/dependency/graph.rb +60 -0
  192. data/lib/puppet/vendor/semantic/lib/semantic/dependency/graph_node.rb +117 -0
  193. data/lib/puppet/vendor/semantic/lib/semantic/dependency/module_release.rb +46 -0
  194. data/lib/puppet/vendor/semantic/lib/semantic/dependency/source.rb +25 -0
  195. data/lib/puppet/vendor/semantic/lib/semantic/dependency/unsatisfiable_graph.rb +31 -0
  196. data/lib/puppet/vendor/semantic/lib/semantic/version.rb +168 -0
  197. data/lib/puppet/vendor/semantic/lib/semantic/version_range.rb +424 -0
  198. data/lib/puppet/vendor/semantic/spec/spec_helper.rb +24 -0
  199. data/lib/puppet/vendor/semantic/spec/unit/semantic/dependency/graph_node_spec.rb +141 -0
  200. data/lib/puppet/vendor/semantic/spec/unit/semantic/dependency/graph_spec.rb +162 -0
  201. data/lib/puppet/vendor/semantic/spec/unit/semantic/dependency/module_release_spec.rb +143 -0
  202. data/lib/puppet/vendor/semantic/spec/unit/semantic/dependency/source_spec.rb +5 -0
  203. data/lib/puppet/vendor/semantic/spec/unit/semantic/dependency/unsatisfiable_graph_spec.rb +44 -0
  204. data/lib/puppet/vendor/semantic/spec/unit/semantic/dependency_spec.rb +383 -0
  205. data/lib/puppet/vendor/semantic/spec/unit/semantic/version_range_spec.rb +307 -0
  206. data/lib/puppet/vendor/semantic/spec/unit/semantic/version_spec.rb +608 -0
  207. data/lib/puppet/version.rb +1 -1
  208. data/spec/fixtures/java.tgz +0 -0
  209. data/spec/fixtures/stdlib.tgz +0 -0
  210. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/usee/lib/puppet/functions/usee/callee.rb +5 -0
  211. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/user/lib/puppet/functions/user/caller.rb +5 -0
  212. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/user/metadata.json +9 -0
  213. data/spec/fixtures/unit/pops/loaders/loaders/single_module/modules/modulea/lib/puppet/functions/modulea/rb_func_a.rb +5 -0
  214. data/spec/fixtures/unit/pops/loaders/loaders/single_module/modules/modulea/lib/puppet/functions/rb_func_a.rb +5 -0
  215. data/spec/fixtures/unit/pops/loaders/loaders/single_module/modules/modulea/manifests/init.pp +3 -0
  216. data/spec/fixtures/unit/pops/loaders/loaders/single_module/modules/modulea/metadata.json +19 -0
  217. data/spec/fixtures/unit/pops/loaders/loaders/wo_metadata_module/modules/moduleb/lib/puppet/functions/moduleb/rb_func_b.rb +6 -0
  218. data/spec/fixtures/unit/pops/loaders/loaders/wo_metadata_module/modules/moduleb/manifests/init.pp +3 -0
  219. data/spec/fixtures/unit/provider/naginator/define_empty_param +6 -0
  220. data/spec/fixtures/unit/provider/service/systemd/list_unit_files_services +7 -0
  221. data/spec/fixtures/unit/type/user/authorized_keys +5 -0
  222. data/spec/integration/application/apply_spec.rb +1 -2
  223. data/spec/integration/configurer_spec.rb +2 -2
  224. data/spec/integration/faces/plugin_spec.rb +62 -0
  225. data/spec/integration/indirector/catalog/compiler_spec.rb +1 -1
  226. data/spec/integration/indirector/catalog/queue_spec.rb +1 -1
  227. data/spec/integration/node/environment_spec.rb +2 -2
  228. data/spec/integration/parser/future_compiler_spec.rb +96 -142
  229. data/spec/integration/parser/ruby_manifest_spec.rb +0 -5
  230. data/spec/integration/provider/cron/crontab_spec.rb +35 -0
  231. data/spec/integration/type/file_spec.rb +74 -72
  232. data/spec/integration/util/windows/security_spec.rb +17 -0
  233. data/spec/lib/matchers/resource.rb +45 -13
  234. data/spec/lib/puppet_spec/files.rb +18 -0
  235. data/spec/lib/puppet_spec/module_tool/shared_functions.rb +56 -0
  236. data/spec/lib/puppet_spec/module_tool/stub_source.rb +133 -0
  237. data/spec/shared_contexts/checksums.rb +55 -0
  238. data/spec/unit/application/apply_spec.rb +10 -7
  239. data/spec/unit/application/doc_spec.rb +17 -10
  240. data/spec/unit/application/indirection_base_spec.rb +18 -10
  241. data/spec/unit/application/inspect_spec.rb +22 -20
  242. data/spec/unit/configurer/downloader_spec.rb +7 -6
  243. data/spec/unit/configurer/plugin_handler_spec.rb +5 -8
  244. data/spec/unit/configurer_spec.rb +1 -1
  245. data/spec/unit/context_spec.rb +23 -0
  246. data/spec/unit/environments_spec.rb +274 -16
  247. data/spec/unit/face/config_spec.rb +111 -11
  248. data/spec/unit/face/module/install_spec.rb +14 -85
  249. data/spec/unit/face/module/list_spec.rb +108 -62
  250. data/spec/unit/face/module/search_spec.rb +1 -1
  251. data/spec/unit/face/module/uninstall_spec.rb +21 -42
  252. data/spec/unit/face/parser_spec.rb +5 -2
  253. data/spec/unit/file_bucket/dipper_spec.rb +92 -86
  254. data/spec/unit/file_bucket/file_spec.rb +23 -75
  255. data/spec/unit/file_serving/metadata_spec.rb +74 -74
  256. data/spec/unit/forge/module_release_spec.rb +131 -0
  257. data/spec/unit/forge/repository_spec.rb +21 -20
  258. data/spec/unit/forge_spec.rb +99 -23
  259. data/spec/unit/functions/assert_type_spec.rb +59 -0
  260. data/spec/unit/functions4_spec.rb +671 -0
  261. data/spec/unit/indirector/catalog/static_compiler_spec.rb +2 -2
  262. data/spec/unit/indirector/facts/facter_spec.rb +9 -3
  263. data/spec/unit/indirector/file_bucket_file/file_spec.rb +156 -155
  264. data/spec/unit/indirector/rest_spec.rb +8 -0
  265. data/spec/unit/interface/face_collection_spec.rb +35 -23
  266. data/spec/unit/module_spec.rb +20 -8
  267. data/spec/unit/module_tool/applications/builder_spec.rb +40 -12
  268. data/spec/unit/module_tool/applications/checksummer_spec.rb +86 -105
  269. data/spec/unit/module_tool/applications/installer_spec.rb +293 -261
  270. data/spec/unit/module_tool/applications/searcher_spec.rb +1 -1
  271. data/spec/unit/module_tool/applications/uninstaller_spec.rb +90 -154
  272. data/spec/unit/module_tool/applications/unpacker_spec.rb +12 -12
  273. data/spec/unit/module_tool/applications/upgrader_spec.rb +286 -18
  274. data/spec/unit/module_tool/metadata_spec.rb +223 -14
  275. data/spec/unit/module_tool/tar/gnu_spec.rb +12 -9
  276. data/spec/unit/module_tool/tar/mini_spec.rb +1 -1
  277. data/spec/unit/module_tool/tar_spec.rb +4 -18
  278. data/spec/unit/module_tool_spec.rb +123 -27
  279. data/spec/unit/network/formats_spec.rb +2 -2
  280. data/spec/unit/network/http_pool_spec.rb +21 -0
  281. data/spec/unit/network/rights_spec.rb +10 -8
  282. data/spec/unit/node/environment_spec.rb +27 -2
  283. data/spec/unit/parser/collector_spec.rb +1 -1
  284. data/spec/unit/parser/compiler_spec.rb +1 -1
  285. data/spec/unit/parser/functions/generate_spec.rb +4 -0
  286. data/spec/unit/pops/evaluator/access_ops_spec.rb +50 -11
  287. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +25 -0
  288. data/spec/unit/pops/loaders/dependency_loader_spec.rb +44 -0
  289. data/spec/unit/pops/loaders/loader_paths_spec.rb +66 -0
  290. data/spec/unit/pops/loaders/loaders_spec.rb +105 -0
  291. data/spec/unit/pops/loaders/module_loaders_spec.rb +119 -0
  292. data/spec/unit/pops/loaders/static_loader_spec.rb +46 -0
  293. data/spec/unit/pops/types/type_calculator_spec.rb +145 -10
  294. data/spec/unit/pops/types/type_factory_spec.rb +101 -0
  295. data/spec/unit/pops/types/type_parser_spec.rb +22 -0
  296. data/spec/unit/property/list_spec.rb +9 -1
  297. data/spec/unit/provider/augeas/augeas_spec.rb +58 -11
  298. data/spec/unit/provider/cron/crontab_spec.rb +1 -0
  299. data/spec/unit/provider/cron/parsed_spec.rb +15 -0
  300. data/spec/unit/provider/naginator_spec.rb +14 -0
  301. data/spec/unit/provider/package/apt_spec.rb +78 -64
  302. data/spec/unit/provider/package/gem_spec.rb +15 -0
  303. data/spec/unit/provider/package/rpm_spec.rb +6 -6
  304. data/spec/unit/provider/package/windows_spec.rb +1 -1
  305. data/spec/unit/provider/package/yum_spec.rb +199 -104
  306. data/spec/unit/provider/package/zypper_spec.rb +41 -15
  307. data/spec/unit/provider/service/openbsd_spec.rb +129 -22
  308. data/spec/unit/provider/service/redhat_spec.rb +18 -4
  309. data/spec/unit/provider/service/systemd_spec.rb +5 -9
  310. data/spec/unit/provider/service/upstart_spec.rb +1 -1
  311. data/spec/unit/provider/user/directoryservice_spec.rb +10 -0
  312. data/spec/unit/provider/yumrepo/inifile_spec.rb +171 -15
  313. data/spec/unit/resource/catalog_spec.rb +20 -104
  314. data/spec/unit/resource/type_collection_spec.rb +10 -9
  315. data/spec/unit/settings/config_file_spec.rb +29 -6
  316. data/spec/unit/settings/environment_conf_spec.rb +51 -0
  317. data/spec/unit/settings_spec.rb +97 -12
  318. data/spec/unit/ssl/certificate_authority_spec.rb +2 -0
  319. data/spec/unit/type/augeas_spec.rb +1 -1
  320. data/spec/unit/type/cron_spec.rb +6 -7
  321. data/spec/unit/type/file/checksum_spec.rb +6 -0
  322. data/spec/unit/type/file/content_spec.rb +277 -207
  323. data/spec/unit/type/file_spec.rb +9 -7
  324. data/spec/unit/type/user_spec.rb +106 -18
  325. data/spec/unit/type/yumrepo_spec.rb +8 -0
  326. data/spec/unit/util/checksums_spec.rb +12 -5
  327. data/spec/unit/util/diff_spec.rb +8 -0
  328. data/spec/unit/util/execution_spec.rb +4 -4
  329. data/spec/unit/util/feature_spec.rb +2 -0
  330. data/spec/unit/util/logging_spec.rb +14 -4
  331. data/spec/unit/util/rdoc/parser_spec.rb +5 -4
  332. data/spec/unit/util/rubygems_spec.rb +14 -0
  333. data/tasks/parallel.rake +2 -2
  334. metadata +154 -21
  335. checksums.yaml +0 -7
  336. data/lib/puppet/module_tool/applications/generator.rb +0 -142
  337. data/lib/puppet/module_tool/skeleton.rb +0 -37
  338. data/lib/puppet/module_tool/skeleton/templates/generator/Modulefile.erb +0 -11
  339. data/lib/puppet/module_tool/skeleton/templates/generator/README.erb +0 -16
  340. data/lib/puppet/module_tool/tar/solaris.rb +0 -5
  341. data/spec/fixtures/unit/provider/service/systemd/list_units_services +0 -17
  342. data/spec/unit/module_tool/tar/solaris_spec.rb +0 -22
@@ -30,6 +30,12 @@ describe checksum do
30
30
  @checksum.sum("foobar").should == "{md5}#{sum}"
31
31
  end
32
32
 
33
+ it "when using digest_algorithm 'sha256' should return the summed contents with a checksum label" do
34
+ sum = Digest::SHA256.hexdigest("foobar")
35
+ @resource[:checksum] = :sha256
36
+ @checksum.sum("foobar").should == "{sha256}#{sum}"
37
+ end
38
+
33
39
  it "should use :md5 as its default type" do
34
40
  @checksum.default.should == :md5
35
41
  end
@@ -4,211 +4,220 @@ require 'puppet/network/http_pool'
4
4
 
5
5
  require 'puppet/network/resolver'
6
6
 
7
- content = Puppet::Type.type(:file).attrclass(:content)
8
- describe content do
7
+ describe Puppet::Type.type(:file).attrclass(:content), :uses_checksums => true do
9
8
  include PuppetSpec::Files
9
+
10
+ let(:filename) { tmpfile('testfile') }
11
+
12
+ let(:catalog) { Puppet::Resource::Catalog.new }
13
+
14
+ let(:resource) { Puppet::Type.type(:file).new :path => filename, :catalog => catalog }
15
+
10
16
  before do
11
- @filename = tmpfile('testfile')
12
- @catalog = Puppet::Resource::Catalog.new
13
- @resource = Puppet::Type.type(:file).new :path => @filename, :catalog => @catalog
14
- File.open(@filename, 'w') {|f| f.write "initial file content"}
15
- content.stubs(:standalone?).returns(false)
17
+ File.open(filename, 'w') {|f| f.write "initial file content"}
18
+ described_class.stubs(:standalone?).returns(false)
16
19
  end
17
20
 
18
21
  describe "when determining the checksum type" do
22
+ let(:content) { described_class.new(:resource => resource) }
23
+
19
24
  it "should use the type specified in the source checksum if a source is set" do
20
- @resource[:source] = File.expand_path("/foo")
21
- @resource.parameter(:source).expects(:checksum).returns "{md5lite}eh"
25
+ resource[:source] = File.expand_path("/foo")
26
+ resource.parameter(:source).expects(:checksum).returns "{md5lite}eh"
22
27
 
23
- @content = content.new(:resource => @resource)
24
- @content.checksum_type.should == :md5lite
28
+ content.checksum_type.should == :md5lite
25
29
  end
26
30
 
27
31
  it "should use the type specified by the checksum parameter if no source is set" do
28
- @resource[:checksum] = :md5lite
32
+ resource[:checksum] = :md5lite
29
33
 
30
- @content = content.new(:resource => @resource)
31
- @content.checksum_type.should == :md5lite
34
+ content.checksum_type.should == :md5lite
35
+ end
36
+
37
+ with_digest_algorithms do
38
+ it "should use the type specified by digest_algorithm by default" do
39
+ content.checksum_type.should == digest_algorithm.intern
40
+ end
32
41
  end
33
42
  end
34
43
 
35
44
  describe "when determining the actual content to write" do
45
+ let(:content) { described_class.new(:resource => resource) }
46
+
36
47
  it "should use the set content if available" do
37
- @content = content.new(:resource => @resource)
38
- @content.should = "ehness"
39
- @content.actual_content.should == "ehness"
48
+ content.should = "ehness"
49
+ content.actual_content.should == "ehness"
40
50
  end
41
51
 
42
52
  it "should not use the content from the source if the source is set" do
43
53
  source = mock 'source'
44
54
 
45
- @resource.expects(:parameter).never.with(:source).returns source
55
+ resource.expects(:parameter).never.with(:source).returns source
46
56
 
47
- @content = content.new(:resource => @resource)
48
- @content.actual_content.should be_nil
57
+ content.actual_content.should be_nil
49
58
  end
50
59
  end
51
60
 
52
61
  describe "when setting the desired content" do
62
+ let(:content) { described_class.new(:resource => resource) }
63
+
53
64
  it "should make the actual content available via an attribute" do
54
- @content = content.new(:resource => @resource)
55
- @content.stubs(:checksum_type).returns "md5"
56
- @content.should = "this is some content"
65
+ content.stubs(:checksum_type).returns "md5"
66
+ content.should = "this is some content"
57
67
 
58
- @content.actual_content.should == "this is some content"
68
+ content.actual_content.should == "this is some content"
59
69
  end
60
70
 
61
- it "should store the checksum as the desired content" do
62
- @content = content.new(:resource => @resource)
63
- digest = Digest::MD5.hexdigest("this is some content")
71
+ with_digest_algorithms do
72
+ it "should store the checksum as the desired content" do
73
+ d = digest("this is some content")
64
74
 
65
- @content.stubs(:checksum_type).returns "md5"
66
- @content.should = "this is some content"
75
+ content.stubs(:checksum_type).returns digest_algorithm
76
+ content.should = "this is some content"
67
77
 
68
- @content.should.must == "{md5}#{digest}"
69
- end
78
+ content.should.must == "{#{digest_algorithm}}#{d}"
79
+ end
70
80
 
71
- it "should not checksum 'absent'" do
72
- @content = content.new(:resource => @resource)
73
- @content.should = :absent
81
+ it "should not checksum 'absent'" do
82
+ content.should = :absent
74
83
 
75
- @content.should.must == :absent
76
- end
84
+ content.should.must == :absent
85
+ end
77
86
 
78
- it "should accept a checksum as the desired content" do
79
- @content = content.new(:resource => @resource)
80
- digest = Digest::MD5.hexdigest("this is some content")
87
+ it "should accept a checksum as the desired content" do
88
+ d = digest("this is some content")
81
89
 
82
- string = "{md5}#{digest}"
83
- @content.should = string
90
+ string = "{#{digest_algorithm}}#{d}"
91
+ content.should = string
84
92
 
85
- @content.should.must == string
93
+ content.should.must == string
94
+ end
86
95
  end
87
96
 
88
97
  it "should convert the value to ASCII-8BIT", :if => "".respond_to?(:encode) do
89
- @content = content.new(:resource => @resource)
90
- @content.should= "Let's make a \u{2603}"
98
+ content.should= "Let's make a \u{2603}"
91
99
 
92
- @content.actual_content.should == "Let's make a \xE2\x98\x83".force_encoding(Encoding::ASCII_8BIT)
100
+ content.actual_content.should == "Let's make a \xE2\x98\x83".force_encoding(Encoding::ASCII_8BIT)
93
101
  end
94
102
  end
95
103
 
96
104
  describe "when retrieving the current content" do
105
+ let(:content) { described_class.new(:resource => resource) }
106
+
97
107
  it "should return :absent if the file does not exist" do
98
- @content = content.new(:resource => @resource)
99
- @resource.expects(:stat).returns nil
108
+ resource.expects(:stat).returns nil
100
109
 
101
- @content.retrieve.should == :absent
110
+ content.retrieve.should == :absent
102
111
  end
103
112
 
104
113
  it "should not manage content on directories" do
105
- @content = content.new(:resource => @resource)
106
-
107
114
  stat = mock 'stat', :ftype => "directory"
108
- @resource.expects(:stat).returns stat
115
+ resource.expects(:stat).returns stat
109
116
 
110
- @content.retrieve.should be_nil
117
+ content.retrieve.should be_nil
111
118
  end
112
119
 
113
120
  it "should not manage content on links" do
114
- @content = content.new(:resource => @resource)
115
-
116
121
  stat = mock 'stat', :ftype => "link"
117
- @resource.expects(:stat).returns stat
122
+ resource.expects(:stat).returns stat
118
123
 
119
- @content.retrieve.should be_nil
124
+ content.retrieve.should be_nil
120
125
  end
121
126
 
122
127
  it "should always return the checksum as a string" do
123
- @content = content.new(:resource => @resource)
124
- @resource[:checksum] = :mtime
128
+ resource[:checksum] = :mtime
125
129
 
126
130
  stat = mock 'stat', :ftype => "file"
127
- @resource.expects(:stat).returns stat
131
+ resource.expects(:stat).returns stat
128
132
 
129
133
  time = Time.now
130
- @resource.parameter(:checksum).expects(:mtime_file).with(@resource[:path]).returns time
134
+ resource.parameter(:checksum).expects(:mtime_file).with(resource[:path]).returns time
131
135
 
132
- @content.retrieve.should == "{mtime}#{time}"
136
+ content.retrieve.should == "{mtime}#{time}"
133
137
  end
134
138
 
135
- it "should return the checksum of the file if it exists and is a normal file" do
136
- @content = content.new(:resource => @resource)
137
- stat = mock 'stat', :ftype => "file"
138
- @resource.expects(:stat).returns stat
139
- @resource.parameter(:checksum).expects(:md5_file).with(@resource[:path]).returns "mysum"
139
+ with_digest_algorithms do
140
+ it "should return the checksum of the file if it exists and is a normal file" do
141
+ stat = mock 'stat', :ftype => "file"
142
+ resource.expects(:stat).returns stat
143
+ resource.parameter(:checksum).expects("#{digest_algorithm}_file".intern).with(resource[:path]).returns "mysum"
140
144
 
141
- @content.retrieve.should == "{md5}mysum"
145
+ content.retrieve.should == "{#{digest_algorithm}}mysum"
146
+ end
142
147
  end
143
148
  end
144
149
 
145
150
  describe "when testing whether the content is in sync" do
151
+ let(:content) { described_class.new(:resource => resource) }
152
+
146
153
  before do
147
- @resource[:ensure] = :file
148
- @content = content.new(:resource => @resource)
154
+ resource[:ensure] = :file
149
155
  end
150
156
 
151
157
  it "should return true if the resource shouldn't be a regular file" do
152
- @resource.expects(:should_be_file?).returns false
153
- @content.should = "foo"
154
- @content.must be_safe_insync("whatever")
158
+ resource.expects(:should_be_file?).returns false
159
+ content.should = "foo"
160
+ content.must be_safe_insync("whatever")
155
161
  end
156
162
 
157
163
  it "should warn that no content will be synced to links when ensure is :present" do
158
- @resource[:ensure] = :present
159
- @resource[:content] = 'foo'
160
- @resource.stubs(:should_be_file?).returns false
161
- @resource.stubs(:stat).returns mock("stat", :ftype => "link")
164
+ resource[:ensure] = :present
165
+ resource[:content] = 'foo'
166
+ resource.stubs(:should_be_file?).returns false
167
+ resource.stubs(:stat).returns mock("stat", :ftype => "link")
162
168
 
163
- @resource.expects(:warning).with {|msg| msg =~ /Ensure set to :present but file type is/}
169
+ resource.expects(:warning).with {|msg| msg =~ /Ensure set to :present but file type is/}
164
170
 
165
- @content.insync? :present
171
+ content.insync? :present
166
172
  end
167
173
 
168
174
  it "should return false if the current content is :absent" do
169
- @content.should = "foo"
170
- @content.should_not be_safe_insync(:absent)
175
+ content.should = "foo"
176
+ content.should_not be_safe_insync(:absent)
171
177
  end
172
178
 
173
179
  it "should return false if the file should be a file but is not present" do
174
- @resource.expects(:should_be_file?).returns true
175
- @content.should = "foo"
180
+ resource.expects(:should_be_file?).returns true
181
+ content.should = "foo"
176
182
 
177
- @content.should_not be_safe_insync(:absent)
183
+ content.should_not be_safe_insync(:absent)
178
184
  end
179
185
 
180
186
  describe "and the file exists" do
181
- before do
182
- @resource.stubs(:stat).returns mock("stat")
183
- @content.should = "some content"
184
- end
185
-
186
- it "should return false if the current contents are different from the desired content" do
187
- @content.should_not be_safe_insync("other content")
188
- end
187
+ with_digest_algorithms do
188
+ before do
189
+ resource.stubs(:stat).returns mock("stat")
190
+ resource[:checksum] = digest_algorithm
191
+ content.should = "some content"
192
+ end
189
193
 
190
- it "should return true if the sum for the current contents is the same as the sum for the desired content" do
191
- @content.must be_safe_insync("{md5}" + Digest::MD5.hexdigest("some content"))
192
- end
194
+ it "should return false if the current contents are different from the desired content" do
195
+ content.should_not be_safe_insync("other content")
196
+ end
193
197
 
194
- [true, false].product([true, false]).each do |cfg, param|
195
- describe "and Puppet[:show_diff] is #{cfg} and show_diff => #{param}" do
196
- before do
197
- Puppet[:show_diff] = cfg
198
- @resource.stubs(:show_diff?).returns param
199
- @resource[:loglevel] = "debug"
200
- end
198
+ it "should return true if the sum for the current contents is the same as the sum for the desired content" do
199
+ content.must be_safe_insync("{#{digest_algorithm}}" + digest("some content"))
200
+ end
201
201
 
202
- if cfg and param
203
- it "should display a diff" do
204
- @content.expects(:diff).returns("my diff").once
205
- @content.expects(:debug).with("\nmy diff").once
206
- @content.should_not be_safe_insync("other content")
202
+ [true, false].product([true, false]).each do |cfg, param|
203
+ describe "and Puppet[:show_diff] is #{cfg} and show_diff => #{param}" do
204
+ before do
205
+ Puppet[:show_diff] = cfg
206
+ resource.stubs(:show_diff?).returns param
207
+ resource[:loglevel] = "debug"
207
208
  end
208
- else
209
- it "should not display a diff" do
210
- @content.expects(:diff).never
211
- @content.should_not be_safe_insync("other content")
209
+
210
+ if cfg and param
211
+ it "should display a diff" do
212
+ content.expects(:diff).returns("my diff").once
213
+ content.expects(:debug).with("\nmy diff").once
214
+ content.should_not be_safe_insync("other content")
215
+ end
216
+ else
217
+ it "should not display a diff" do
218
+ content.expects(:diff).never
219
+ content.should_not be_safe_insync("other content")
220
+ end
212
221
  end
213
222
  end
214
223
  end
@@ -217,189 +226,250 @@ describe content do
217
226
 
218
227
  describe "and :replace is false" do
219
228
  before do
220
- @resource.stubs(:replace?).returns false
229
+ resource.stubs(:replace?).returns false
221
230
  end
222
231
 
223
232
  it "should be insync if the file exists and the content is different" do
224
- @resource.stubs(:stat).returns mock('stat')
233
+ resource.stubs(:stat).returns mock('stat')
225
234
 
226
- @content.must be_safe_insync("whatever")
235
+ content.must be_safe_insync("whatever")
227
236
  end
228
237
 
229
238
  it "should be insync if the file exists and the content is right" do
230
- @resource.stubs(:stat).returns mock('stat')
239
+ resource.stubs(:stat).returns mock('stat')
231
240
 
232
- @content.must be_safe_insync("something")
241
+ content.must be_safe_insync("something")
233
242
  end
234
243
 
235
244
  it "should not be insync if the file does not exist" do
236
- @content.should = "foo"
237
- @content.should_not be_safe_insync(:absent)
245
+ content.should = "foo"
246
+ content.should_not be_safe_insync(:absent)
238
247
  end
239
248
  end
240
249
  end
241
250
 
242
- describe "when changing the content" do
243
- before do
244
- @content = content.new(:resource => @resource)
245
- @content.should = "some content"
251
+ describe "when changing the content" do
252
+ let(:content) { described_class.new(:resource => resource) }
246
253
 
247
- @resource.stubs(:[]).with(:path).returns "/boo"
248
- @resource.stubs(:stat).returns "eh"
254
+ before do
255
+ resource.stubs(:[]).with(:path).returns "/boo"
256
+ resource.stubs(:stat).returns "eh"
249
257
  end
250
258
 
251
259
  it "should use the file's :write method to write the content" do
252
- @resource.expects(:write).with(:content)
260
+ resource.expects(:write).with(:content)
253
261
 
254
- @content.sync
262
+ content.sync
255
263
  end
256
264
 
257
265
  it "should return :file_changed if the file already existed" do
258
- @resource.expects(:stat).returns "something"
259
- @resource.stubs(:write)
260
- @content.sync.should == :file_changed
266
+ resource.expects(:stat).returns "something"
267
+ resource.stubs(:write)
268
+ content.sync.should == :file_changed
261
269
  end
262
270
 
263
271
  it "should return :file_created if the file did not exist" do
264
- @resource.expects(:stat).returns nil
265
- @resource.stubs(:write)
266
- @content.sync.should == :file_created
272
+ resource.expects(:stat).returns nil
273
+ resource.stubs(:write)
274
+ content.sync.should == :file_created
267
275
  end
268
276
  end
269
277
 
270
278
  describe "when writing" do
271
- before do
272
- @content = content.new(:resource => @resource)
273
- end
279
+ let(:content) { described_class.new(:resource => resource) }
280
+
281
+ let(:fh) { File.open(filename, 'wb') }
274
282
 
275
283
  it "should attempt to read from the filebucket if no actual content nor source exists" do
276
- @fh = File.open(@filename, 'wb')
277
- @content.should = "{md5}foo"
278
- @content.resource.bucket.class.any_instance.stubs(:getfile).returns "foo"
279
- @content.write(@fh)
280
- @fh.close
284
+ content.should = "{md5}foo"
285
+ content.resource.bucket.class.any_instance.stubs(:getfile).returns "foo"
286
+ content.write(fh)
287
+ fh.close
281
288
  end
282
289
 
283
290
  describe "from actual content" do
284
291
  before(:each) do
285
- @content.stubs(:actual_content).returns("this is content")
292
+ content.stubs(:actual_content).returns("this is content")
286
293
  end
287
294
 
288
295
  it "should write to the given file handle" do
289
296
  fh = mock 'filehandle'
290
297
  fh.expects(:print).with("this is content")
291
- @content.write(fh)
298
+ content.write(fh)
292
299
  end
293
300
 
294
301
  it "should return the current checksum value" do
295
- @resource.parameter(:checksum).expects(:sum_stream).returns "checksum"
296
- @content.write(@fh).should == "checksum"
302
+ resource.parameter(:checksum).expects(:sum_stream).returns "checksum"
303
+ content.write(fh).should == "checksum"
297
304
  end
298
305
  end
299
306
 
300
307
  describe "from a file bucket" do
301
308
  it "should fail if a file bucket cannot be retrieved" do
302
- @content.should = "{md5}foo"
303
- @content.resource.expects(:bucket).returns nil
304
- lambda { @content.write(@fh) }.should raise_error(Puppet::Error)
309
+ content.should = "{md5}foo"
310
+ content.resource.expects(:bucket).returns nil
311
+ expect { content.write(fh) }.to raise_error(Puppet::Error)
305
312
  end
306
313
 
307
314
  it "should fail if the file bucket cannot find any content" do
308
- @content.should = "{md5}foo"
315
+ content.should = "{md5}foo"
309
316
  bucket = stub 'bucket'
310
- @content.resource.expects(:bucket).returns bucket
317
+ content.resource.expects(:bucket).returns bucket
311
318
  bucket.expects(:getfile).with("foo").raises "foobar"
312
- lambda { @content.write(@fh) }.should raise_error(Puppet::Error)
319
+ expect { content.write(fh) }.to raise_error(Puppet::Error)
313
320
  end
314
321
 
315
322
  it "should write the returned content to the file" do
316
- @content.should = "{md5}foo"
323
+ content.should = "{md5}foo"
317
324
  bucket = stub 'bucket'
318
- @content.resource.expects(:bucket).returns bucket
325
+ content.resource.expects(:bucket).returns bucket
319
326
  bucket.expects(:getfile).with("foo").returns "mycontent"
320
327
 
321
328
  fh = mock 'filehandle'
322
329
  fh.expects(:print).with("mycontent")
323
- @content.write(fh)
330
+ content.write(fh)
324
331
  end
325
332
  end
326
333
 
327
334
  describe "from local source" do
335
+ let(:source_content) { "source file content\r\n"*10000 }
328
336
  before(:each) do
329
- @sourcename = tmpfile('source')
330
- @resource = Puppet::Type.type(:file).new :path => @filename, :backup => false, :source => @sourcename, :catalog => @catalog
337
+ sourcename = tmpfile('source')
338
+ resource[:backup] = false
339
+ resource[:source] = sourcename
331
340
 
332
- @source_content = "source file content\r\n"*10000
333
- @sourcefile = File.open(@sourcename, 'wb') {|f| f.write @source_content}
341
+ File.open(sourcename, 'wb') {|f| f.write source_content}
334
342
 
335
- @content = @resource.newattr(:content)
336
- @source = @resource.parameter :source #newattr(:source)
343
+ # This needs to be invoked to properly initialize the content property,
344
+ # or attempting to write a file will fail.
345
+ resource.newattr(:content)
337
346
  end
338
347
 
339
348
  it "should copy content from the source to the file" do
340
- @resource.write(@source)
349
+ source = resource.parameter(:source)
350
+ resource.write(source)
341
351
 
342
- Puppet::FileSystem.binread(@filename).should == @source_content
352
+ Puppet::FileSystem.binread(filename).should == source_content
343
353
  end
344
354
 
345
- it "should return the checksum computed" do
346
- File.open(@filename, 'wb') do |file|
347
- @content.write(file).should == "{md5}#{Digest::MD5.hexdigest(@source_content)}"
355
+ with_digest_algorithms do
356
+ it "should return the checksum computed" do
357
+ File.open(filename, 'wb') do |file|
358
+ resource[:checksum] = digest_algorithm
359
+ content.write(file).should == "{#{digest_algorithm}}#{digest(source_content)}"
360
+ end
348
361
  end
349
362
  end
350
363
  end
351
364
 
352
- describe "from remote source" do
365
+ describe "from an explicit fileserver" do
366
+ let(:source_content) { "source file content\n"*10000 }
367
+ let(:response) { stub_everything 'response' }
368
+ let(:source) { resource.newattr(:source) }
369
+
353
370
  before(:each) do
354
- @resource = Puppet::Type.type(:file).new :path => @filename, :backup => false, :catalog => @catalog
355
- @response = stub_everything 'response', :code => "200"
356
- @source_content = "source file content\n"*10000
357
- @response.stubs(:read_body).multiple_yields(*(["source file content\n"]*10000))
371
+ resource[:backup] = false
372
+ response.stubs(:read_body).multiple_yields(*(["source file content\n"]*10000))
358
373
 
359
- @conn = stub_everything 'connection'
360
- @conn.stubs(:request_get).yields @response
361
- Puppet::Network::HttpPool.stubs(:http_instance).returns @conn
374
+ conn = mock('connection')
375
+ conn.stubs(:request_get).yields response
362
376
 
363
- @content = @resource.newattr(:content)
364
- @sourcename = "puppet:///test/foo"
365
- @source = @resource.newattr(:source)
366
- @source.stubs(:metadata).returns stub_everything('metadata', :source => @sourcename, :ftype => 'file')
377
+ Puppet::Network::HttpPool.expects(:http_instance).with('somehostname',any_parameters).returns(conn).at_least_once
378
+
379
+ # This needs to be invoked to properly initialize the content property,
380
+ # or attempting to write a file will fail.
381
+ resource.newattr(:content)
382
+
383
+ source.stubs(:metadata).returns stub_everything('metadata', :source => "puppet://somehostname/test/foo", :ftype => 'file')
367
384
  end
368
385
 
369
- it "should write the contents to the file" do
370
- @resource.write(@source)
386
+ describe "and the request was successful" do
387
+ before { response.stubs(:code).returns '200' }
388
+
389
+ it "should write the contents to the file" do
390
+ resource.write(source)
391
+ Puppet::FileSystem.binread(filename).should == source_content
392
+ end
371
393
 
372
- Puppet::FileSystem.binread(@filename).should == @source_content
394
+ with_digest_algorithms do
395
+ it "should return the checksum computed" do
396
+ File.open(filename, 'w') do |file|
397
+ resource[:checksum] = digest_algorithm
398
+ content.write(file).should == "{#{digest_algorithm}}#{digest(source_content)}"
399
+ end
400
+ end
401
+ end
373
402
  end
374
403
 
375
404
  it "should not write anything if source is not found" do
376
- @response.stubs(:code).returns("404")
377
- lambda {@resource.write(@source)}.should raise_error(Net::HTTPError) { |e| e.message =~ /404/ }
378
- File.read(@filename).should == "initial file content"
405
+ response.stubs(:code).returns("404")
406
+ expect { resource.write(source) }.to raise_error(Net::HTTPError, /404/)
407
+ File.read(filename).should == "initial file content"
379
408
  end
380
409
 
381
410
  it "should raise an HTTP error in case of server error" do
382
- @response.stubs(:code).returns("500")
383
- lambda { @content.write(@fh) }.should raise_error { |e| e.message.include? @source_content }
411
+ response.stubs(:code).returns("500")
412
+ expect { content.write(fh) }.to raise_error(Net::HTTPError, /500/)
413
+ end
414
+
415
+ end
416
+
417
+ describe "from remote source" do
418
+ let(:source_content) { "source file content\n"*10000 }
419
+ let(:response) { stub_everything 'response' }
420
+ let(:source) { resource.newattr(:source) }
421
+
422
+ before(:each) do
423
+ resource[:backup] = false
424
+ response.stubs(:read_body).multiple_yields(*(["source file content\n"]*10000))
425
+
426
+ conn = stub_everything 'connection'
427
+ conn.stubs(:request_get).yields response
428
+ Puppet::Network::HttpPool.stubs(:http_instance).returns conn
429
+
430
+ # This needs to be invoked to properly initialize the content property,
431
+ # or attempting to write a file will fail.
432
+ resource.newattr(:content)
433
+ source.stubs(:metadata).returns stub_everything('metadata', :source => "puppet://somehostname/test/foo", :ftype => 'file')
384
434
  end
385
435
 
386
- it "should return the checksum computed" do
387
- File.open(@filename, 'w') do |file|
388
- @content.write(file).should == "{md5}#{Digest::MD5.hexdigest(@source_content)}"
436
+ describe "and the request was successful" do
437
+ before { response.stubs(:code).returns '200' }
438
+
439
+ it "should write the contents to the file" do
440
+ resource.write(source)
441
+ Puppet::FileSystem.binread(filename).should == source_content
442
+ end
443
+
444
+ with_digest_algorithms do
445
+ it "should return the checksum computed" do
446
+ File.open(filename, 'w') do |file|
447
+ resource[:checksum] = digest_algorithm
448
+ content.write(file).should == "{#{digest_algorithm}}#{digest(source_content)}"
449
+ end
450
+ end
389
451
  end
390
452
  end
453
+
454
+ it "should not write anything if source is not found" do
455
+ response.stubs(:code).returns("404")
456
+ expect {resource.write(source)}.to raise_error(Net::HTTPError, /404/)
457
+ File.read(filename).should == "initial file content"
458
+ end
459
+
460
+ it "should raise an HTTP error in case of server error" do
461
+ response.stubs(:code).returns("500")
462
+ expect { content.write(fh) }.to raise_error(Net::HTTPError, /500/)
463
+ end
391
464
  end
392
465
 
393
466
  # These are testing the implementation rather than the desired behaviour; while that bites, there are a whole
394
467
  # pile of other methods in the File type that depend on intimate details of this implementation and vice-versa.
395
468
  # If these blow up, you are gonna have to review the callers to make sure they don't explode! --daniel 2011-02-01
396
469
  describe "each_chunk_from should work" do
397
- before do
398
- @content = content.new(:resource => @resource)
399
- end
400
470
 
401
471
  it "when content is a string" do
402
- @content.each_chunk_from('i_am_a_string') { |chunk| chunk.should == 'i_am_a_string' }
472
+ content.each_chunk_from('i_am_a_string') { |chunk| chunk.should == 'i_am_a_string' }
403
473
  end
404
474
 
405
475
  # The following manifest is a case where source and content.should are both set
@@ -409,54 +479,54 @@ describe content do
409
479
  # }
410
480
  it "when content checksum comes from source" do
411
481
  source_param = Puppet::Type.type(:file).attrclass(:source)
412
- source = source_param.new(:resource => @resource)
413
- @content.should = "{md5}123abcd"
482
+ source = source_param.new(:resource => resource)
483
+ content.should = "{md5}123abcd"
414
484
 
415
- @content.expects(:chunk_file_from_source).returns('from_source')
416
- @content.each_chunk_from(source) { |chunk| chunk.should == 'from_source' }
485
+ content.expects(:chunk_file_from_source).returns('from_source')
486
+ content.each_chunk_from(source) { |chunk| chunk.should == 'from_source' }
417
487
  end
418
488
 
419
489
  it "when no content, source, but ensure present" do
420
- @resource[:ensure] = :present
421
- @content.each_chunk_from(nil) { |chunk| chunk.should == '' }
490
+ resource[:ensure] = :present
491
+ content.each_chunk_from(nil) { |chunk| chunk.should == '' }
422
492
  end
423
493
 
424
494
  # you might do this if you were just auditing
425
495
  it "when no content, source, but ensure file" do
426
- @resource[:ensure] = :file
427
- @content.each_chunk_from(nil) { |chunk| chunk.should == '' }
496
+ resource[:ensure] = :file
497
+ content.each_chunk_from(nil) { |chunk| chunk.should == '' }
428
498
  end
429
499
 
430
500
  it "when source_or_content is nil and content not a checksum" do
431
- @content.each_chunk_from(nil) { |chunk| chunk.should == '' }
501
+ content.each_chunk_from(nil) { |chunk| chunk.should == '' }
432
502
  end
433
503
 
434
504
  # the content is munged so that if it's a checksum nil gets passed in
435
505
  it "when content is a checksum it should try to read from filebucket" do
436
- @content.should = "{md5}123abcd"
437
- @content.expects(:read_file_from_filebucket).once.returns('im_a_filebucket')
438
- @content.each_chunk_from(nil) { |chunk| chunk.should == 'im_a_filebucket' }
506
+ content.should = "{md5}123abcd"
507
+ content.expects(:read_file_from_filebucket).once.returns('im_a_filebucket')
508
+ content.each_chunk_from(nil) { |chunk| chunk.should == 'im_a_filebucket' }
439
509
  end
440
510
 
441
511
  it "when running as puppet apply" do
442
512
  Puppet[:default_file_terminus] = "file_server"
443
513
  source_or_content = stubs('source_or_content')
444
514
  source_or_content.expects(:content).once.returns :whoo
445
- @content.each_chunk_from(source_or_content) { |chunk| chunk.should == :whoo }
515
+ content.each_chunk_from(source_or_content) { |chunk| chunk.should == :whoo }
446
516
  end
447
517
 
448
518
  it "when running from source with a local file" do
449
519
  source_or_content = stubs('source_or_content')
450
520
  source_or_content.expects(:local?).returns true
451
- @content.expects(:chunk_file_from_disk).with(source_or_content).once.yields 'woot'
452
- @content.each_chunk_from(source_or_content) { |chunk| chunk.should == 'woot' }
521
+ content.expects(:chunk_file_from_disk).with(source_or_content).once.yields 'woot'
522
+ content.each_chunk_from(source_or_content) { |chunk| chunk.should == 'woot' }
453
523
  end
454
524
 
455
525
  it "when running from source with a remote file" do
456
526
  source_or_content = stubs('source_or_content')
457
527
  source_or_content.expects(:local?).returns false
458
- @content.expects(:chunk_file_from_source).with(source_or_content).once.yields 'woot'
459
- @content.each_chunk_from(source_or_content) { |chunk| chunk.should == 'woot' }
528
+ content.expects(:chunk_file_from_source).with(source_or_content).once.yields 'woot'
529
+ content.each_chunk_from(source_or_content) { |chunk| chunk.should == 'woot' }
460
530
  end
461
531
  end
462
532
  end