puppet 2.7.11 → 2.7.12

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 (220) hide show
  1. data/CHANGELOG +188 -0
  2. data/conf/osx/createpackage.sh +1 -0
  3. data/conf/redhat/puppet.spec +12 -9
  4. data/conf/suse/puppet.spec +4 -1
  5. data/install.rb +9 -22
  6. data/lib/puppet.rb +1 -31
  7. data/lib/puppet/agent.rb +3 -5
  8. data/lib/puppet/agent/locker.rb +15 -1
  9. data/lib/puppet/application.rb +7 -4
  10. data/lib/puppet/application/agent.rb +4 -25
  11. data/lib/puppet/application/apply.rb +3 -3
  12. data/lib/puppet/application/device.rb +2 -16
  13. data/lib/puppet/application/doc.rb +2 -2
  14. data/lib/puppet/application/face_base.rb +22 -5
  15. data/lib/puppet/application/filebucket.rb +2 -0
  16. data/lib/puppet/application/inspect.rb +2 -1
  17. data/lib/puppet/application/kick.rb +25 -9
  18. data/lib/puppet/application/queue.rb +0 -23
  19. data/lib/puppet/configurer.rb +1 -0
  20. data/lib/puppet/configurer/downloader.rb +7 -3
  21. data/lib/puppet/defaults.rb +34 -29
  22. data/lib/puppet/face/ca.rb +1 -1
  23. data/lib/puppet/face/catalog.rb +1 -0
  24. data/lib/puppet/face/file/store.rb +1 -1
  25. data/lib/puppet/face/module/list.rb +23 -3
  26. data/lib/puppet/face/module/search.rb +21 -32
  27. data/lib/puppet/face/module/uninstall.rb +56 -15
  28. data/lib/puppet/file_bucket/dipper.rb +2 -2
  29. data/lib/puppet/file_serving/base.rb +6 -5
  30. data/lib/puppet/file_serving/configuration/parser.rb +1 -1
  31. data/lib/puppet/file_serving/content.rb +1 -1
  32. data/lib/puppet/forge.rb +153 -0
  33. data/lib/puppet/{module_tool → forge}/cache.rb +1 -2
  34. data/lib/puppet/{module_tool → forge}/repository.rb +46 -4
  35. data/lib/puppet/indirector/exec.rb +1 -1
  36. data/lib/puppet/indirector/file_bucket_file/file.rb +3 -3
  37. data/lib/puppet/interface/action.rb +6 -2
  38. data/lib/puppet/module.rb +70 -10
  39. data/lib/puppet/module_tool.rb +2 -38
  40. data/lib/puppet/module_tool/applications.rb +15 -11
  41. data/lib/puppet/module_tool/applications/application.rb +2 -5
  42. data/lib/puppet/module_tool/applications/cleaner.rb +1 -1
  43. data/lib/puppet/module_tool/applications/installer.rb +10 -45
  44. data/lib/puppet/module_tool/applications/searcher.rb +2 -26
  45. data/lib/puppet/module_tool/applications/uninstaller.rb +39 -13
  46. data/lib/puppet/module_tool/applications/unpacker.rb +1 -1
  47. data/lib/puppet/module_tool/dependency.rb +1 -1
  48. data/lib/puppet/network/authconfig.rb +1 -1
  49. data/lib/puppet/network/handler/fileserver.rb +1 -1
  50. data/lib/puppet/network/http/handler.rb +4 -1
  51. data/lib/puppet/network/http/webrick.rb +4 -2
  52. data/lib/puppet/node/environment.rb +32 -6
  53. data/lib/puppet/parameter/path.rb +0 -4
  54. data/lib/puppet/parser/ast/relationship.rb +3 -16
  55. data/lib/puppet/parser/collector.rb +5 -3
  56. data/lib/puppet/parser/compiler.rb +2 -1
  57. data/lib/puppet/parser/functions/file.rb +1 -1
  58. data/lib/puppet/parser/functions/generate.rb +8 -2
  59. data/lib/puppet/parser/grammar.ra +16 -15
  60. data/lib/puppet/parser/parser.rb +959 -881
  61. data/lib/puppet/parser/relationship.rb +32 -15
  62. data/lib/puppet/parser/resource.rb +0 -1
  63. data/lib/puppet/parser/type_loader.rb +1 -2
  64. data/lib/puppet/provider/augeas/augeas.rb +17 -29
  65. data/lib/puppet/provider/exec/windows.rb +25 -3
  66. data/lib/puppet/provider/file/posix.rb +1 -1
  67. data/lib/puppet/provider/file/windows.rb +1 -1
  68. data/lib/puppet/provider/group/windows_adsi.rb +1 -1
  69. data/lib/puppet/provider/package/aix.rb +1 -1
  70. data/lib/puppet/provider/package/appdmg.rb +1 -1
  71. data/lib/puppet/provider/package/dpkg.rb +1 -1
  72. data/lib/puppet/provider/package/gem.rb +21 -23
  73. data/lib/puppet/provider/package/macports.rb +1 -1
  74. data/lib/puppet/provider/package/msi.rb +7 -1
  75. data/lib/puppet/provider/package/openbsd.rb +13 -16
  76. data/lib/puppet/provider/package/pacman.rb +1 -1
  77. data/lib/puppet/provider/package/pip.rb +3 -0
  78. data/lib/puppet/provider/package/pkg.rb +1 -1
  79. data/lib/puppet/provider/package/pkgdmg.rb +1 -1
  80. data/lib/puppet/provider/package/pkgutil.rb +1 -1
  81. data/lib/puppet/provider/package/portage.rb +2 -2
  82. data/lib/puppet/provider/package/rpm.rb +1 -1
  83. data/lib/puppet/provider/package/sun.rb +1 -1
  84. data/lib/puppet/provider/package/zypper.rb +35 -3
  85. data/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb +6 -2
  86. data/lib/puppet/provider/selmodule/semodule.rb +2 -2
  87. data/lib/puppet/provider/service/base.rb +1 -1
  88. data/lib/puppet/provider/service/launchd.rb +4 -0
  89. data/lib/puppet/provider/service/src.rb +2 -2
  90. data/lib/puppet/provider/service/upstart.rb +1 -1
  91. data/lib/puppet/provider/service/windows.rb +5 -4
  92. data/lib/puppet/provider/user/aix.rb +3 -3
  93. data/lib/puppet/provider/user/pw.rb +6 -0
  94. data/lib/puppet/provider/user/windows_adsi.rb +1 -1
  95. data/lib/puppet/resource/catalog.rb +6 -6
  96. data/lib/puppet/resource/type.rb +2 -0
  97. data/lib/puppet/ssl/certificate_request.rb +0 -70
  98. data/lib/puppet/transaction.rb +1 -1
  99. data/lib/puppet/transaction/report.rb +3 -2
  100. data/lib/puppet/type.rb +1 -1
  101. data/lib/puppet/type/cron.rb +5 -2
  102. data/lib/puppet/type/exec.rb +8 -0
  103. data/lib/puppet/type/file.rb +27 -18
  104. data/lib/puppet/type/file/checksum.rb +2 -2
  105. data/lib/puppet/type/file/content.rb +14 -9
  106. data/lib/puppet/type/file/ensure.rb +5 -4
  107. data/lib/puppet/type/file/group.rb +10 -2
  108. data/lib/puppet/type/file/mode.rb +46 -18
  109. data/lib/puppet/type/file/owner.rb +10 -2
  110. data/lib/puppet/type/file/source.rb +27 -40
  111. data/lib/puppet/type/file/target.rb +6 -6
  112. data/lib/puppet/type/group.rb +13 -9
  113. data/lib/puppet/type/k5login.rb +1 -1
  114. data/lib/puppet/type/package.rb +24 -8
  115. data/lib/puppet/type/scheduled_task.rb +77 -131
  116. data/lib/puppet/type/service.rb +22 -8
  117. data/lib/puppet/type/user.rb +29 -9
  118. data/lib/puppet/util.rb +24 -33
  119. data/lib/puppet/util/colors.rb +98 -0
  120. data/lib/puppet/util/diff.rb +3 -1
  121. data/lib/puppet/util/log.rb +5 -1
  122. data/lib/puppet/util/log/destinations.rb +37 -44
  123. data/lib/puppet/util/monkey_patches.rb +32 -0
  124. data/lib/puppet/util/pidlock.rb +70 -21
  125. data/lib/puppet/util/rdoc/parser.rb +4 -2
  126. data/lib/puppet/util/selinux.rb +1 -1
  127. data/lib/puppet/util/suidmanager.rb +2 -12
  128. data/lib/puppet/util/windows.rb +2 -0
  129. data/lib/puppet/util/windows/process.rb +33 -0
  130. data/lib/puppet/util/windows/security.rb +6 -4
  131. data/lib/puppet/util/windows/user.rb +44 -0
  132. data/lib/semver.rb +55 -4
  133. data/spec/fixtures/unit/provider/package/openbsd/pkginfo.detail +19 -0
  134. data/spec/fixtures/unit/provider/package/openbsd/pkginfo.list +10 -0
  135. data/spec/fixtures/unit/provider/package/openbsd/pkginfo.query +1 -0
  136. data/spec/fixtures/unit/provider/package/zypper/zypper-list-updates-SLES11sp1.out +369 -0
  137. data/spec/integration/defaults_spec.rb +10 -0
  138. data/spec/integration/indirector/direct_file_server_spec.rb +1 -1
  139. data/spec/integration/module_tool_spec.rb +10 -12
  140. data/spec/integration/parser/compiler_spec.rb +147 -0
  141. data/spec/integration/type/file_spec.rb +1 -1
  142. data/spec/integration/util/windows/user_spec.rb +59 -0
  143. data/spec/lib/puppet/face/basetest.rb +5 -0
  144. data/spec/lib/puppet_spec/modules.rb +26 -0
  145. data/spec/spec_helper.rb +25 -0
  146. data/spec/unit/agent/locker_spec.rb +12 -0
  147. data/spec/unit/agent_backward_compatibility_spec.rb +152 -0
  148. data/spec/unit/agent_spec.rb +28 -8
  149. data/spec/unit/application/agent_spec.rb +4 -36
  150. data/spec/unit/application/device_spec.rb +55 -10
  151. data/spec/unit/application/face_base_spec.rb +32 -10
  152. data/spec/unit/application/filebucket_spec.rb +5 -0
  153. data/spec/unit/application/kick_spec.rb +6 -0
  154. data/spec/unit/application_spec.rb +8 -1
  155. data/spec/unit/configurer/downloader_spec.rb +4 -5
  156. data/spec/unit/face/ca_spec.rb +15 -4
  157. data/spec/unit/file_bucket/dipper_spec.rb +1 -1
  158. data/spec/unit/file_serving/base_spec.rb +60 -42
  159. data/spec/unit/file_serving/configuration/parser_spec.rb +5 -3
  160. data/spec/unit/file_serving/content_spec.rb +26 -27
  161. data/spec/unit/file_serving/metadata_spec.rb +22 -21
  162. data/spec/unit/forge/repository_spec.rb +86 -0
  163. data/spec/unit/forge_spec.rb +114 -0
  164. data/spec/unit/indirector/exec_spec.rb +8 -6
  165. data/spec/unit/indirector/facts/inventory_active_record_spec.rb +0 -1
  166. data/spec/unit/indirector/file_bucket_file/file_spec.rb +1 -1
  167. data/spec/unit/indirector/node/exec_spec.rb +1 -1
  168. data/spec/unit/indirector/resource/active_record_spec.rb +0 -4
  169. data/spec/unit/interface/action_builder_spec.rb +7 -5
  170. data/spec/unit/module_spec.rb +228 -9
  171. data/spec/unit/module_tool/application_spec.rb +3 -3
  172. data/spec/unit/module_tool/uninstaller_spec.rb +107 -27
  173. data/spec/unit/module_tool_spec.rb +0 -33
  174. data/spec/unit/network/authconfig_spec.rb +22 -21
  175. data/spec/unit/network/http/webrick_spec.rb +13 -9
  176. data/spec/unit/node/environment_spec.rb +159 -66
  177. data/spec/unit/parser/collector_spec.rb +16 -8
  178. data/spec/unit/parser/functions/generate_spec.rb +60 -18
  179. data/spec/unit/parser/resource_spec.rb +44 -0
  180. data/spec/unit/provider/augeas/augeas_spec.rb +160 -179
  181. data/spec/unit/provider/confine/feature_spec.rb +3 -5
  182. data/spec/unit/provider/package/dpkg_spec.rb +4 -2
  183. data/spec/unit/provider/package/gem_spec.rb +59 -43
  184. data/spec/unit/provider/package/openbsd_spec.rb +114 -0
  185. data/spec/unit/provider/package/pacman_spec.rb +1 -1
  186. data/spec/unit/provider/package/pip_spec.rb +10 -4
  187. data/spec/unit/provider/package/zypper_spec.rb +56 -14
  188. data/spec/unit/provider/selmodule_spec.rb +3 -3
  189. data/spec/unit/provider/service/launchd_spec.rb +22 -21
  190. data/spec/unit/provider/service/{upstart.rb → upstart_spec.rb} +7 -3
  191. data/spec/unit/provider/user/pw_spec.rb +19 -0
  192. data/spec/unit/resource/catalog_spec.rb +3 -3
  193. data/spec/unit/semver_spec.rb +117 -24
  194. data/spec/unit/transaction/report_spec.rb +11 -1
  195. data/spec/unit/type/cron_spec.rb +200 -213
  196. data/spec/unit/type/exec_spec.rb +7 -0
  197. data/spec/unit/type/file/content_spec.rb +2 -2
  198. data/spec/unit/type/file_spec.rb +12 -9
  199. data/spec/unit/type/package_spec.rb +25 -0
  200. data/spec/unit/type/schedule_spec.rb +31 -31
  201. data/spec/unit/util/diff_spec.rb +30 -0
  202. data/spec/unit/util/execution_stub_spec.rb +1 -2
  203. data/spec/unit/util/log/destinations_spec.rb +51 -0
  204. data/spec/unit/util/log_spec.rb +17 -1
  205. data/spec/unit/util/monkey_patches_spec.rb +119 -0
  206. data/spec/unit/util/rdoc/parser_spec.rb +25 -1
  207. data/spec/unit/util/selinux_spec.rb +2 -2
  208. data/spec/unit/util/suidmanager_spec.rb +6 -51
  209. data/spec/unit/util_spec.rb +82 -24
  210. data/test/lib/puppettest/certificates.rb +16 -0
  211. data/test/lib/puppettest/servertest.rb +4 -0
  212. data/test/util/pidlock.rb +125 -0
  213. metadata +23 -14
  214. data/ext/puppetstoredconfigclean.rb +0 -103
  215. data/lib/puppet/agent/disabler.rb +0 -27
  216. data/lib/puppet/util/anonymous_filelock.rb +0 -36
  217. data/spec/unit/agent/disabler_spec.rb +0 -60
  218. data/spec/unit/module_tool/repository_spec.rb +0 -52
  219. data/spec/unit/util/anonymous_filelock_spec.rb +0 -78
  220. data/spec/unit/util/pidlock_spec.rb +0 -208
@@ -4,8 +4,11 @@ require 'spec_helper'
4
4
  require 'puppet/file_serving/base'
5
5
 
6
6
  describe Puppet::FileServing::Base do
7
+ let(:path) { File.expand_path('/module/dir/file') }
8
+ let(:file) { File.expand_path('/my/file') }
9
+
7
10
  it "should accept a path" do
8
- Puppet::FileServing::Base.new("/module/dir/file").path.should == "/module/dir/file"
11
+ Puppet::FileServing::Base.new(path).path.should == path
9
12
  end
10
13
 
11
14
  it "should require that paths be fully qualified" do
@@ -13,119 +16,134 @@ describe Puppet::FileServing::Base do
13
16
  end
14
17
 
15
18
  it "should allow specification of whether links should be managed" do
16
- Puppet::FileServing::Base.new("/module/dir/file", :links => :manage).links.should == :manage
19
+ Puppet::FileServing::Base.new(path, :links => :manage).links.should == :manage
17
20
  end
18
21
 
19
22
  it "should have a :source attribute" do
20
- file = Puppet::FileServing::Base.new("/module/dir/file")
23
+ file = Puppet::FileServing::Base.new(path)
21
24
  file.should respond_to(:source)
22
25
  file.should respond_to(:source=)
23
26
  end
24
27
 
25
28
  it "should consider :ignore links equivalent to :manage links" do
26
- Puppet::FileServing::Base.new("/module/dir/file", :links => :ignore).links.should == :manage
29
+ Puppet::FileServing::Base.new(path, :links => :ignore).links.should == :manage
27
30
  end
28
31
 
29
32
  it "should fail if :links is set to anything other than :manage, :follow, or :ignore" do
30
- proc { Puppet::FileServing::Base.new("/module/dir/file", :links => :else) }.should raise_error(ArgumentError)
33
+ proc { Puppet::FileServing::Base.new(path, :links => :else) }.should raise_error(ArgumentError)
31
34
  end
32
35
 
33
36
  it "should allow links values to be set as strings" do
34
- Puppet::FileServing::Base.new("/module/dir/file", :links => "follow").links.should == :follow
37
+ Puppet::FileServing::Base.new(path, :links => "follow").links.should == :follow
35
38
  end
36
39
 
37
40
  it "should default to :manage for :links" do
38
- Puppet::FileServing::Base.new("/module/dir/file").links.should == :manage
41
+ Puppet::FileServing::Base.new(path).links.should == :manage
39
42
  end
40
43
 
41
44
  it "should allow specification of a path" do
42
45
  FileTest.stubs(:exists?).returns(true)
43
- Puppet::FileServing::Base.new("/module/dir/file", :path => "/my/file").path.should == "/my/file"
46
+ Puppet::FileServing::Base.new(path, :path => file).path.should == file
44
47
  end
45
48
 
46
49
  it "should allow specification of a relative path" do
47
50
  FileTest.stubs(:exists?).returns(true)
48
- Puppet::FileServing::Base.new("/module/dir/file", :relative_path => "my/file").relative_path.should == "my/file"
51
+ Puppet::FileServing::Base.new(path, :relative_path => "my/file").relative_path.should == "my/file"
49
52
  end
50
53
 
51
54
  it "should have a means of determining if the file exists" do
52
- Puppet::FileServing::Base.new("/blah").should respond_to(:exist?)
55
+ Puppet::FileServing::Base.new(file).should respond_to(:exist?)
53
56
  end
54
57
 
55
58
  it "should correctly indicate if the file is present" do
56
- File.expects(:lstat).with("/my/file").returns(mock("stat"))
57
- Puppet::FileServing::Base.new("/my/file").exist?.should be_true
59
+ File.expects(:lstat).with(file).returns(mock("stat"))
60
+ Puppet::FileServing::Base.new(file).exist?.should be_true
58
61
  end
59
62
 
60
63
  it "should correctly indicate if the file is absent" do
61
- File.expects(:lstat).with("/my/file").raises RuntimeError
62
- Puppet::FileServing::Base.new("/my/file").exist?.should be_false
64
+ File.expects(:lstat).with(file).raises RuntimeError
65
+ Puppet::FileServing::Base.new(file).exist?.should be_false
63
66
  end
64
67
 
65
68
  describe "when setting the relative path" do
66
69
  it "should require that the relative path be unqualified" do
67
- @file = Puppet::FileServing::Base.new("/module/dir/file")
70
+ @file = Puppet::FileServing::Base.new(path)
68
71
  FileTest.stubs(:exists?).returns(true)
69
- proc { @file.relative_path = "/qualified/file" }.should raise_error(ArgumentError)
72
+ proc { @file.relative_path = File.expand_path("/qualified/file") }.should raise_error(ArgumentError)
70
73
  end
71
74
  end
72
75
 
73
76
  describe "when determining the full file path" do
74
- before do
75
- @file = Puppet::FileServing::Base.new("/this/file")
76
- end
77
+ let(:path) { File.expand_path('/this/file') }
78
+ let(:file) { Puppet::FileServing::Base.new(path) }
77
79
 
78
80
  it "should return the path if there is no relative path" do
79
- @file.full_path.should == "/this/file"
81
+ file.full_path.should == path
80
82
  end
81
83
 
82
84
  it "should return the path if the relative_path is set to ''" do
83
- @file.relative_path = ""
84
- @file.full_path.should == "/this/file"
85
+ file.relative_path = ""
86
+ file.full_path.should == path
85
87
  end
86
88
 
87
89
  it "should return the path if the relative_path is set to '.'" do
88
- @file.relative_path = "."
89
- @file.full_path.should == "/this/file"
90
+ file.relative_path = "."
91
+ file.full_path.should == path
90
92
  end
91
93
 
92
94
  it "should return the path joined with the relative path if there is a relative path and it is not set to '/' or ''" do
93
- @file.relative_path = "not/qualified"
94
- @file.full_path.should == "/this/file/not/qualified"
95
+ file.relative_path = "not/qualified"
96
+ file.full_path.should == File.join(path, "not/qualified")
95
97
  end
96
98
 
97
99
  it "should strip extra slashes" do
98
- file = Puppet::FileServing::Base.new("//this//file")
99
- file.full_path.should == "/this/file"
100
+ file = Puppet::FileServing::Base.new(File.join(File.expand_path('/'), "//this//file"))
101
+ file.full_path.should == path
100
102
  end
101
103
  end
102
104
 
103
105
  describe "when stat'ing files" do
104
- before do
105
- @file = Puppet::FileServing::Base.new("/this/file")
106
- end
106
+ let(:path) { File.expand_path('/this/file') }
107
+ let(:file) { Puppet::FileServing::Base.new(path) }
107
108
 
108
109
  it "should stat the file's full path" do
109
- @file.stubs(:full_path).returns("/this/file")
110
- File.expects(:lstat).with("/this/file").returns stub("stat", :ftype => "file")
111
- @file.stat
110
+ File.expects(:lstat).with(path).returns stub("stat", :ftype => "file")
111
+ file.stat
112
112
  end
113
113
 
114
114
  it "should fail if the file does not exist" do
115
- @file.stubs(:full_path).returns("/this/file")
116
- File.expects(:lstat).with("/this/file").raises(Errno::ENOENT)
117
- proc { @file.stat }.should raise_error(Errno::ENOENT)
115
+ File.expects(:lstat).with(path).raises(Errno::ENOENT)
116
+ proc { file.stat }.should raise_error(Errno::ENOENT)
118
117
  end
119
118
 
120
119
  it "should use :lstat if :links is set to :manage" do
121
- File.expects(:lstat).with("/this/file").returns stub("stat", :ftype => "file")
122
- @file.stat
120
+ File.expects(:lstat).with(path).returns stub("stat", :ftype => "file")
121
+ file.stat
123
122
  end
124
123
 
125
124
  it "should use :stat if :links is set to :follow" do
126
- File.expects(:stat).with("/this/file").returns stub("stat", :ftype => "file")
127
- @file.links = :follow
128
- @file.stat
125
+ File.expects(:stat).with(path).returns stub("stat", :ftype => "file")
126
+ file.links = :follow
127
+ file.stat
128
+ end
129
+ end
130
+
131
+ describe "#absolute?" do
132
+ it "should be accept POSIX paths" do
133
+ Puppet::FileServing::Base.should be_absolute('/')
134
+ end
135
+
136
+ it "should accept Windows paths on Windows" do
137
+ Puppet.features.stubs(:microsoft_windows?).returns(true)
138
+ Puppet.features.stubs(:posix?).returns(false)
139
+
140
+ Puppet::FileServing::Base.should be_absolute('c:/foo')
141
+ end
142
+
143
+ it "should reject Windows paths on POSIX" do
144
+ Puppet.features.stubs(:microsoft_windows?).returns(false)
145
+
146
+ Puppet::FileServing::Base.should_not be_absolute('c:/foo')
129
147
  end
130
148
  end
131
149
  end
@@ -14,7 +14,8 @@ module FSConfigurationParserTesting
14
14
  def mock_file_content(content)
15
15
  # We want an array, but we actually want our carriage returns on all of it.
16
16
  lines = content.split("\n").collect { |l| l + "\n" }
17
- @filehandle.stubs(:each).multiple_yields(*lines)
17
+ @filehandle.stubs(:each_line).multiple_yields(*lines)
18
+ @filehandle.expects(:each).never
18
19
  end
19
20
  end
20
21
 
@@ -24,6 +25,7 @@ describe Puppet::FileServing::Configuration::Parser do
24
25
  FileTest.stubs(:exists?).with(@path).returns(true)
25
26
  FileTest.stubs(:readable?).with(@path).returns(true)
26
27
  @filehandle = mock 'filehandle'
28
+ @filehandle.expects(:each).never
27
29
  File.expects(:open).with(@path).yields(@filehandle)
28
30
  @parser = Puppet::FileServing::Configuration::Parser.new(@path)
29
31
  end
@@ -32,12 +34,12 @@ describe Puppet::FileServing::Configuration::Parser do
32
34
  include FSConfigurationParserTesting
33
35
 
34
36
  it "should allow comments" do
35
- @filehandle.expects(:each).yields("# this is a comment\n")
37
+ @filehandle.expects(:each_line).yields("# this is a comment\n")
36
38
  proc { @parser.parse }.should_not raise_error
37
39
  end
38
40
 
39
41
  it "should allow blank lines" do
40
- @filehandle.expects(:each).yields("\n")
42
+ @filehandle.expects(:each_line).yields("\n")
41
43
  proc { @parser.parse }.should_not raise_error
42
44
  end
43
45
 
@@ -4,6 +4,8 @@ require 'spec_helper'
4
4
  require 'puppet/file_serving/content'
5
5
 
6
6
  describe Puppet::FileServing::Content do
7
+ let(:path) { File.expand_path('/path') }
8
+
7
9
  it "should should be a subclass of Base" do
8
10
  Puppet::FileServing::Content.superclass.should equal(Puppet::FileServing::Base)
9
11
  end
@@ -21,38 +23,38 @@ describe Puppet::FileServing::Content do
21
23
  end
22
24
 
23
25
  it "should have a method for collecting its attributes" do
24
- Puppet::FileServing::Content.new("/path").should respond_to(:collect)
26
+ Puppet::FileServing::Content.new(path).should respond_to(:collect)
25
27
  end
26
28
 
27
29
  it "should not retrieve and store its contents when its attributes are collected if the file is a normal file" do
28
- content = Puppet::FileServing::Content.new("/path")
30
+ content = Puppet::FileServing::Content.new(path)
29
31
 
30
32
  result = "foo"
31
33
  File.stubs(:lstat).returns(stub("stat", :ftype => "file"))
32
- File.expects(:read).with("/path").never
34
+ File.expects(:read).with(path).never
33
35
  content.collect
34
36
 
35
37
  content.instance_variable_get("@content").should be_nil
36
38
  end
37
39
 
38
40
  it "should not attempt to retrieve its contents if the file is a directory" do
39
- content = Puppet::FileServing::Content.new("/path")
41
+ content = Puppet::FileServing::Content.new(path)
40
42
 
41
43
  result = "foo"
42
44
  File.stubs(:lstat).returns(stub("stat", :ftype => "directory"))
43
- File.expects(:read).with("/path").never
45
+ File.expects(:read).with(path).never
44
46
  content.collect
45
47
 
46
48
  content.instance_variable_get("@content").should be_nil
47
49
  end
48
50
 
49
51
  it "should have a method for setting its content" do
50
- content = Puppet::FileServing::Content.new("/path")
52
+ content = Puppet::FileServing::Content.new(path)
51
53
  content.should respond_to(:content=)
52
54
  end
53
55
 
54
56
  it "should make content available when set externally" do
55
- content = Puppet::FileServing::Content.new("/path")
57
+ content = Puppet::FileServing::Content.new(path)
56
58
  content.content = "foo/bar"
57
59
  content.content.should == "foo/bar"
58
60
  end
@@ -71,47 +73,44 @@ describe Puppet::FileServing::Content do
71
73
  end
72
74
 
73
75
  it "should return an opened File when converted to raw" do
74
- content = Puppet::FileServing::Content.new("/path")
76
+ content = Puppet::FileServing::Content.new(path)
75
77
 
76
- File.expects(:new).with("/path","rb").returns :file
78
+ File.expects(:new).with(path, "rb").returns :file
77
79
 
78
80
  content.to_raw.should == :file
79
81
  end
80
82
  end
81
83
 
82
84
  describe Puppet::FileServing::Content, "when returning the contents" do
83
- before do
84
- @path = "/my/path"
85
- @content = Puppet::FileServing::Content.new(@path, :links => :follow)
86
- end
85
+ let(:path) { File.expand_path('/my/path') }
86
+ let(:content) { Puppet::FileServing::Content.new(path, :links => :follow) }
87
87
 
88
88
  it "should fail if the file is a symlink and links are set to :manage" do
89
- @content.links = :manage
90
- File.expects(:lstat).with(@path).returns stub("stat", :ftype => "symlink")
91
- proc { @content.content }.should raise_error(ArgumentError)
89
+ content.links = :manage
90
+ File.expects(:lstat).with(path).returns stub("stat", :ftype => "symlink")
91
+ proc { content.content }.should raise_error(ArgumentError)
92
92
  end
93
93
 
94
94
  it "should fail if a path is not set" do
95
- proc { @content.content }.should raise_error(Errno::ENOENT)
95
+ proc { content.content }.should raise_error(Errno::ENOENT)
96
96
  end
97
97
 
98
98
  it "should raise Errno::ENOENT if the file is absent" do
99
- @content.path = "/there/is/absolutely/no/chance/that/this/path/exists"
100
- proc { @content.content }.should raise_error(Errno::ENOENT)
99
+ content.path = File.expand_path("/there/is/absolutely/no/chance/that/this/path/exists")
100
+ proc { content.content }.should raise_error(Errno::ENOENT)
101
101
  end
102
102
 
103
103
  it "should return the contents of the path if the file exists" do
104
- File.expects(:stat).with(@path).returns stub("stat", :ftype => "file")
105
- Puppet::Util.expects(:binread).with(@path).returns(:mycontent)
106
- @content.content.should == :mycontent
104
+ File.expects(:stat).with(path).returns stub("stat", :ftype => "file")
105
+ IO.expects(:binread).with(path).returns(:mycontent)
106
+ content.content.should == :mycontent
107
107
  end
108
108
 
109
109
  it "should cache the returned contents" do
110
- File.expects(:stat).with(@path).returns stub("stat", :ftype => "file")
111
- Puppet::Util.expects(:binread).with(@path).returns(:mycontent)
112
- @content.content
113
-
110
+ File.expects(:stat).with(path).returns stub("stat", :ftype => "file")
111
+ IO.expects(:binread).with(path).returns(:mycontent)
112
+ content.content
114
113
  # The second run would throw a failure if the content weren't being cached.
115
- @content.content
114
+ content.content
116
115
  end
117
116
  end
@@ -4,6 +4,8 @@ require 'spec_helper'
4
4
  require 'puppet/file_serving/metadata'
5
5
 
6
6
  describe Puppet::FileServing::Metadata do
7
+ let(:foobar) { File.expand_path('/foo/bar') }
8
+
7
9
  it "should should be a subclass of Base" do
8
10
  Puppet::FileServing::Metadata.superclass.should equal(Puppet::FileServing::Base)
9
11
  end
@@ -17,15 +19,15 @@ describe Puppet::FileServing::Metadata do
17
19
  end
18
20
 
19
21
  it "should have a method that triggers attribute collection" do
20
- Puppet::FileServing::Metadata.new("/foo/bar").should respond_to(:collect)
22
+ Puppet::FileServing::Metadata.new(foobar).should respond_to(:collect)
21
23
  end
22
24
 
23
25
  it "should support pson serialization" do
24
- Puppet::FileServing::Metadata.new("/foo/bar").should respond_to(:to_pson)
26
+ Puppet::FileServing::Metadata.new(foobar).should respond_to(:to_pson)
25
27
  end
26
28
 
27
29
  it "should support to_pson_data_hash" do
28
- Puppet::FileServing::Metadata.new("/foo/bar").should respond_to(:to_pson_data_hash)
30
+ Puppet::FileServing::Metadata.new(foobar).should respond_to(:to_pson_data_hash)
29
31
  end
30
32
 
31
33
  it "should support pson deserialization" do
@@ -33,67 +35,66 @@ describe Puppet::FileServing::Metadata do
33
35
  end
34
36
 
35
37
  describe "when serializing" do
36
- before do
37
- @metadata = Puppet::FileServing::Metadata.new("/foo/bar")
38
- end
38
+ let(:metadata) { Puppet::FileServing::Metadata.new(foobar) }
39
+
39
40
  it "should perform pson serialization by calling to_pson on it's pson_data_hash" do
40
41
  pdh = mock "data hash"
41
42
  pdh_as_pson = mock "data as pson"
42
- @metadata.expects(:to_pson_data_hash).returns pdh
43
+ metadata.expects(:to_pson_data_hash).returns pdh
43
44
  pdh.expects(:to_pson).returns pdh_as_pson
44
- @metadata.to_pson.should == pdh_as_pson
45
+ metadata.to_pson.should == pdh_as_pson
45
46
  end
46
47
 
47
48
  it "should serialize as FileMetadata" do
48
- @metadata.to_pson_data_hash['document_type'].should == "FileMetadata"
49
+ metadata.to_pson_data_hash['document_type'].should == "FileMetadata"
49
50
  end
50
51
 
51
52
  it "the data should include the path, relative_path, links, owner, group, mode, checksum, type, and destination" do
52
- @metadata.to_pson_data_hash['data'].keys.sort.should == %w{ path relative_path links owner group mode checksum type destination }.sort
53
+ metadata.to_pson_data_hash['data'].keys.sort.should == %w{ path relative_path links owner group mode checksum type destination }.sort
53
54
  end
54
55
 
55
56
  it "should pass the path in the hash verbatum" do
56
- @metadata.to_pson_data_hash['data']['path'] == @metadata.path
57
+ metadata.to_pson_data_hash['data']['path'] == metadata.path
57
58
  end
58
59
 
59
60
  it "should pass the relative_path in the hash verbatum" do
60
- @metadata.to_pson_data_hash['data']['relative_path'] == @metadata.relative_path
61
+ metadata.to_pson_data_hash['data']['relative_path'] == metadata.relative_path
61
62
  end
62
63
 
63
64
  it "should pass the links in the hash verbatum" do
64
- @metadata.to_pson_data_hash['data']['links'] == @metadata.links
65
+ metadata.to_pson_data_hash['data']['links'] == metadata.links
65
66
  end
66
67
 
67
68
  it "should pass the path owner in the hash verbatum" do
68
- @metadata.to_pson_data_hash['data']['owner'] == @metadata.owner
69
+ metadata.to_pson_data_hash['data']['owner'] == metadata.owner
69
70
  end
70
71
 
71
72
  it "should pass the group in the hash verbatum" do
72
- @metadata.to_pson_data_hash['data']['group'] == @metadata.group
73
+ metadata.to_pson_data_hash['data']['group'] == metadata.group
73
74
  end
74
75
 
75
76
  it "should pass the mode in the hash verbatum" do
76
- @metadata.to_pson_data_hash['data']['mode'] == @metadata.mode
77
+ metadata.to_pson_data_hash['data']['mode'] == metadata.mode
77
78
  end
78
79
 
79
80
  it "should pass the ftype in the hash verbatum as the 'type'" do
80
- @metadata.to_pson_data_hash['data']['type'] == @metadata.ftype
81
+ metadata.to_pson_data_hash['data']['type'] == metadata.ftype
81
82
  end
82
83
 
83
84
  it "should pass the destination verbatum" do
84
- @metadata.to_pson_data_hash['data']['destination'] == @metadata.destination
85
+ metadata.to_pson_data_hash['data']['destination'] == metadata.destination
85
86
  end
86
87
 
87
88
  it "should pass the checksum in the hash as a nested hash" do
88
- @metadata.to_pson_data_hash['data']['checksum'].should be_is_a(Hash)
89
+ metadata.to_pson_data_hash['data']['checksum'].should be_is_a(Hash)
89
90
  end
90
91
 
91
92
  it "should pass the checksum_type in the hash verbatum as the checksum's type" do
92
- @metadata.to_pson_data_hash['data']['checksum']['type'] == @metadata.checksum_type
93
+ metadata.to_pson_data_hash['data']['checksum']['type'] == metadata.checksum_type
93
94
  end
94
95
 
95
96
  it "should pass the checksum in the hash verbatum as the checksum's value" do
96
- @metadata.to_pson_data_hash['data']['checksum']['value'] == @metadata.checksum
97
+ metadata.to_pson_data_hash['data']['checksum']['value'] == metadata.checksum
97
98
  end
98
99
 
99
100
  end