summaryrefslogtreecommitdiffstats
path: root/test/util/storage.rb
blob: ae28bf992136098f839d5c4f6fc0d40078e33651 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env ruby

require File.dirname(__FILE__) + '/../lib/puppettest'

require 'puppet'
require 'puppettest'

class TestStorage < Test::Unit::TestCase
    include PuppetTest

    def mkfile
        path = tempfile()
        File.open(path, "w") { |f| f.puts :yayness }


                    f = Puppet::Type.type(:file).new(
                
            :name => path,
        
            :check => %w{checksum type}
        )

        f
    end

    def test_storeandretrieve
        path = tempfile()

        f = mkfile()

        # Load first, since that's what we do in the code base; this creates
        # all of the necessary directories.
        assert_nothing_raised {
            Puppet::Util::Storage.load
        }

        hash = {:a => :b, :c => :d}

        state = nil
        assert_nothing_raised {
            state = Puppet::Util::Storage.cache(f)
        }

        assert(!state.include?("name"))

        assert_nothing_raised {
            state["name"] = hash
        }

        assert_nothing_raised {
            Puppet::Util::Storage.store
        }
        assert_nothing_raised {
            Puppet::Util::Storage.clear
        }
        assert_nothing_raised {
            Puppet::Util::Storage.load
        }

        # Reset it
        state = nil
        assert_nothing_raised {
            state = Puppet::Util::Storage.cache(f)
        }

        assert_equal(state["name"], hash)
    end

    def test_emptyrestore
        Puppet::Util::Storage.load
        Puppet::Util::Storage.store
        Puppet::Util::Storage.clear
        Puppet::Util::Storage.load

        f = mkfile()
        state = Puppet::Util::Storage.cache(f)
        assert_same Hash, state.class
        assert_equal 0, state.size
    end
end