File: facts_spec.rb

package info (click to toggle)
puppet-agent 8.10.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,404 kB
  • sloc: ruby: 286,820; sh: 492; xml: 116; makefile: 88; cs: 68
file content (40 lines) | stat: -rw-r--r-- 1,649 bytes parent folder | download | duplicates (2)
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
require 'spec_helper'

describe Puppet::Node::Facts do
  describe "when using the indirector" do
    it "should expire any cached node instances when it is saved" do
      allow(Puppet::Node::Facts.indirection).to receive(:terminus_class).and_return(:yaml)

      expect(Puppet::Node::Facts.indirection.terminus(:yaml)).to equal(Puppet::Node::Facts.indirection.terminus(:yaml))
      terminus = Puppet::Node::Facts.indirection.terminus(:yaml)
      allow(terminus).to receive(:save)

      expect(Puppet::Node.indirection).to receive(:expire).with("me", be_a(Hash).or(be_nil))

      facts = Puppet::Node::Facts.new("me")
      Puppet::Node::Facts.indirection.save(facts)
    end

    it "should be able to delegate to the :yaml terminus" do
      allow(Puppet::Node::Facts.indirection).to receive(:terminus_class).and_return(:yaml)

      # Load now, before we stub the exists? method.
      terminus = Puppet::Node::Facts.indirection.terminus(:yaml)

      expect(terminus).to receive(:path).with("me").and_return("/my/yaml/file")
      expect(Puppet::FileSystem).to receive(:exist?).with("/my/yaml/file").and_return(false)

      expect(Puppet::Node::Facts.indirection.find("me")).to be_nil
    end

    it "should be able to delegate to the :facter terminus" do
      allow(Puppet::Node::Facts.indirection).to receive(:terminus_class).and_return(:facter)

      expect(Facter).to receive(:resolve).and_return({1 => 2})
      facts = Puppet::Node::Facts.new("me")
      expect(Puppet::Node::Facts).to receive(:new).with("me", {1 => 2}).and_return(facts)

      expect(Puppet::Node::Facts.indirection.find("me")).to equal(facts)
    end
  end
end