Skip to content

Commit 97eb01c

Browse files
committed
(PUP-10688) Allow tidy to pass on metaparameters
Prior to this commit, if a tidy resource contained a metaparamter like "schedule," that metaparameter was not passed on to generated child file resources. This commit uses the copy_metaparams method to allow tidy to generate child file resources with the same metaparameters (except for "alias"). It also updates and simplifies some older spec tests.
1 parent 238ec16 commit 97eb01c

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

lib/puppet/type/tidy.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,10 @@ def mkfile(path)
247247
:ensure => :absent, :force => true
248248
}
249249

250-
parameters[:noop] = self[:noop] unless self[:noop].nil?
250+
new_file = Puppet::Type.type(:file).new(parameters)
251+
new_file.copy_metaparams(@parameters)
251252

252-
Puppet::Type.type(:file).new(parameters)
253+
new_file
253254
end
254255

255256
def retrieve

spec/unit/type/tidy_spec.rb

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,27 +141,20 @@
141141
describe "and generating files" do
142142
it "should set the backup on the file if backup is set on the tidy instance" do
143143
@tidy[:backup] = "whatever"
144-
expect(Puppet::Type.type(:file)).to receive(:new).with(hash_including(backup: "whatever"))
145144

146-
@tidy.mkfile(@basepath)
145+
expect(@tidy.mkfile(@basepath)[:backup]).to eq("whatever")
147146
end
148147

149148
it "should set the file's path to the tidy's path" do
150-
expect(Puppet::Type.type(:file)).to receive(:new).with(hash_including(path: @basepath))
151-
152-
@tidy.mkfile(@basepath)
149+
expect(@tidy.mkfile(@basepath)[:path]).to eq(@basepath)
153150
end
154151

155152
it "should configure the file for deletion" do
156-
expect(Puppet::Type.type(:file)).to receive(:new).with(hash_including(ensure: :absent))
157-
158-
@tidy.mkfile(@basepath)
153+
expect(@tidy.mkfile(@basepath)[:ensure]).to eq(:absent)
159154
end
160155

161156
it "should force deletion on the file" do
162-
expect(Puppet::Type.type(:file)).to receive(:new).with(hash_including(force: true))
163-
164-
@tidy.mkfile(@basepath)
157+
expect(@tidy.mkfile(@basepath)[:force]).to eq(true)
165158
end
166159

167160
it "should do nothing if the targeted file does not exist" do
@@ -471,6 +464,23 @@
471464

472465
expect(result.values).to all(be_noop)
473466
end
467+
468+
it "generates resources whose schedule parameter matches the managed resource's schedule parameter" do
469+
@tidy[:recurse] = true
470+
@tidy[:schedule] = 'fake_schedule'
471+
472+
fileset = double('fileset')
473+
expect(Puppet::FileServing::Fileset).to receive(:new).with(@basepath, {:recurse => true, :max_files=>0}).and_return(fileset)
474+
expect(fileset).to receive(:files).and_return(%w{. a a/2 a/1 a/3})
475+
allow(@tidy).to receive(:tidy?).and_return(true)
476+
477+
result = @tidy.generate.inject({}) { |hash, res| hash[res[:path]] = res; hash }
478+
479+
result.each do |file_resource|
480+
expect(file_resource[1][:schedule]).to eq('fake_schedule')
481+
end
482+
483+
end
474484
end
475485

476486
def lstat_is(path, stat)

0 commit comments

Comments
 (0)