diff options
author | Jesse Wolfe <jes5199@gmail.com> | 2010-12-20 12:17:52 -0800 |
---|---|---|
committer | Jesse Wolfe <jes5199@gmail.com> | 2010-12-20 16:43:36 -0800 |
commit | 76fe2b3b24f6c04cd1cff7c8492d479d15258566 (patch) | |
tree | 2c30345fd6d82b446eb863eab2d3e40c52056978 /spec/unit | |
parent | a17f2616b4cb0a9231745090ace5bb25e7bc77c9 (diff) | |
download | puppet-76fe2b3b24f6c04cd1cff7c8492d479d15258566.tar.gz puppet-76fe2b3b24f6c04cd1cff7c8492d479d15258566.tar.xz puppet-76fe2b3b24f6c04cd1cff7c8492d479d15258566.zip |
Implement #5168 and #5169 ctime and mtime are properties
File ctime and mtime are now implemented as read-only properties, so
they can be examined with audit.
Diffstat (limited to 'spec/unit')
-rw-r--r-- | spec/unit/type/file/ctime.rb | 35 | ||||
-rw-r--r-- | spec/unit/type/file/mtime.rb | 35 | ||||
-rw-r--r-- | spec/unit/type/file/type.rb | 20 |
3 files changed, 90 insertions, 0 deletions
diff --git a/spec/unit/type/file/ctime.rb b/spec/unit/type/file/ctime.rb new file mode 100644 index 000000000..6145cbfdc --- /dev/null +++ b/spec/unit/type/file/ctime.rb @@ -0,0 +1,35 @@ +#!/usr/bin/env ruby + +Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") } + +describe Puppet::Type.type(:file).attrclass(:ctime) do + require 'puppet_spec/files' + include PuppetSpec::Files + + before do + @filename = tmpfile('ctime') + @resource = Puppet::Type.type(:file).new({:name => @filename}) + end + + it "should be able to audit the file's ctime" do + File.open(@filename, "w"){ } + + @resource[:audit] = [:ctime] + + # this .to_resource audit behavior is magical :-( + @resource.to_resource[:ctime].should == File.stat(@filename).ctime + end + + it "should return absent if auditing an absent file" do + @resource[:audit] = [:ctime] + + @resource.to_resource[:ctime].should == :absent + end + + it "should prevent the user from trying to set the ctime" do + lambda { + @resource[:ctime] = Time.now.to_s + }.should raise_error(Puppet::Error, /ctime is read-only/) + end + +end diff --git a/spec/unit/type/file/mtime.rb b/spec/unit/type/file/mtime.rb new file mode 100644 index 000000000..043156ceb --- /dev/null +++ b/spec/unit/type/file/mtime.rb @@ -0,0 +1,35 @@ +#!/usr/bin/env ruby + +Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") } + +describe Puppet::Type.type(:file).attrclass(:mtime) do + require 'puppet_spec/files' + include PuppetSpec::Files + + before do + @filename = tmpfile('mtime') + @resource = Puppet::Type.type(:file).new({:name => @filename}) + end + + it "should be able to audit the file's mtime" do + File.open(@filename, "w"){ } + + @resource[:audit] = [:mtime] + + # this .to_resource audit behavior is magical :-( + @resource.to_resource[:mtime].should == File.stat(@filename).mtime + end + + it "should return absent if auditing an absent file" do + @resource[:audit] = [:mtime] + + @resource.to_resource[:mtime].should == :absent + end + + it "should prevent the user from trying to set the mtime" do + lambda { + @resource[:mtime] = Time.now.to_s + }.should raise_error(Puppet::Error, /mtime is read-only/) + end + +end diff --git a/spec/unit/type/file/type.rb b/spec/unit/type/file/type.rb new file mode 100644 index 000000000..e46f0e0b0 --- /dev/null +++ b/spec/unit/type/file/type.rb @@ -0,0 +1,20 @@ +#!/usr/bin/env ruby + +Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") } + +describe Puppet::Type.type(:file).attrclass(:type) do + require 'puppet_spec/files' + include PuppetSpec::Files + + before do + @filename = tmpfile('type') + @resource = Puppet::Type.type(:file).new({:name => @filename}) + end + + it "should prevent the user from trying to set the type" do + lambda { + @resource[:type] = "fifo" + }.should raise_error(Puppet::Error, /type is read-only/) + end + +end |