summaryrefslogtreecommitdiffstats
path: root/test/other/loadedfile.rb
blob: efb17a1e55fd56b0a0def993bdedf9ef9335c175 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
if __FILE__ == $0
    $:.unshift '..'
    $:.unshift '../../lib'
    $puppetbase = "../.."
end

require 'puppet'
require 'puppet/loadedfile'
require 'puppettest'
require 'test/unit'

class TestLoadedFile < Test::Unit::TestCase
	include TestPuppet
    def test_file
        Puppet[:filetimeout] = 0
        file = nil
        path = tempfile()
        File.open(path, "w") { |f| f.puts "yayness" }
        assert_nothing_raised {
            file = Puppet::LoadedFile.new(path)
        }

        assert(!file.changed?, "File incorrectly returned changed")

        #sleep(1)
        File.open(path, "w") { |f| f.puts "booness" }
        file.send("tstamp=".intern, File.stat(path).ctime - 5)

        assert(file.changed?, "File did not catch change")
    end

    def test_timeout
        Puppet[:filetimeout] = 50
        path = tempfile()

        File.open(path, "w") { |f| f.puts "yay" }
        file = nil
        assert_nothing_raised {
            file = Puppet::LoadedFile.new(path)
        }

        assert_nothing_raised { file.changed? }

        File.open(path, "w") { |f| f.puts "yay" }
        file.send("tstamp=".intern, File.stat(path).ctime - 5)

        assert(!file.changed?,
            "File was marked as changed too soon")

        Puppet[:filetimeout] = 0
        assert(file.changed?,
            "File was not marked as changed soon enough")


    end
end

# $Id$