summaryrefslogtreecommitdiffstats
path: root/spec/unit/type/file/ctime.rb
blob: 72a10b5687866b887e63dc66974c39dfc94fb04e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env ruby

require 'spec_helper'

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