summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-05-01 10:13:19 -0700
committerJames Turnbull <james@lovedthanlost.net>2010-05-02 17:58:04 +1000
commitbcde541e4433aa46c9f922b01e34368a09abb7e8 (patch)
treefe7acfb7067a5531b9bfb9bc2faa70d01ea80131 /spec
parent5abe571e167744ac198960c8e35c699375ec5cf7 (diff)
Fix for #2910 -- Tidy/matches is too tricky to use
The semantic interaction of tidy/matches and tidy/recurse is tricky to get right; it only makes sense to use matches with recursion (a fixed path will either statically match or it won't, no need for a run-time check) but there was nothing to warn users of this fact. To compound matters, the example in the matches parameter doc string even made this mistake. This patch: 1) fixes the doc string; 2) prohibits the use of match without a value of recurse capable of generating files to match, 3) fixes tests that were passing for the wrong reason and adds tests on the prohibition added in (2).
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/type/tidy.rb25
1 files changed, 24 insertions, 1 deletions
diff --git a/spec/unit/type/tidy.rb b/spec/unit/type/tidy.rb
index ccec9ed7c..6eac6a286 100755
--- a/spec/unit/type/tidy.rb
+++ b/spec/unit/type/tidy.rb
@@ -60,6 +60,28 @@ describe tidy do
lambda { @tidy[:recurse] = "whatever" }.should raise_error
end
end
+
+ describe "for 'matches'" do
+ before do
+ @tidy = Puppet::Type.type(:tidy).new :path => "/tmp", :age => "100d"
+ end
+
+ it "should object if matches is given with recurse is not specified" do
+ lambda { @tidy[:matches] = '*.doh' }.should raise_error
+ end
+ it "should object if matches is given and recurse is 0" do
+ lambda { @tidy[:recurse] = 0; @tidy[:matches] = '*.doh' }.should raise_error
+ end
+ it "should object if matches is given and recurse is false" do
+ lambda { @tidy[:recurse] = false; @tidy[:matches] = '*.doh' }.should raise_error
+ end
+ it "should not object if matches is given and recurse is > 0" do
+ lambda { @tidy[:recurse] = 1; @tidy[:matches] = '*.doh' }.should_not raise_error
+ end
+ it "should not object if matches is given and recurse is true" do
+ lambda { @tidy[:recurse] = true; @tidy[:matches] = '*.doh' }.should_not raise_error
+ end
+ end
end
describe "when matching files by age" do
@@ -199,7 +221,7 @@ describe tidy do
describe "and determining whether a file matches provided glob patterns" do
before do
- @tidy = Puppet::Type.type(:tidy).new :path => "/what/ever"
+ @tidy = Puppet::Type.type(:tidy).new :path => "/what/ever", :recurse => 1
@tidy[:matches] = %w{*foo* *bar*}
@stat = mock 'stat'
@@ -316,6 +338,7 @@ describe tidy do
end
it "should return false if it does not match any provided globs" do
+ @tidy[:recurse] = 1
@tidy[:matches] = "globs"
matches = @tidy.parameter(:matches)