puppet 3.3.2 → 3.4.0.rc1

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 (589) hide show
  1. data/CONTRIBUTING.md +22 -0
  2. data/Gemfile +11 -2
  3. data/README.md +13 -17
  4. data/README_DEVELOPER.md +1 -1
  5. data/Rakefile +1 -1
  6. data/examples/hiera/README.md +4 -4
  7. data/ext/debian/puppetmaster.init +1 -0
  8. data/ext/debian/rules +2 -5
  9. data/ext/nagios/check_puppet.rb +7 -7
  10. data/ext/osx/file_mapping.yaml +1 -1
  11. data/ext/osx/preflight.erb +34 -19
  12. data/ext/rack/{files/config.ru → config.ru} +0 -0
  13. data/ext/rack/{files/apache2.conf → example-passenger-vhost.conf} +6 -0
  14. data/ext/redhat/puppet.spec.erb +20 -2
  15. data/ext/systemd/{puppetagent.service → puppet.service} +0 -0
  16. data/lib/hiera_puppet.rb +2 -2
  17. data/lib/puppet/agent.rb +1 -6
  18. data/lib/puppet/application.rb +15 -2
  19. data/lib/puppet/application/agent.rb +2 -7
  20. data/lib/puppet/application/apply.rb +8 -13
  21. data/lib/puppet/application/cert.rb +47 -7
  22. data/lib/puppet/application/device.rb +1 -6
  23. data/lib/puppet/application/face_base.rb +1 -1
  24. data/lib/puppet/application/filebucket.rb +1 -1
  25. data/lib/puppet/application/inspect.rb +3 -12
  26. data/lib/puppet/application/master.rb +1 -6
  27. data/lib/puppet/application/queue.rb +1 -6
  28. data/lib/puppet/application/resource.rb +2 -6
  29. data/lib/puppet/coercion.rb +11 -0
  30. data/lib/puppet/configurer.rb +5 -3
  31. data/lib/puppet/configurer/downloader.rb +3 -1
  32. data/lib/puppet/configurer/plugin_handler.rb +10 -0
  33. data/lib/puppet/confine.rb +80 -0
  34. data/lib/puppet/{provider/confine → confine}/exists.rb +3 -3
  35. data/lib/puppet/{provider/confine → confine}/false.rb +2 -2
  36. data/lib/puppet/{provider/confine → confine}/feature.rb +2 -2
  37. data/lib/puppet/{provider/confine → confine}/true.rb +2 -2
  38. data/lib/puppet/{provider/confine → confine}/variable.rb +2 -2
  39. data/lib/puppet/{provider/confine_collection.rb → confine_collection.rb} +4 -4
  40. data/lib/puppet/{provider/confiner.rb → confiner.rb} +4 -4
  41. data/lib/puppet/daemon.rb +2 -6
  42. data/lib/puppet/data_binding.rb +2 -30
  43. data/lib/puppet/defaults.rb +283 -174
  44. data/lib/puppet/error.rb +1 -0
  45. data/lib/puppet/external/nagios.rb +0 -2
  46. data/lib/puppet/external/nagios/base.rb +4 -3
  47. data/lib/puppet/external/nagios/grammar.ry +173 -112
  48. data/lib/puppet/external/nagios/parser.rb +233 -184
  49. data/lib/puppet/face/file/store.rb +1 -1
  50. data/lib/puppet/face/module/generate.rb +5 -7
  51. data/lib/puppet/face/parser.rb +12 -2
  52. data/lib/puppet/face/plugin.rb +6 -0
  53. data/lib/puppet/feature/base.rb +16 -0
  54. data/lib/puppet/feature/external_facts.rb +5 -0
  55. data/lib/puppet/feature/libuser.rb +1 -1
  56. data/lib/puppet/feature/msgpack.rb +1 -0
  57. data/lib/puppet/feature/rails.rb +2 -2
  58. data/lib/puppet/file_bucket/dipper.rb +8 -6
  59. data/lib/puppet/file_bucket/file.rb +17 -1
  60. data/lib/puppet/file_serving/base.rb +21 -10
  61. data/lib/puppet/file_serving/configuration.rb +5 -7
  62. data/lib/puppet/file_serving/configuration/parser.rb +1 -1
  63. data/lib/puppet/file_serving/content.rb +1 -1
  64. data/lib/puppet/file_serving/fileset.rb +3 -3
  65. data/lib/puppet/file_serving/metadata.rb +22 -18
  66. data/lib/puppet/file_serving/mount/file.rb +1 -1
  67. data/lib/puppet/file_serving/mount/pluginfacts.rb +35 -0
  68. data/lib/puppet/file_system.rb +3 -0
  69. data/lib/puppet/file_system/file.rb +261 -0
  70. data/lib/puppet/file_system/file18.rb +5 -0
  71. data/lib/puppet/file_system/file19.rb +5 -0
  72. data/lib/puppet/file_system/file19windows.rb +113 -0
  73. data/lib/puppet/file_system/memory_file.rb +31 -0
  74. data/lib/puppet/file_system/tempfile.rb +20 -0
  75. data/lib/puppet/indirector/active_record.rb +1 -0
  76. data/lib/puppet/indirector/catalog/compiler.rb +28 -0
  77. data/lib/puppet/indirector/certificate_request/memory.rb +6 -0
  78. data/lib/puppet/indirector/data_binding/hiera.rb +46 -2
  79. data/lib/puppet/indirector/direct_file_server.rb +2 -2
  80. data/lib/puppet/indirector/facts/facter.rb +25 -0
  81. data/lib/puppet/indirector/file_bucket_file/file.rb +60 -74
  82. data/lib/puppet/indirector/indirection.rb +5 -1
  83. data/lib/puppet/indirector/json.rb +1 -1
  84. data/lib/puppet/indirector/key/ca.rb +4 -0
  85. data/lib/puppet/indirector/key/file.rb +7 -3
  86. data/lib/puppet/indirector/key/memory.rb +6 -0
  87. data/lib/puppet/indirector/node/write_only_yaml.rb +2 -2
  88. data/lib/puppet/indirector/request.rb +17 -11
  89. data/lib/puppet/indirector/resource/ral.rb +5 -0
  90. data/lib/puppet/indirector/resource/rest.rb +1 -0
  91. data/lib/puppet/indirector/resource/store_configs.rb +4 -0
  92. data/lib/puppet/indirector/rest.rb +2 -1
  93. data/lib/puppet/indirector/ssl_file.rb +7 -7
  94. data/lib/puppet/indirector/terminus.rb +4 -0
  95. data/lib/puppet/indirector/yaml.rb +3 -3
  96. data/lib/puppet/interface/documentation.rb +4 -11
  97. data/lib/puppet/module.rb +19 -6
  98. data/lib/puppet/module_tool/applications/builder.rb +1 -1
  99. data/lib/puppet/module_tool/applications/installer.rb +1 -1
  100. data/lib/puppet/module_tool/checksums.rb +1 -1
  101. data/lib/puppet/module_tool/dependency.rb +7 -3
  102. data/lib/puppet/module_tool/metadata.rb +6 -2
  103. data/lib/puppet/module_tool/tar.rb +2 -1
  104. data/lib/puppet/module_tool/tar/gnu.rb +6 -2
  105. data/lib/puppet/module_tool/tar/mini.rb +2 -0
  106. data/lib/puppet/module_tool/tar/solaris.rb +2 -5
  107. data/lib/puppet/network/authconfig.rb +0 -2
  108. data/lib/puppet/network/authentication.rb +1 -1
  109. data/lib/puppet/network/authstore.rb +6 -7
  110. data/lib/puppet/network/format.rb +2 -3
  111. data/lib/puppet/network/format_handler.rb +16 -11
  112. data/lib/puppet/network/format_support.rb +14 -0
  113. data/lib/puppet/network/formats.rb +26 -0
  114. data/lib/puppet/network/http/connection.rb +8 -41
  115. data/lib/puppet/network/http/handler.rb +28 -32
  116. data/lib/puppet/network/http/webrick.rb +15 -22
  117. data/lib/puppet/network/http_pool.rb +43 -9
  118. data/lib/puppet/network/rights.rb +0 -0
  119. data/lib/puppet/node.rb +24 -8
  120. data/lib/puppet/node/environment.rb +18 -20
  121. data/lib/puppet/node/facts.rb +23 -6
  122. data/lib/puppet/parameter.rb +15 -2
  123. data/lib/puppet/parameter/boolean.rb +5 -0
  124. data/lib/puppet/parameter/value_collection.rb +6 -4
  125. data/lib/puppet/parser/ast/resourceparam.rb +2 -1
  126. data/lib/puppet/parser/compiler.rb +25 -9
  127. data/lib/puppet/parser/files.rb +1 -1
  128. data/lib/puppet/parser/functions.rb +12 -21
  129. data/lib/puppet/parser/functions/collect.rb +6 -35
  130. data/lib/puppet/parser/functions/contain.rb +26 -0
  131. data/lib/puppet/parser/functions/create_resources.rb +5 -0
  132. data/lib/puppet/parser/functions/extlookup.rb +2 -2
  133. data/lib/puppet/parser/functions/file.rb +1 -1
  134. data/lib/puppet/parser/functions/{reject.rb → filter.rb} +13 -12
  135. data/lib/puppet/parser/functions/fqdn_rand.rb +13 -5
  136. data/lib/puppet/parser/functions/include.rb +18 -1
  137. data/lib/puppet/parser/functions/map.rb +44 -0
  138. data/lib/puppet/parser/functions/select.rb +6 -38
  139. data/lib/puppet/parser/lexer.rb +1 -1
  140. data/lib/puppet/parser/parser_support.rb +1 -1
  141. data/lib/puppet/parser/resource.rb +6 -45
  142. data/lib/puppet/parser/scope.rb +33 -2
  143. data/lib/puppet/parser/type_loader.rb +4 -60
  144. data/lib/puppet/pops/binder/bindings_loader.rb +1 -1
  145. data/lib/puppet/pops/binder/config/binder_config.rb +3 -3
  146. data/lib/puppet/pops/binder/hiera2/bindings_provider.rb +1 -1
  147. data/lib/puppet/pops/binder/scheme_handler/confdir_hiera_scheme.rb +1 -1
  148. data/lib/puppet/pops/binder/scheme_handler/module_hiera_scheme.rb +2 -2
  149. data/lib/puppet/pops/issues.rb +4 -0
  150. data/lib/puppet/pops/model/ast_transformer.rb +4 -1
  151. data/lib/puppet/pops/model/model_label_provider.rb +1 -1
  152. data/lib/puppet/pops/parser/egrammar.ra +5 -24
  153. data/lib/puppet/pops/parser/eparser.rb +859 -902
  154. data/lib/puppet/pops/parser/lexer.rb +48 -30
  155. data/lib/puppet/pops/parser/parser_support.rb +1 -1
  156. data/lib/puppet/pops/patterns.rb +4 -4
  157. data/lib/puppet/pops/utils.rb +1 -1
  158. data/lib/puppet/pops/validation/checker3_1.rb +25 -20
  159. data/lib/puppet/provider.rb +23 -6
  160. data/lib/puppet/provider/aixobject.rb +0 -0
  161. data/lib/puppet/provider/augeas/augeas.rb +21 -5
  162. data/lib/puppet/provider/confine.rb +5 -79
  163. data/lib/puppet/provider/cron/crontab.rb +0 -0
  164. data/lib/puppet/provider/exec.rb +9 -7
  165. data/lib/puppet/provider/exec/posix.rb +10 -1
  166. data/lib/puppet/provider/exec/windows.rb +1 -1
  167. data/lib/puppet/provider/file/posix.rb +1 -0
  168. data/lib/puppet/provider/file/windows.rb +16 -5
  169. data/lib/puppet/provider/group/aix.rb +0 -0
  170. data/lib/puppet/provider/group/windows_adsi.rb +33 -1
  171. data/lib/puppet/provider/macauthorization/macauthorization.rb +1 -1
  172. data/lib/puppet/provider/mailalias/aliases.rb +0 -0
  173. data/lib/puppet/provider/maillist/mailman.rb +0 -0
  174. data/lib/puppet/provider/mount/parsed.rb +0 -0
  175. data/lib/puppet/provider/nameservice/directoryservice.rb +3 -3
  176. data/lib/puppet/provider/package/appdmg.rb +1 -1
  177. data/lib/puppet/provider/package/apple.rb +1 -1
  178. data/lib/puppet/provider/package/apt.rb +1 -1
  179. data/lib/puppet/provider/package/aptitude.rb +0 -0
  180. data/lib/puppet/provider/package/blastwave.rb +1 -1
  181. data/lib/puppet/provider/package/dpkg.rb +1 -1
  182. data/lib/puppet/provider/package/fink.rb +1 -1
  183. data/lib/puppet/provider/package/freebsd.rb +0 -0
  184. data/lib/puppet/provider/package/gem.rb +0 -0
  185. data/lib/puppet/provider/package/macports.rb +0 -0
  186. data/lib/puppet/provider/package/msi.rb +4 -10
  187. data/lib/puppet/provider/package/nim.rb +8 -8
  188. data/lib/puppet/provider/package/openbsd.rb +1 -1
  189. data/lib/puppet/provider/package/opkg.rb +0 -0
  190. data/lib/puppet/provider/package/pacman.rb +2 -2
  191. data/lib/puppet/provider/package/pkgdmg.rb +1 -1
  192. data/lib/puppet/provider/package/pkgutil.rb +1 -1
  193. data/lib/puppet/provider/package/ports.rb +0 -0
  194. data/lib/puppet/provider/package/rpm.rb +39 -3
  195. data/lib/puppet/provider/package/sun.rb +3 -3
  196. data/lib/puppet/provider/package/sunfreeware.rb +0 -0
  197. data/lib/puppet/provider/package/windows.rb +12 -19
  198. data/lib/puppet/provider/package/windows/package.rb +1 -1
  199. data/lib/puppet/provider/package/yum.rb +2 -2
  200. data/lib/puppet/provider/parsedfile.rb +0 -0
  201. data/lib/puppet/provider/port/parsed.rb +0 -0
  202. data/lib/puppet/provider/service/base.rb +0 -0
  203. data/lib/puppet/provider/service/bsd.rb +3 -3
  204. data/lib/puppet/provider/service/daemontools.rb +8 -8
  205. data/lib/puppet/provider/service/debian.rb +0 -0
  206. data/lib/puppet/provider/service/freebsd.rb +3 -3
  207. data/lib/puppet/provider/service/init.rb +5 -4
  208. data/lib/puppet/provider/service/launchd.rb +35 -24
  209. data/lib/puppet/provider/service/openbsd.rb +23 -0
  210. data/lib/puppet/provider/service/redhat.rb +0 -0
  211. data/lib/puppet/provider/service/runit.rb +3 -3
  212. data/lib/puppet/provider/service/smf.rb +0 -0
  213. data/lib/puppet/provider/service/src.rb +0 -0
  214. data/lib/puppet/provider/service/systemd.rb +0 -0
  215. data/lib/puppet/provider/service/upstart.rb +3 -3
  216. data/lib/puppet/provider/ssh_authorized_key/parsed.rb +2 -2
  217. data/lib/puppet/provider/sshkey/parsed.rb +0 -0
  218. data/lib/puppet/provider/user/aix.rb +0 -0
  219. data/lib/puppet/provider/user/directoryservice.rb +1 -1
  220. data/lib/puppet/provider/user/useradd.rb +1 -1
  221. data/lib/puppet/provider/zone/solaris.rb +1 -1
  222. data/lib/puppet/rails/benchmark.rb +1 -1
  223. data/lib/puppet/reference/configuration.rb +1 -2
  224. data/lib/puppet/reference/indirection.rb +12 -14
  225. data/lib/puppet/relationship.rb +7 -4
  226. data/lib/puppet/reports.rb +2 -2
  227. data/lib/puppet/reports/rrdgraph.rb +1 -1
  228. data/lib/puppet/reports/store.rb +3 -3
  229. data/lib/puppet/reports/tagmail.rb +2 -2
  230. data/lib/puppet/resource.rb +66 -8
  231. data/lib/puppet/resource/catalog.rb +18 -25
  232. data/lib/puppet/resource/status.rb +10 -4
  233. data/lib/puppet/run.rb +6 -2
  234. data/lib/puppet/settings.rb +39 -119
  235. data/lib/puppet/settings/base_setting.rb +8 -9
  236. data/lib/puppet/settings/directory_setting.rb +8 -0
  237. data/lib/puppet/settings/file_setting.rb +35 -1
  238. data/lib/puppet/settings/priority_setting.rb +42 -0
  239. data/lib/puppet/ssl.rb +4 -0
  240. data/lib/puppet/ssl/certificate.rb +18 -0
  241. data/lib/puppet/ssl/certificate_authority.rb +101 -72
  242. data/lib/puppet/ssl/certificate_authority/autosign_command.rb +44 -0
  243. data/lib/puppet/ssl/certificate_authority/interface.rb +21 -17
  244. data/lib/puppet/ssl/certificate_factory.rb +38 -12
  245. data/lib/puppet/ssl/certificate_request.rb +201 -47
  246. data/lib/puppet/ssl/certificate_request_attributes.rb +34 -0
  247. data/lib/puppet/ssl/certificate_revocation_list.rb +2 -2
  248. data/lib/puppet/ssl/host.rb +21 -10
  249. data/lib/puppet/ssl/inventory.rb +6 -10
  250. data/lib/puppet/ssl/key.rb +1 -1
  251. data/lib/puppet/ssl/oids.rb +78 -0
  252. data/lib/puppet/ssl/validator.rb +41 -97
  253. data/lib/puppet/ssl/validator/default_validator.rb +153 -0
  254. data/lib/puppet/ssl/validator/no_validator.rb +17 -0
  255. data/lib/puppet/status.rb +4 -0
  256. data/lib/puppet/test/test_helper.rb +5 -0
  257. data/lib/puppet/transaction.rb +13 -0
  258. data/lib/puppet/transaction/event.rb +8 -3
  259. data/lib/puppet/transaction/report.rb +6 -2
  260. data/lib/puppet/transaction/resource_harness.rb +173 -115
  261. data/lib/puppet/type.rb +30 -13
  262. data/lib/puppet/type/augeas.rb +12 -46
  263. data/lib/puppet/type/component.rb +1 -7
  264. data/lib/puppet/type/cron.rb +0 -0
  265. data/lib/puppet/type/exec.rb +13 -1
  266. data/lib/puppet/type/file.rb +19 -10
  267. data/lib/puppet/type/file/checksum.rb +0 -0
  268. data/lib/puppet/type/file/content.rb +3 -0
  269. data/lib/puppet/type/file/ensure.rb +33 -15
  270. data/lib/puppet/type/file/group.rb +0 -0
  271. data/lib/puppet/type/file/mode.rb +6 -2
  272. data/lib/puppet/type/file/owner.rb +0 -0
  273. data/lib/puppet/type/file/source.rb +65 -14
  274. data/lib/puppet/type/file/target.rb +6 -6
  275. data/lib/puppet/type/file/type.rb +0 -0
  276. data/lib/puppet/type/filebucket.rb +0 -0
  277. data/lib/puppet/type/group.rb +18 -0
  278. data/lib/puppet/type/host.rb +0 -0
  279. data/lib/puppet/type/k5login.rb +4 -4
  280. data/lib/puppet/type/mailalias.rb +0 -0
  281. data/lib/puppet/type/maillist.rb +0 -0
  282. data/lib/puppet/type/mount.rb +15 -1
  283. data/lib/puppet/type/package.rb +7 -1
  284. data/lib/puppet/type/port.rb +0 -0
  285. data/lib/puppet/type/schedule.rb +9 -4
  286. data/lib/puppet/type/service.rb +1 -1
  287. data/lib/puppet/type/sshkey.rb +0 -0
  288. data/lib/puppet/type/tidy.rb +1 -1
  289. data/lib/puppet/type/user.rb +3 -0
  290. data/lib/puppet/type/yumrepo.rb +8 -6
  291. data/lib/puppet/type/zpool.rb +0 -0
  292. data/lib/puppet/util.rb +4 -31
  293. data/lib/puppet/util/adsi.rb +73 -17
  294. data/lib/puppet/util/autoload.rb +3 -3
  295. data/lib/puppet/util/backups.rb +4 -4
  296. data/lib/puppet/util/cacher.rb +7 -13
  297. data/lib/puppet/util/checksums.rb +2 -2
  298. data/lib/puppet/util/classgen.rb +3 -1
  299. data/lib/puppet/util/colors.rb +1 -0
  300. data/lib/puppet/util/command_line.rb +5 -0
  301. data/lib/puppet/util/docs.rb +33 -27
  302. data/lib/puppet/util/execution.rb +42 -18
  303. data/lib/puppet/util/filetype.rb +3 -3
  304. data/lib/puppet/util/instance_loader.rb +2 -2
  305. data/lib/puppet/util/instrumentation.rb +23 -42
  306. data/lib/puppet/util/instrumentation/data.rb +11 -4
  307. data/lib/puppet/util/instrumentation/indirection_probe.rb +11 -4
  308. data/lib/puppet/util/instrumentation/instrumentable.rb +7 -14
  309. data/lib/puppet/util/instrumentation/listener.rb +15 -8
  310. data/lib/puppet/util/instrumentation/listeners/log.rb +4 -10
  311. data/lib/puppet/util/instrumentation/listeners/performance.rb +8 -14
  312. data/lib/puppet/util/limits.rb +12 -0
  313. data/lib/puppet/util/lockfile.rb +2 -2
  314. data/lib/puppet/util/log.rb +14 -6
  315. data/lib/puppet/util/log/destinations.rb +23 -1
  316. data/lib/puppet/util/metric.rb +9 -3
  317. data/lib/puppet/util/monkey_patches.rb +7 -2
  318. data/lib/puppet/util/network_device/config.rb +1 -1
  319. data/lib/puppet/util/plugins.rb +1 -1
  320. data/lib/puppet/util/posix.rb +0 -0
  321. data/lib/puppet/util/profiler.rb +7 -2
  322. data/lib/puppet/util/provider_features.rb +2 -2
  323. data/lib/puppet/util/rdoc.rb +28 -30
  324. data/lib/puppet/util/rdoc/code_objects.rb +75 -25
  325. data/lib/puppet/util/rdoc/generators/puppet_generator.rb +1 -1
  326. data/lib/puppet/util/rdoc/parser.rb +12 -487
  327. data/lib/puppet/util/rdoc/parser/puppet_parser_core.rb +477 -0
  328. data/lib/puppet/util/rdoc/parser/puppet_parser_rdoc1.rb +19 -0
  329. data/lib/puppet/util/rdoc/parser/puppet_parser_rdoc2.rb +14 -0
  330. data/lib/puppet/util/reference.rb +1 -1
  331. data/lib/puppet/util/resource_template.rb +1 -1
  332. data/lib/puppet/util/selinux.rb +1 -1
  333. data/lib/puppet/util/storage.rb +2 -2
  334. data/lib/puppet/util/suidmanager.rb +1 -1
  335. data/lib/puppet/util/tag_set.rb +29 -0
  336. data/lib/puppet/util/tagging.rb +8 -24
  337. data/lib/puppet/util/watched_file.rb +1 -1
  338. data/lib/puppet/util/watcher.rb +1 -1
  339. data/lib/puppet/util/windows.rb +3 -0
  340. data/lib/puppet/util/windows/access_control_entry.rb +84 -0
  341. data/lib/puppet/util/windows/access_control_list.rb +106 -0
  342. data/lib/puppet/util/windows/file.rb +213 -0
  343. data/lib/puppet/util/windows/process.rb +199 -0
  344. data/lib/puppet/util/windows/root_certs.rb +52 -37
  345. data/lib/puppet/util/windows/security.rb +270 -245
  346. data/lib/puppet/util/windows/security_descriptor.rb +62 -0
  347. data/lib/puppet/util/windows/sid.rb +26 -4
  348. data/lib/puppet/version.rb +2 -2
  349. data/spec/fixtures/releases/jamtur01-apache/lib/puppet/provider/a2mod/debian.rb +1 -1
  350. data/spec/fixtures/unit/indirector/{hiera → data_binding/hiera}/global.yaml +0 -0
  351. data/spec/fixtures/unit/indirector/data_binding/hiera/invalid.yaml +1 -0
  352. data/spec/fixtures/unit/module/trailing-comma.json +24 -0
  353. data/spec/fixtures/unit/util/monkey_patches/x509.pem +32 -0
  354. data/spec/integration/application/apply_spec.rb +1 -1
  355. data/spec/integration/application/doc_spec.rb +1 -1
  356. data/spec/integration/configurer_spec.rb +4 -2
  357. data/spec/integration/data_binding.rb +100 -0
  358. data/spec/integration/indirector/catalog/compiler_spec.rb +16 -13
  359. data/spec/integration/indirector/direct_file_server_spec.rb +3 -5
  360. data/spec/integration/indirector/file_content/file_server_spec.rb +2 -2
  361. data/spec/integration/node/facts_spec.rb +1 -1
  362. data/spec/integration/node_spec.rb +1 -1
  363. data/spec/integration/parser/compiler_spec.rb +90 -0
  364. data/spec/integration/parser/parser_spec.rb +2 -2
  365. data/spec/integration/provider/cron/crontab_spec.rb +3 -5
  366. data/spec/integration/resource/catalog_spec.rb +1 -1
  367. data/spec/integration/ssl/autosign_spec.rb +90 -0
  368. data/spec/integration/ssl/certificate_authority_spec.rb +62 -69
  369. data/spec/integration/ssl/certificate_revocation_list_spec.rb +1 -1
  370. data/spec/integration/ssl/host_spec.rb +1 -1
  371. data/spec/integration/transaction_spec.rb +13 -13
  372. data/spec/integration/type/exec_spec.rb +2 -2
  373. data/spec/integration/type/file_spec.rb +287 -45
  374. data/spec/integration/type/tidy_spec.rb +3 -3
  375. data/spec/integration/util/rdoc/parser_spec.rb +236 -35
  376. data/spec/integration/util/settings_spec.rb +1 -1
  377. data/spec/integration/util/windows/process_spec.rb +22 -0
  378. data/spec/integration/util/windows/security_spec.rb +316 -106
  379. data/spec/lib/matchers/containment_matchers.rb +52 -0
  380. data/spec/lib/puppet_spec/compiler.rb +6 -0
  381. data/spec/lib/puppet_spec/files.rb +20 -21
  382. data/spec/shared_behaviours/documentation_on_faces.rb +3 -3
  383. data/spec/shared_behaviours/file_server_terminus.rb +2 -2
  384. data/spec/shared_contexts/platform.rb +1 -0
  385. data/spec/spec_helper.rb +13 -1
  386. data/spec/unit/agent_spec.rb +0 -12
  387. data/spec/unit/application/agent_spec.rb +4 -4
  388. data/spec/unit/application/apply_spec.rb +18 -2
  389. data/spec/unit/application/cert_spec.rb +8 -6
  390. data/spec/unit/application/device_spec.rb +1 -1
  391. data/spec/unit/application/filebucket_spec.rb +1 -1
  392. data/spec/unit/application/inspect_spec.rb +1 -1
  393. data/spec/unit/application_spec.rb +24 -0
  394. data/spec/unit/configurer/downloader_spec.rb +8 -7
  395. data/spec/unit/configurer/fact_handler_spec.rb +23 -0
  396. data/spec/unit/configurer/plugin_handler_spec.rb +7 -2
  397. data/spec/unit/configurer_spec.rb +15 -5
  398. data/spec/unit/{provider/confine → confine}/exists_spec.rb +12 -12
  399. data/spec/unit/{provider/confine → confine}/false_spec.rb +9 -9
  400. data/spec/unit/{provider/confine → confine}/feature_spec.rb +10 -10
  401. data/spec/unit/{provider/confine → confine}/true_spec.rb +7 -7
  402. data/spec/unit/{provider/confine → confine}/variable_spec.rb +16 -16
  403. data/spec/unit/{provider/confine_collection_spec.rb → confine_collection_spec.rb} +30 -30
  404. data/spec/unit/{provider/confine_spec.rb → confine_spec.rb} +11 -11
  405. data/spec/unit/{provider/confiner_spec.rb → confiner_spec.rb} +4 -4
  406. data/spec/unit/face/parser_spec.rb +54 -0
  407. data/spec/unit/file_bucket/dipper_spec.rb +2 -2
  408. data/spec/unit/file_serving/base_spec.rb +32 -9
  409. data/spec/unit/file_serving/configuration_spec.rb +7 -7
  410. data/spec/unit/file_serving/content_spec.rb +12 -7
  411. data/spec/unit/file_serving/fileset_spec.rb +57 -27
  412. data/spec/unit/file_serving/metadata_spec.rb +74 -12
  413. data/spec/unit/file_serving/mount/file_spec.rb +10 -10
  414. data/spec/unit/file_serving/mount/pluginfacts_spec.rb +73 -0
  415. data/spec/unit/file_system/file_spec.rb +486 -0
  416. data/spec/unit/file_system/tempfile_spec.rb +48 -0
  417. data/spec/unit/graph/relationship_graph_spec.rb +0 -6
  418. data/spec/unit/hiera_puppet_spec.rb +2 -2
  419. data/spec/unit/indirector/catalog/compiler_spec.rb +15 -19
  420. data/spec/unit/indirector/certificate_status/file_spec.rb +30 -40
  421. data/spec/unit/indirector/data_binding/hiera_spec.rb +95 -2
  422. data/spec/unit/indirector/direct_file_server_spec.rb +6 -6
  423. data/spec/unit/indirector/facts/facter_spec.rb +33 -0
  424. data/spec/unit/indirector/file_bucket_file/file_spec.rb +61 -52
  425. data/spec/unit/indirector/file_metadata/file_spec.rb +2 -2
  426. data/spec/unit/indirector/file_server_spec.rb +4 -4
  427. data/spec/unit/indirector/json_spec.rb +4 -4
  428. data/spec/unit/indirector/key/file_spec.rb +13 -14
  429. data/spec/unit/indirector/resource/ral_spec.rb +7 -0
  430. data/spec/unit/indirector/resource/store_configs_spec.rb +11 -0
  431. data/spec/unit/indirector/rest_spec.rb +7 -3
  432. data/spec/unit/indirector/ssl_file_spec.rb +14 -17
  433. data/spec/unit/indirector/yaml_spec.rb +4 -4
  434. data/spec/unit/module_spec.rb +43 -15
  435. data/spec/unit/module_tool/tar/gnu_spec.rb +2 -2
  436. data/spec/unit/module_tool/tar/solaris_spec.rb +2 -2
  437. data/spec/unit/module_tool/tar_spec.rb +45 -0
  438. data/spec/unit/network/authconfig_spec.rb +2 -1
  439. data/spec/unit/network/authentication_spec.rb +2 -2
  440. data/spec/unit/network/format_handler_spec.rb +2 -2
  441. data/spec/unit/network/formats_spec.rb +24 -0
  442. data/spec/unit/network/http/connection_spec.rb +76 -199
  443. data/spec/unit/network/http/handler_spec.rb +33 -34
  444. data/spec/unit/network/http_pool_spec.rb +8 -5
  445. data/spec/unit/node/environment_spec.rb +76 -90
  446. data/spec/unit/node/facts_spec.rb +20 -3
  447. data/spec/unit/node_spec.rb +43 -0
  448. data/spec/unit/parameter/boolean_spec.rb +22 -12
  449. data/spec/unit/parser/ast/resourceparam_spec.rb +51 -0
  450. data/spec/unit/parser/compiler_spec.rb +103 -35
  451. data/spec/unit/parser/eparser_adapter_spec.rb +12 -12
  452. data/spec/unit/parser/files_spec.rb +11 -11
  453. data/spec/unit/parser/functions/contain_spec.rb +185 -0
  454. data/spec/unit/parser/functions/create_resources_spec.rb +13 -5
  455. data/spec/unit/parser/functions/generate_spec.rb +1 -1
  456. data/spec/unit/parser/functions_spec.rb +2 -2
  457. data/spec/unit/parser/lexer_spec.rb +1 -1
  458. data/spec/unit/parser/methods/each_spec.rb +1 -1
  459. data/spec/unit/parser/methods/{select_spec.rb → filter_spec.rb} +11 -11
  460. data/spec/unit/parser/methods/map_spec.rb +95 -0
  461. data/spec/unit/parser/methods/reduce_spec.rb +12 -11
  462. data/spec/unit/parser/methods/shared.rb +5 -5
  463. data/spec/unit/parser/methods/slice_spec.rb +13 -13
  464. data/spec/unit/parser/parser_spec.rb +1 -1
  465. data/spec/unit/parser/resource/param_spec.rb +44 -0
  466. data/spec/unit/parser/resource_spec.rb +16 -15
  467. data/spec/unit/pops/model/ast_transformer_spec.rb +18 -4
  468. data/spec/unit/pops/parser/lexer_spec.rb +22 -5
  469. data/spec/unit/pops/parser/parse_calls_spec.rb +5 -5
  470. data/spec/unit/pops/transformer/transform_calls_spec.rb +6 -6
  471. data/spec/unit/pops/transformer/transform_containers_spec.rb +2 -2
  472. data/spec/unit/pops/validator/validator_spec.rb +31 -0
  473. data/spec/unit/provider/augeas/augeas_spec.rb +57 -2
  474. data/spec/unit/provider/exec/posix_spec.rb +8 -3
  475. data/spec/unit/provider/file/posix_spec.rb +2 -2
  476. data/spec/unit/provider/group/windows_adsi_spec.rb +70 -3
  477. data/spec/unit/provider/nameservice/directoryservice_spec.rb +3 -3
  478. data/spec/unit/provider/package/apt_spec.rb +1 -1
  479. data/spec/unit/provider/package/msi_spec.rb +15 -42
  480. data/spec/unit/provider/package/openbsd_spec.rb +3 -3
  481. data/spec/unit/provider/package/rpm_spec.rb +56 -13
  482. data/spec/unit/provider/package/windows_spec.rb +15 -19
  483. data/spec/unit/provider/service/base_spec.rb +1 -1
  484. data/spec/unit/provider/service/daemontools_spec.rb +18 -8
  485. data/spec/unit/provider/service/freebsd_spec.rb +3 -3
  486. data/spec/unit/provider/service/gentoo_spec.rb +5 -2
  487. data/spec/unit/provider/service/init_spec.rb +17 -17
  488. data/spec/unit/provider/service/launchd_spec.rb +76 -23
  489. data/spec/unit/provider/service/openbsd_spec.rb +125 -0
  490. data/spec/unit/provider/service/openwrt_spec.rb +1 -1
  491. data/spec/unit/provider/service/runit_spec.rb +12 -5
  492. data/spec/unit/provider/service/upstart_spec.rb +4 -4
  493. data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +5 -5
  494. data/spec/unit/provider/user/directoryservice_spec.rb +4 -4
  495. data/spec/unit/provider/zone/solaris_spec.rb +1 -1
  496. data/spec/unit/provider_spec.rb +2 -2
  497. data/spec/unit/reports/http_spec.rb +19 -34
  498. data/spec/unit/reports/store_spec.rb +2 -2
  499. data/spec/unit/resource/catalog_spec.rb +81 -11
  500. data/spec/unit/resource/status_spec.rb +11 -1
  501. data/spec/unit/resource/type_spec.rb +30 -1
  502. data/spec/unit/resource_spec.rb +40 -4
  503. data/spec/unit/settings/file_setting_spec.rb +2 -2
  504. data/spec/unit/settings/path_setting_spec.rb +2 -2
  505. data/spec/unit/settings/priority_setting_spec.rb +66 -0
  506. data/spec/unit/settings_spec.rb +16 -31
  507. data/spec/unit/ssl/certificate_authority/autosign_command_spec.rb +30 -0
  508. data/spec/unit/ssl/certificate_authority_spec.rb +129 -134
  509. data/spec/unit/ssl/certificate_factory_spec.rb +18 -0
  510. data/spec/unit/ssl/certificate_request_attributes_spec.rb +61 -0
  511. data/spec/unit/ssl/certificate_request_spec.rb +103 -0
  512. data/spec/unit/ssl/certificate_spec.rb +31 -18
  513. data/spec/unit/ssl/host_spec.rb +34 -8
  514. data/spec/unit/ssl/inventory_spec.rb +27 -62
  515. data/spec/unit/ssl/key_spec.rb +4 -4
  516. data/spec/unit/ssl/oids_spec.rb +48 -0
  517. data/spec/unit/ssl/validator_spec.rb +49 -6
  518. data/spec/unit/status_spec.rb +9 -0
  519. data/spec/unit/transaction/event_spec.rb +1 -9
  520. data/spec/unit/transaction/report_spec.rb +20 -1
  521. data/spec/unit/transaction/resource_harness_spec.rb +60 -210
  522. data/spec/unit/transaction_spec.rb +54 -8
  523. data/spec/unit/type/component_spec.rb +2 -2
  524. data/spec/unit/type/exec_spec.rb +14 -7
  525. data/spec/unit/type/file/content_spec.rb +13 -2
  526. data/spec/unit/type/file/ctime_spec.rb +1 -1
  527. data/spec/unit/type/file/mode_spec.rb +48 -2
  528. data/spec/unit/type/file/mtime_spec.rb +1 -1
  529. data/spec/unit/type/file/source_spec.rb +177 -7
  530. data/spec/unit/type/file_spec.rb +63 -71
  531. data/spec/unit/type/group_spec.rb +20 -0
  532. data/spec/unit/type/k5login_spec.rb +3 -3
  533. data/spec/unit/type/mount_spec.rb +53 -0
  534. data/spec/unit/type/nagios_spec.rb +216 -0
  535. data/spec/unit/type/package_spec.rb +7 -1
  536. data/spec/unit/type/schedule_spec.rb +6 -0
  537. data/spec/unit/type/service_spec.rb +3 -3
  538. data/spec/unit/type/tidy_spec.rb +14 -14
  539. data/spec/unit/type/user_spec.rb +9 -0
  540. data/spec/unit/type_spec.rb +86 -4
  541. data/spec/unit/util/adsi_spec.rb +120 -12
  542. data/spec/unit/util/autoload_spec.rb +14 -14
  543. data/spec/unit/util/backups_spec.rb +29 -21
  544. data/spec/unit/util/checksums_spec.rb +2 -1
  545. data/spec/unit/util/command_line_spec.rb +41 -0
  546. data/spec/unit/util/docs_spec.rb +91 -0
  547. data/spec/unit/util/execution_spec.rb +26 -2
  548. data/spec/unit/util/filetype_spec.rb +7 -7
  549. data/spec/unit/util/lockfile_spec.rb +2 -2
  550. data/spec/unit/util/log/destinations_spec.rb +32 -0
  551. data/spec/unit/util/monkey_patches_spec.rb +41 -0
  552. data/spec/unit/util/pidlock_spec.rb +6 -6
  553. data/spec/unit/util/rdoc/parser_spec.rb +15 -13
  554. data/spec/unit/util/rdoc_spec.rb +18 -24
  555. data/spec/unit/util/resource_template_spec.rb +3 -3
  556. data/spec/unit/util/selinux_spec.rb +4 -2
  557. data/spec/unit/util/storage_spec.rb +4 -4
  558. data/spec/unit/util/suidmanager_spec.rb +7 -0
  559. data/spec/unit/util/tag_set_spec.rb +46 -0
  560. data/spec/unit/util/tagging_spec.rb +82 -45
  561. data/spec/unit/util/watcher_spec.rb +4 -1
  562. data/spec/unit/util/windows/access_control_entry_spec.rb +67 -0
  563. data/spec/unit/util/windows/access_control_list_spec.rb +133 -0
  564. data/spec/unit/util/windows/root_certs_spec.rb +10 -8
  565. data/spec/unit/util/windows/security_descriptor_spec.rb +117 -0
  566. data/spec/unit/util/windows/sid_spec.rb +69 -0
  567. data/spec/unit/util_spec.rb +7 -7
  568. data/tasks/ci.rake +17 -36
  569. metadata +2811 -2746
  570. checksums.yaml +0 -7
  571. data/examples/mac_automount.pp +0 -16
  572. data/examples/mcx_dock_absent.pp +0 -4
  573. data/examples/mcx_dock_default.pp +0 -118
  574. data/examples/mcx_dock_full.pp +0 -125
  575. data/examples/mcx_dock_invalid.pp +0 -9
  576. data/examples/mcx_nogroup.pp +0 -118
  577. data/examples/mcx_notexists_absent.pp +0 -4
  578. data/ext/rack/README +0 -58
  579. data/ext/rack/manifest.pp +0 -59
  580. data/lib/puppet/external/lock.rb +0 -63
  581. data/lib/puppet/indirector/hiera.rb +0 -39
  582. data/lib/puppet/parser/functions/foreach.rb +0 -95
  583. data/spec/integration/network/server/webrick_spec.rb +0 -76
  584. data/spec/integration/parser/functions_spec.rb +0 -16
  585. data/spec/unit/indirector/hiera_spec.rb +0 -154
  586. data/spec/unit/parser/methods/collect_spec.rb +0 -153
  587. data/spec/unit/parser/methods/foreach_spec.rb +0 -91
  588. data/spec/unit/parser/methods/reject_spec.rb +0 -73
  589. data/spec/unit/resource/resource_type.json +0 -34
@@ -3,6 +3,21 @@ require 'spec_helper'
3
3
 
4
4
  require 'puppet/file_serving/metadata'
5
5
 
6
+ # the json-schema gem doesn't support windows
7
+ if not Puppet.features.microsoft_windows?
8
+ FILE_METADATA_SCHEMA = JSON.parse(File.read(File.join(File.dirname(__FILE__), '../../../api/schemas/file_metadata.json')))
9
+
10
+ describe "catalog schema" do
11
+ it "should validate against the json meta-schema" do
12
+ JSON::Validator.validate!(JSON_META_SCHEMA, FILE_METADATA_SCHEMA)
13
+ end
14
+ end
15
+
16
+ def validate_json_for_file_metadata(file_metadata)
17
+ JSON::Validator.validate!(FILE_METADATA_SCHEMA, file_metadata.to_pson)
18
+ end
19
+ end
20
+
6
21
  describe Puppet::FileServing::Metadata do
7
22
  let(:foobar) { File.expand_path('/foo/bar') }
8
23
 
@@ -84,7 +99,6 @@ describe Puppet::FileServing::Metadata do
84
99
  it "should pass the checksum in the hash verbatim as the checksum's value" do
85
100
  metadata.to_pson_data_hash['data']['checksum']['value'].should == metadata.checksum
86
101
  end
87
-
88
102
  end
89
103
  end
90
104
 
@@ -139,6 +153,10 @@ describe Puppet::FileServing::Metadata do
139
153
  metadata.checksum.should == "{mtime}#{@time}"
140
154
  end
141
155
  end
156
+
157
+ it "should validate against the schema", :unless => Puppet.features.microsoft_windows? do
158
+ validate_json_for_file_metadata(metadata)
159
+ end
142
160
  end
143
161
 
144
162
  describe "when managing directories" do
@@ -160,25 +178,45 @@ describe Puppet::FileServing::Metadata do
160
178
  metadata.collect
161
179
  metadata.checksum.should == "{ctime}#{time}"
162
180
  end
181
+
182
+ it "should validate against the schema", :unless => Puppet.features.microsoft_windows? do
183
+ metadata.collect
184
+ validate_json_for_file_metadata(metadata)
185
+ end
163
186
  end
187
+ end
188
+ end
164
189
 
165
- describe "when managing links", :unless => Puppet.features.microsoft_windows? do
190
+ shared_examples_for "metadata collector symlinks" do
191
+
192
+ let(:metadata) do
193
+ data = described_class.new(path)
194
+ data.collect
195
+ data
196
+ end
197
+
198
+ describe "when collecting attributes" do
199
+ describe "when managing links" do
166
200
  # 'path' is a link that points to 'target'
167
201
  let(:path) { tmpfile('file_serving_metadata_link') }
168
202
  let(:target) { tmpfile('file_serving_metadata_target') }
169
203
  let(:checksum) { Digest::MD5.hexdigest("some content\n") }
170
- let(:fmode) { File.lstat(path).mode & 0777 }
204
+ let(:fmode) { Puppet::FileSystem::File.new(path).lstat.mode & 0777 }
171
205
 
172
206
  before :each do
173
207
  File.open(target, "wb") {|f| f.print("some content\n")}
174
208
  set_mode(0644, target)
175
209
 
176
- FileUtils.symlink(target, path)
210
+ Puppet::FileSystem::File.new(target).symlink(path)
177
211
  end
178
212
 
179
213
  it "should read links instead of returning their checksums" do
180
214
  metadata.destination.should == target
181
215
  end
216
+
217
+ it "should validate against the schema", :unless => Puppet.features.microsoft_windows? do
218
+ validate_json_for_file_metadata(metadata)
219
+ end
182
220
  end
183
221
  end
184
222
 
@@ -209,6 +247,10 @@ describe Puppet::FileServing::Metadata do
209
247
 
210
248
  proc { metadata.collect}.should raise_error(Errno::ENOENT)
211
249
  end
250
+
251
+ it "should validate against the schema", :unless => Puppet.features.microsoft_windows? do
252
+ validate_json_for_file_metadata(metadata)
253
+ end
212
254
  end
213
255
  end
214
256
 
@@ -222,6 +264,7 @@ describe Puppet::FileServing::Metadata do
222
264
  end
223
265
 
224
266
  it_should_behave_like "metadata collector"
267
+ it_should_behave_like "metadata collector symlinks"
225
268
 
226
269
  def set_mode(mode, path)
227
270
  File.chmod(mode, path)
@@ -239,6 +282,7 @@ describe Puppet::FileServing::Metadata do
239
282
  end
240
283
 
241
284
  it_should_behave_like "metadata collector"
285
+ it_should_behave_like "metadata collector symlinks" if Puppet.features.manages_symlinks?
242
286
 
243
287
  describe "if ACL metadata cannot be collected" do
244
288
  let(:path) { tmpdir('file_serving_metadata_acl') }
@@ -274,16 +318,24 @@ describe Puppet::FileServing::Metadata do
274
318
  end
275
319
 
276
320
 
277
- describe Puppet::FileServing::Metadata, " when pointing to a link", :unless => Puppet.features.microsoft_windows? do
321
+ describe Puppet::FileServing::Metadata, " when pointing to a link", :if => Puppet.features.manages_symlinks? do
278
322
  describe "when links are managed" do
279
323
  before do
280
- @file = Puppet::FileServing::Metadata.new("/base/path/my/file", :links => :manage)
281
- File.expects(:lstat).with("/base/path/my/file").returns stub("stat", :uid => 1, :gid => 2, :ftype => "link", :mode => 0755)
282
- File.expects(:readlink).with("/base/path/my/file").returns "/some/other/path"
283
-
324
+ path = "/base/path/my/file"
325
+ @file = Puppet::FileServing::Metadata.new(path, :links => :manage)
326
+ stat = stub("stat", :uid => 1, :gid => 2, :ftype => "link", :mode => 0755)
327
+ stub_file = stub(:readlink => "/some/other/path", :lstat => stat)
328
+ Puppet::FileSystem::File.expects(:new).with(path).at_least_once.returns stub_file
284
329
  @checksum = Digest::MD5.hexdigest("some content\n") # Remove these when :managed links are no longer checksumed.
285
330
  @file.stubs(:md5_file).returns(@checksum) #
331
+
332
+ if Puppet.features.microsoft_windows?
333
+ win_stat = stub('win_stat', :owner => 'snarf', :group => 'thundercats',
334
+ :ftype => 'link', :mode => 0755)
335
+ Puppet::FileServing::Metadata::WindowsStat.stubs(:new).returns win_stat
336
+ end
286
337
  end
338
+
287
339
  it "should store the destination of the link in :destination if links are :manage" do
288
340
  @file.collect
289
341
  @file.destination.should == "/some/other/path"
@@ -301,9 +353,19 @@ describe Puppet::FileServing::Metadata, " when pointing to a link", :unless => P
301
353
 
302
354
  describe "when links are followed" do
303
355
  before do
304
- @file = Puppet::FileServing::Metadata.new("/base/path/my/file", :links => :follow)
305
- File.expects(:stat).with("/base/path/my/file").returns stub("stat", :uid => 1, :gid => 2, :ftype => "file", :mode => 0755)
306
- File.expects(:readlink).with("/base/path/my/file").never
356
+ path = "/base/path/my/file"
357
+ @file = Puppet::FileServing::Metadata.new(path, :links => :follow)
358
+ stat = stub("stat", :uid => 1, :gid => 2, :ftype => "file", :mode => 0755)
359
+ mocked_file = mock(path, :stat => stat)
360
+ Puppet::FileSystem::File.expects(:new).with(path).at_least_once.returns mocked_file
361
+ mocked_file.expects(:readlink).never
362
+
363
+ if Puppet.features.microsoft_windows?
364
+ win_stat = stub('win_stat', :owner => 'snarf', :group => 'thundercats',
365
+ :ftype => 'file', :mode => 0755)
366
+ Puppet::FileServing::Metadata::WindowsStat.stubs(:new).returns win_stat
367
+ end
368
+
307
369
  @checksum = Digest::MD5.hexdigest("some content\n")
308
370
  @file.stubs(:md5_file).returns(@checksum)
309
371
  end
@@ -85,7 +85,7 @@ describe Puppet::FileServing::Mount::File do
85
85
  include FileServingMountTesting
86
86
 
87
87
  before do
88
- FileTest.stubs(:exist?).returns(true)
88
+ Puppet::FileSystem::File.stubs(:exist?).returns(true)
89
89
  FileTest.stubs(:directory?).returns(true)
90
90
  FileTest.stubs(:readable?).returns(true)
91
91
  @mount = Puppet::FileServing::Mount::File.new("test")
@@ -95,12 +95,12 @@ describe Puppet::FileServing::Mount::File do
95
95
  end
96
96
 
97
97
  it "should return nil if the file is absent" do
98
- FileTest.stubs(:exist?).returns(false)
98
+ Puppet::FileSystem::File.stubs(:exist?).returns(false)
99
99
  @mount.complete_path("/my/path", nil).should be_nil
100
100
  end
101
101
 
102
102
  it "should write a log message if the file is absent" do
103
- FileTest.stubs(:exist?).returns(false)
103
+ Puppet::FileSystem::File.stubs(:exist?).returns(false)
104
104
 
105
105
  Puppet.expects(:info).with("File does not exist or is not accessible: /mount/my/path")
106
106
 
@@ -108,12 +108,12 @@ describe Puppet::FileServing::Mount::File do
108
108
  end
109
109
 
110
110
  it "should return the file path if the file is present" do
111
- FileTest.stubs(:exist?).with("/my/path").returns(true)
111
+ Puppet::FileSystem::File.stubs(:exist?).with("/my/path").returns(true)
112
112
  @mount.complete_path("/my/path", nil).should == "/mount/my/path"
113
113
  end
114
114
 
115
115
  it "should treat a nil file name as the path to the mount itself" do
116
- FileTest.stubs(:exist?).returns(true)
116
+ Puppet::FileSystem::File.stubs(:exist?).returns(true)
117
117
  @mount.complete_path(nil, nil).should == "/mount"
118
118
  end
119
119
 
@@ -141,7 +141,7 @@ describe Puppet::FileServing::Mount::File do
141
141
  include FileServingMountTesting
142
142
 
143
143
  before do
144
- FileTest.stubs(:exist?).returns(true)
144
+ Puppet::FileSystem::File.stubs(:exist?).returns(true)
145
145
  FileTest.stubs(:directory?).returns(true)
146
146
  FileTest.stubs(:readable?).returns(true)
147
147
  @mount = Puppet::FileServing::Mount::File.new("test")
@@ -153,7 +153,7 @@ describe Puppet::FileServing::Mount::File do
153
153
  end
154
154
 
155
155
  it "should return the results of the complete file path" do
156
- FileTest.stubs(:exist?).returns(false)
156
+ Puppet::FileSystem::File.stubs(:exist?).returns(false)
157
157
  @mount.expects(:complete_path).with("/my/path", "foo").returns "eh"
158
158
  @mount.find("/my/path", @request).should == "eh"
159
159
  end
@@ -163,7 +163,7 @@ describe Puppet::FileServing::Mount::File do
163
163
  include FileServingMountTesting
164
164
 
165
165
  before do
166
- FileTest.stubs(:exist?).returns(true)
166
+ Puppet::FileSystem::File.stubs(:exist?).returns(true)
167
167
  FileTest.stubs(:directory?).returns(true)
168
168
  FileTest.stubs(:readable?).returns(true)
169
169
  @mount = Puppet::FileServing::Mount::File.new("test")
@@ -175,13 +175,13 @@ describe Puppet::FileServing::Mount::File do
175
175
  end
176
176
 
177
177
  it "should return the results of the complete file path as an array" do
178
- FileTest.stubs(:exist?).returns(false)
178
+ Puppet::FileSystem::File.stubs(:exist?).returns(false)
179
179
  @mount.expects(:complete_path).with("/my/path", "foo").returns "eh"
180
180
  @mount.search("/my/path", @request).should == ["eh"]
181
181
  end
182
182
 
183
183
  it "should return nil if the complete path is nil" do
184
- FileTest.stubs(:exist?).returns(false)
184
+ Puppet::FileSystem::File.stubs(:exist?).returns(false)
185
185
  @mount.expects(:complete_path).with("/my/path", "foo").returns nil
186
186
  @mount.search("/my/path", @request).should be_nil
187
187
  end
@@ -0,0 +1,73 @@
1
+ #! /usr/bin/env ruby
2
+ require 'spec_helper'
3
+ require 'puppet/file_serving/mount/pluginfacts'
4
+
5
+ describe Puppet::FileServing::Mount::PluginFacts do
6
+ before do
7
+ @mount = Puppet::FileServing::Mount::PluginFacts.new("pluginfacts")
8
+
9
+ @environment = stub 'environment', :module => nil
10
+ @options = { :recurse => true }
11
+ @request = stub 'request', :environment => @environment, :options => @options
12
+ end
13
+
14
+ describe "when finding files" do
15
+ it "should use the provided environment to find the modules" do
16
+ @environment.expects(:modules).returns []
17
+
18
+ @mount.find("foo", @request)
19
+ end
20
+
21
+ it "should return nil if no module can be found with a matching plugin" do
22
+ mod = mock 'module'
23
+ mod.stubs(:pluginfact).with("foo/bar").returns nil
24
+
25
+ @environment.stubs(:modules).returns [mod]
26
+ @mount.find("foo/bar", @request).should be_nil
27
+ end
28
+
29
+ it "should return the file path from the module" do
30
+ mod = mock 'module'
31
+ mod.stubs(:pluginfact).with("foo/bar").returns "eh"
32
+
33
+ @environment.stubs(:modules).returns [mod]
34
+ @mount.find("foo/bar", @request).should == "eh"
35
+ end
36
+ end
37
+
38
+ describe "when searching for files" do
39
+ it "should use the node's environment to find the modules" do
40
+ @environment.expects(:modules).at_least_once.returns []
41
+ @environment.stubs(:modulepath).returns ["/tmp/modules"]
42
+
43
+ @mount.search("foo", @request)
44
+ end
45
+
46
+ it "should return modulepath if no modules can be found that have plugins" do
47
+ mod = mock 'module'
48
+ mod.stubs(:pluginfacts?).returns false
49
+
50
+ @environment.stubs(:modules).returns []
51
+ @environment.stubs(:modulepath).returns ["/"]
52
+ @options.expects(:[]=).with(:recurse, false)
53
+ @mount.search("foo/bar", @request).should == ["/"]
54
+ end
55
+
56
+ it "should return nil if no modules can be found that have plugins and modulepath is invalid" do
57
+ mod = mock 'module'
58
+ mod.stubs(:pluginfacts?).returns false
59
+
60
+ @environment.stubs(:modules).returns []
61
+ @environment.stubs(:modulepath).returns []
62
+ @mount.search("foo/bar", @request).should be_nil
63
+ end
64
+
65
+ it "should return the plugin paths for each module that has plugins" do
66
+ one = stub 'module', :pluginfacts? => true, :plugin_fact_directory => "/one"
67
+ two = stub 'module', :pluginfacts? => true, :plugin_fact_directory => "/two"
68
+
69
+ @environment.stubs(:modules).returns [one, two]
70
+ @mount.search("foo/bar", @request).should == %w{/one /two}
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,486 @@
1
+ require 'spec_helper'
2
+ require 'puppet/file_system'
3
+ require 'puppet/util/platform'
4
+
5
+ describe Puppet::FileSystem::File do
6
+ include PuppetSpec::Files
7
+
8
+ context "#exclusive_open" do
9
+ it "opens ands allows updating of an existing file" do
10
+ file = Puppet::FileSystem::File.new(file_containing("file_to_update", "the contents"))
11
+
12
+ file.exclusive_open(0660, 'r+') do |fh|
13
+ old = fh.read
14
+ fh.truncate(0)
15
+ fh.rewind
16
+ fh.write("updated #{old}")
17
+ end
18
+
19
+ expect(file.read).to eq("updated the contents")
20
+ end
21
+
22
+ it "opens, creates ands allows updating of a new file" do
23
+ file = Puppet::FileSystem::File.new(tmpfile("file_to_update"))
24
+
25
+ file.exclusive_open(0660, 'w') do |fh|
26
+ fh.write("updated new file")
27
+ end
28
+
29
+ expect(file.read).to eq("updated new file")
30
+ end
31
+
32
+ it "excludes other processes from updating at the same time", :unless => Puppet::Util::Platform.windows? do
33
+ file = Puppet::FileSystem::File.new(file_containing("file_to_update", "0"))
34
+
35
+ increment_counter_in_multiple_processes(file, 5, 'r+')
36
+
37
+ expect(file.read).to eq("5")
38
+ end
39
+
40
+ it "excludes other processes from updating at the same time even when creating the file", :unless => Puppet::Util::Platform.windows? do
41
+ file = Puppet::FileSystem::File.new(tmpfile("file_to_update"))
42
+
43
+ increment_counter_in_multiple_processes(file, 5, 'a+')
44
+
45
+ expect(file.read).to eq("5")
46
+ end
47
+
48
+ it "times out if the lock cannot be aquired in a specified amount of time", :unless => Puppet::Util::Platform.windows? do
49
+ file = tmpfile("file_to_update")
50
+
51
+ child = spawn_process_that_locks(file)
52
+
53
+ expect do
54
+ Puppet::FileSystem::File.new(file).exclusive_open(0666, 'a', 0.1) do |f|
55
+ end
56
+ end.to raise_error(Timeout::Error)
57
+
58
+ Process.kill(9, child)
59
+ end
60
+
61
+ def spawn_process_that_locks(file)
62
+ read, write = IO.pipe
63
+
64
+ child = Kernel.fork do
65
+ read.close
66
+ Puppet::FileSystem::File.new(file).exclusive_open(0666, 'a') do |fh|
67
+ write.write(true)
68
+ write.close
69
+ sleep 10
70
+ end
71
+ end
72
+
73
+ write.close
74
+ read.read
75
+ read.close
76
+
77
+ child
78
+ end
79
+
80
+ def increment_counter_in_multiple_processes(file, num_procs, options)
81
+ children = []
82
+ 5.times do |number|
83
+ children << Kernel.fork do
84
+ file.exclusive_open(0660, options) do |fh|
85
+ fh.rewind
86
+ contents = (fh.read || 0).to_i
87
+ fh.truncate(0)
88
+ fh.rewind
89
+ fh.write((contents + 1).to_s)
90
+ end
91
+ exit(0)
92
+ end
93
+ end
94
+
95
+ children.each { |pid| Process.wait(pid) }
96
+ end
97
+ end
98
+
99
+ describe "symlink",
100
+ :if => ! Puppet.features.manages_symlinks? &&
101
+ Puppet.features.microsoft_windows? do
102
+
103
+ let (:file) { Puppet::FileSystem::File.new(tmpfile("somefile")) }
104
+ let (:missing_file) { Puppet::FileSystem::File.new(tmpfile("missingfile")) }
105
+ let (:expected_msg) { "This version of Windows does not support symlinks. Windows Vista / 2008 or higher is required." }
106
+
107
+ before :each do
108
+ FileUtils.touch(file.path)
109
+ end
110
+
111
+ it "should raise an error when trying to create a symlink" do
112
+ expect { file.symlink('foo') }.to raise_error(Puppet::Util::Windows::Error)
113
+ end
114
+
115
+ it "should return false when trying to check if a path is a symlink" do
116
+ file.symlink?.should be_false
117
+ end
118
+
119
+ it "should raise an error when trying to read a symlink" do
120
+ expect { file.readlink }.to raise_error(Puppet::Util::Windows::Error)
121
+ end
122
+
123
+ it "should return a File::Stat instance when calling stat on an existing file" do
124
+ file.stat.should be_instance_of(File::Stat)
125
+ end
126
+
127
+ it "should raise Errno::ENOENT when calling stat on a missing file" do
128
+ expect { missing_file.stat }.to raise_error(Errno::ENOENT)
129
+ end
130
+
131
+ it "should fall back to stat when trying to lstat a file" do
132
+ Puppet::Util::Windows::File.expects(:stat).with(file.path)
133
+
134
+ file.lstat
135
+ end
136
+ end
137
+
138
+ describe "symlink", :if => Puppet.features.manages_symlinks? do
139
+
140
+ let (:file) { Puppet::FileSystem::File.new(tmpfile("somefile")) }
141
+ let (:missing_file) { Puppet::FileSystem::File.new(tmpfile("missingfile")) }
142
+ let (:dir) { Puppet::FileSystem::File.new(tmpdir("somedir")) }
143
+
144
+ before :each do
145
+ FileUtils.touch(file.path)
146
+ end
147
+
148
+ it "should return true for exist? on a present file" do
149
+ file.exist?.should be_true
150
+ Puppet::FileSystem::File.exist?(file.path).should be_true
151
+ end
152
+
153
+ it "should return false for exist? on a non-existant file" do
154
+ missing_file.exist?.should be_false
155
+ Puppet::FileSystem::File.exist?(missing_file.path).should be_false
156
+ end
157
+
158
+ it "should return true for exist? on a present directory" do
159
+ dir.exist?.should be_true
160
+ Puppet::FileSystem::File.exist?(dir.path).should be_true
161
+ end
162
+
163
+ it "should return false for exist? on a dangling symlink" do
164
+ symlink = Puppet::FileSystem::File.new(tmpfile("somefile_link"))
165
+ missing_file.symlink(symlink.path)
166
+
167
+ missing_file.exist?.should be_false
168
+ symlink.exist?.should be_false
169
+ end
170
+
171
+ it "should return true for exist? on valid symlinks" do
172
+ [file, dir].each do |target|
173
+ symlink = Puppet::FileSystem::File.new(tmpfile("#{target.path.basename.to_s}_link"))
174
+ target.symlink(symlink.path)
175
+
176
+ target.exist?.should be_true
177
+ symlink.exist?.should be_true
178
+ end
179
+ end
180
+
181
+ it "should not create a symlink when the :noop option is specified" do
182
+ [file, dir].each do |target|
183
+ symlink = Puppet::FileSystem::File.new(tmpfile("#{target.path.basename.to_s}_link"))
184
+ target.symlink(symlink.path, { :noop => true })
185
+
186
+ target.exist?.should be_true
187
+ symlink.exist?.should be_false
188
+ end
189
+ end
190
+
191
+ it "should raise Errno::EEXIST if trying to create a file / directory symlink when the symlink path already exists as a file" do
192
+ existing_file = Puppet::FileSystem::File.new(tmpfile("#{file.path.basename.to_s}_link"))
193
+ FileUtils.touch(existing_file.path)
194
+
195
+ [file, dir].each do |target|
196
+ expect { target.symlink(existing_file.path) }.to raise_error(Errno::EEXIST)
197
+
198
+ existing_file.exist?.should be_true
199
+ existing_file.symlink?.should be_false
200
+ end
201
+ end
202
+
203
+ it "should silently fail if trying to create a file / directory symlink when the symlink path already exists as a directory" do
204
+ existing_dir = Puppet::FileSystem::File.new(tmpdir("#{file.path.basename.to_s}_dir"))
205
+
206
+ [file, dir].each do |target|
207
+ target.symlink(existing_dir.path).should == 0
208
+
209
+ existing_dir.exist?.should be_true
210
+ File.directory?(existing_dir.path).should be_true
211
+ existing_dir.symlink?.should be_false
212
+ end
213
+ end
214
+
215
+ it "should silently fail to modify an existing directory symlink to reference a new file or directory" do
216
+ [file, dir].each do |target|
217
+ existing_dir = Puppet::FileSystem::File.new(tmpdir("#{target.path.basename.to_s}_dir"))
218
+ symlink = Puppet::FileSystem::File.new(tmpfile("#{existing_dir.path.basename.to_s}_link"))
219
+ existing_dir.symlink(symlink.path)
220
+
221
+ symlink.readlink.should == existing_dir.path.to_s
222
+
223
+ # now try to point it at the new target, no error raised, but file system unchanged
224
+ target.symlink(symlink.path).should == 0
225
+ symlink.readlink.should == existing_dir.path.to_s
226
+ end
227
+ end
228
+
229
+ it "should raise Errno::EEXIST if trying to modify a file symlink to reference a new file or directory" do
230
+ symlink = Puppet::FileSystem::File.new(tmpfile("#{file.path.basename.to_s}_link"))
231
+ file_2 = Puppet::FileSystem::File.new(tmpfile("#{file.path.basename.to_s}_2"))
232
+ FileUtils.touch(file_2.path)
233
+ # symlink -> file_2
234
+ file_2.symlink(symlink.path)
235
+
236
+ [file, dir].each do |target|
237
+ expect { target.symlink(symlink.path) }.to raise_error(Errno::EEXIST)
238
+ symlink.readlink.should == file_2.path.to_s
239
+ end
240
+ end
241
+
242
+ it "should delete the existing file when creating a file / directory symlink with :force when the symlink path exists as a file" do
243
+ [file, dir].each do |target|
244
+ existing_file = Puppet::FileSystem::File.new(tmpfile("#{target.path.basename.to_s}_existing"))
245
+ FileUtils.touch(existing_file.path)
246
+ existing_file.symlink?.should be_false
247
+
248
+ target.symlink(existing_file.path, { :force => true })
249
+
250
+ existing_file.symlink?.should be_true
251
+ existing_file.readlink.should == target.path.to_s
252
+ end
253
+ end
254
+
255
+ it "should modify an existing file symlink when using :force to reference a new file or directory" do
256
+ [file, dir].each do |target|
257
+ existing_file = Puppet::FileSystem::File.new(tmpfile("#{target.path.basename.to_s}_existing"))
258
+ FileUtils.touch(existing_file.path)
259
+ existing_symlink = Puppet::FileSystem::File.new(tmpfile("#{existing_file.path.basename.to_s}_link"))
260
+ existing_file.symlink(existing_symlink.path)
261
+
262
+ existing_symlink.readlink.should == existing_file.path.to_s
263
+
264
+ target.symlink(existing_symlink.path, { :force => true })
265
+
266
+ existing_symlink.readlink.should == target.path.to_s
267
+ end
268
+ end
269
+
270
+ it "should silently fail if trying to overwrite an existing directory with a new symlink when using :force to reference a file or directory" do
271
+ [file, dir].each do |target|
272
+ existing_dir = Puppet::FileSystem::File.new(tmpdir("#{target.path.basename.to_s}_existing"))
273
+
274
+ target.symlink(existing_dir.path, { :force => true }).should == 0
275
+
276
+ existing_dir.symlink?.should be_false
277
+ end
278
+ end
279
+
280
+ it "should silently fail if trying to modify an existing directory symlink when using :force to reference a new file or directory" do
281
+ [file, dir].each do |target|
282
+ existing_dir = Puppet::FileSystem::File.new(tmpdir("#{target.path.basename.to_s}_existing"))
283
+ existing_symlink = Puppet::FileSystem::File.new(tmpfile("#{existing_dir.path.basename.to_s}_link"))
284
+ existing_dir.symlink(existing_symlink.path)
285
+
286
+ existing_symlink.readlink.should == existing_dir.path.to_s
287
+
288
+ target.symlink(existing_symlink.path, { :force => true }).should == 0
289
+
290
+ existing_symlink.readlink.should == existing_dir.path.to_s
291
+ end
292
+ end
293
+
294
+ it "should accept a string, Pathname or object with to_str (Puppet::Util::WatchedFile) for exist?" do
295
+ [ tmpfile('bogus1'),
296
+ Pathname.new(tmpfile('bogus2')),
297
+ Puppet::Util::WatchedFile.new(tmpfile('bogus3'))
298
+ ].each { |f| Puppet::FileSystem::File.exist?(f).should be_false }
299
+ end
300
+
301
+ it "should return a File::Stat instance when calling stat on an existing file" do
302
+ file.stat.should be_instance_of(File::Stat)
303
+ end
304
+
305
+ it "should raise Errno::ENOENT when calling stat on a missing file" do
306
+ expect { missing_file.stat }.to raise_error(Errno::ENOENT)
307
+ end
308
+
309
+ it "should be able to create a symlink, and verify it with symlink?" do
310
+ symlink = Puppet::FileSystem::File.new(tmpfile("somefile_link"))
311
+ file.symlink(symlink.path)
312
+
313
+ symlink.symlink?.should be_true
314
+ end
315
+
316
+ it "should report symlink? as false on file, directory and missing files" do
317
+ [file, dir, missing_file].each do |f|
318
+ f.symlink?.should be_false
319
+ end
320
+ end
321
+
322
+ it "should return a File::Stat with ftype 'link' when calling lstat on a symlink pointing to existing file" do
323
+ symlink = Puppet::FileSystem::File.new(tmpfile("somefile_link"))
324
+ file.symlink(symlink.path)
325
+
326
+ stat = symlink.lstat
327
+ stat.should be_instance_of(File::Stat)
328
+ stat.ftype.should == 'link'
329
+ end
330
+
331
+ it "should return a File::Stat of ftype 'link' when calling lstat on a symlink pointing to missing file" do
332
+ symlink = Puppet::FileSystem::File.new(tmpfile("somefile_link"))
333
+ missing_file.symlink(symlink.path)
334
+
335
+ stat = symlink.lstat
336
+ stat.should be_instance_of(File::Stat)
337
+ stat.ftype.should == 'link'
338
+ end
339
+
340
+ it "should return a File::Stat of ftype 'file' when calling stat on a symlink pointing to existing file" do
341
+ symlink = Puppet::FileSystem::File.new(tmpfile("somefile_link"))
342
+ file.symlink(symlink.path)
343
+
344
+ stat = symlink.stat
345
+ stat.should be_instance_of(File::Stat)
346
+ stat.ftype.should == 'file'
347
+ end
348
+
349
+ it "should return a File::Stat of ftype 'directory' when calling stat on a symlink pointing to existing directory" do
350
+ symlink = Puppet::FileSystem::File.new(tmpfile("somefile_link"))
351
+ dir.symlink(symlink.path)
352
+
353
+ stat = symlink.stat
354
+ stat.should be_instance_of(File::Stat)
355
+ stat.ftype.should == 'directory'
356
+ end
357
+
358
+ it "should return a File::Stat of ftype 'file' when calling stat on a symlink pointing to another symlink" do
359
+ # point symlink -> file
360
+ symlink = Puppet::FileSystem::File.new(tmpfile("somefile_link"))
361
+ file.symlink(symlink.path)
362
+
363
+ # point symlink2 -> symlink
364
+ symlink2 = Puppet::FileSystem::File.new(tmpfile("somefile_link2"))
365
+ symlink.symlink(symlink2.path)
366
+
367
+ symlink2.stat.ftype.should == 'file'
368
+ end
369
+
370
+
371
+ it "should raise Errno::ENOENT when calling stat on a dangling symlink" do
372
+ symlink = Puppet::FileSystem::File.new(tmpfile("somefile_link"))
373
+ missing_file.symlink(symlink.path)
374
+
375
+ expect { symlink.stat }.to raise_error(Errno::ENOENT)
376
+ end
377
+
378
+ it "should be able to readlink to resolve the physical path to a symlink" do
379
+ symlink = Puppet::FileSystem::File.new(tmpfile("somefile_link"))
380
+ file.symlink(symlink.path)
381
+
382
+ file.exist?.should be_true
383
+ symlink.readlink.should == file.path.to_s
384
+ end
385
+
386
+ it "should not resolve entire symlink chain with readlink on a symlink'd symlink" do
387
+ # point symlink -> file
388
+ symlink = Puppet::FileSystem::File.new(tmpfile("somefile_link"))
389
+ file.symlink(symlink.path)
390
+
391
+ # point symlink2 -> symlink
392
+ symlink2 = Puppet::FileSystem::File.new(tmpfile("somefile_link2"))
393
+ symlink.symlink(symlink2.path)
394
+
395
+ file.exist?.should be_true
396
+ symlink2.readlink.should == symlink.path.to_s
397
+ end
398
+
399
+ it "should be able to readlink to resolve the physical path to a dangling symlink" do
400
+ symlink = Puppet::FileSystem::File.new(tmpfile("somefile_link"))
401
+ missing_file.symlink(symlink.path)
402
+
403
+ missing_file.exist?.should be_false
404
+ symlink.readlink.should == missing_file.path.to_s
405
+ end
406
+
407
+ it "should delete only the symlink and not the target when calling unlink instance method" do
408
+ [file, dir].each do |target|
409
+ symlink = Puppet::FileSystem::File.new(tmpfile("#{target.path.basename.to_s}_link"))
410
+ target.symlink(symlink.path)
411
+
412
+ target.exist?.should be_true
413
+ symlink.readlink.should == target.path.to_s
414
+
415
+ symlink.unlink.should == 1 # count of files
416
+
417
+ target.exist?.should be_true
418
+ symlink.exist?.should be_false
419
+ end
420
+ end
421
+
422
+ it "should delete only the symlink and not the target when calling unlink class method" do
423
+ [file, dir].each do |target|
424
+ symlink = Puppet::FileSystem::File.new(tmpfile("#{target.path.basename.to_s}_link"))
425
+ target.symlink(symlink.path)
426
+
427
+ target.exist?.should be_true
428
+ symlink.readlink.should == target.path.to_s
429
+
430
+ Puppet::FileSystem::File.unlink(symlink.path).should == 1 # count of files
431
+
432
+ target.exist?.should be_true
433
+ symlink.exist?.should be_false
434
+ end
435
+ end
436
+
437
+ describe "unlink" do
438
+ it "should delete files with unlink" do
439
+ file.exist?.should be_true
440
+
441
+ file.unlink.should == 1 # count of files
442
+
443
+ file.exist?.should be_false
444
+ end
445
+
446
+ it "should delete files with unlink class method" do
447
+ file.exist?.should be_true
448
+
449
+ Puppet::FileSystem::File.unlink(file.path).should == 1 # count of files
450
+
451
+ file.exist?.should be_false
452
+ end
453
+
454
+ it "should delete multiple files with unlink class method" do
455
+ paths = (1..3).collect do |i|
456
+ f = Puppet::FileSystem::File.new(tmpfile("somefile_#{i}"))
457
+ FileUtils.touch(f.path)
458
+ f.exist?.should be_true
459
+ f.path.to_s
460
+ end
461
+
462
+ Puppet::FileSystem::File.unlink(*paths).should == 3 # count of files
463
+
464
+ paths.each { |p| Puppet::FileSystem::File.exist?(p).should be_false }
465
+ end
466
+
467
+ it "should raise Errno::EPERM or Errno::EISDIR when trying to delete a directory with the unlink class method" do
468
+ dir.exist?.should be_true
469
+
470
+ ex = nil
471
+ begin
472
+ Puppet::FileSystem::File.unlink(dir.path)
473
+ rescue Exception => e
474
+ ex = e
475
+ end
476
+
477
+ [
478
+ Errno::EPERM, # Windows and OSX
479
+ Errno::EISDIR # Linux
480
+ ].should include ex.class
481
+
482
+ dir.exist?.should be_true
483
+ end
484
+ end
485
+ end
486
+ end