summaryrefslogtreecommitdiffstats
path: root/spec/unit/indirector/facts/yaml.rb
blob: 45c079a6938713d2797436e1d077cbbd0693167c (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
#!/usr/bin/env ruby

require File.dirname(__FILE__) + '/../../../spec_helper'

require 'puppet/indirector'
require 'puppet/node/facts'
require 'puppettest'

describe Puppet::Indirector.terminus(:facts, :yaml), " when managing facts" do
    # For cleanup mechanisms.
    include PuppetTest

    # LAK:FIXME It seems like I really do have to hit the filesystem
    # here, since, like, that's what I'm testing.  Is there another/better
    # way to do this?
    before do
        @store = Puppet::Indirector.terminus(:facts, :yaml).new
        setup # Grr, stupid rspec
        Puppet[:yamlfactdir] = tempfile
        Dir.mkdir(Puppet[:yamlfactdir])
    end

    it "should store facts in YAML in the yamlfactdir" do
        values = {"one" => "two", "three" => "four"}
        facts = Puppet::Node::Facts.new("node", values)
        @store.put(facts)

        # Make sure the file exists
        path = File.join(Puppet[:yamlfactdir], facts.name) + ".yaml"
        File.exists?(path).should be_true

        # And make sure it's right
        newvals = YAML.load(File.read(path))

        # We iterate over them, because the store might add extra values.
        values.each do |name, value|
            newvals[name].should == value
        end
    end

    it "should retrieve values from disk" do
        values = {"one" => "two", "three" => "four"}

        # Create the file.
        path = File.join(Puppet[:yamlfactdir], "node") + ".yaml"
        File.open(path, "w") do |f|
            f.print values.to_yaml
        end

        facts = Puppet::Node::Facts.get('node')
        facts.should be_instance_of(Puppet::Node::Facts)

        # We iterate over them, because the store might add extra values.
        values.each do |name, value|
            facts.values[name].should == value
        end
    end

    after do
        teardown
    end
end