File: catalog_spec.rb

package info (click to toggle)
puppet-agent 8.10.0-5
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 27,392 kB
  • sloc: ruby: 286,820; sh: 492; xml: 116; makefile: 88; cs: 68
file content (68 lines) | stat: -rw-r--r-- 2,139 bytes parent folder | download | duplicates (3)
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
require 'spec_helper'
require 'matchers/include_in_order'
require 'puppet_spec/compiler'
require 'puppet/indirector/catalog/compiler'

describe "A catalog" do
  include PuppetSpec::Compiler

  context "when compiled" do
    let(:env) { Puppet::Node::Environment.create(:testing, []) }
    let(:node) { Puppet::Node.new('test', :environment => env) }
    let(:loaders) { Puppet::Pops::Loaders.new(env) }

    before(:each) do
      Puppet.push_context({:loaders => loaders, :current_environment => env})
      allow_any_instance_of(Puppet::Parser::Compiler).to receive(:loaders).and_return(loaders)
    end

    after(:each) do
      Puppet.pop_context()
    end

    context "when transmitted to the agent" do
      it "preserves the order in which the resources are added to the catalog" do
        resources_in_declaration_order = ["Class[First]",
                                          "Second[position]",
                                          "Class[Third]",
                                          "Fourth[position]"]

        master_catalog, agent_catalog = master_and_agent_catalogs_for(<<-EOM)
          define fourth() { }
          class third { }

          define second() {
            fourth { "position": }
          }

          class first {
            second { "position": }
            class { "third": }
          }

          include first
        EOM

        expect(resources_in(master_catalog)).
          to include_in_order(*resources_in_declaration_order)
        expect(resources_in(agent_catalog)).
          to include_in_order(*resources_in_declaration_order)
      end
    end
  end

  def master_catalog_for(manifest)
    Puppet::Resource::Catalog::Compiler.new.filter(compile_to_catalog(manifest, node))
  end

  def master_and_agent_catalogs_for(manifest)
    compiler = Puppet::Resource::Catalog::Compiler.new
    master_catalog = compiler.filter(compile_to_catalog(manifest, node))
    agent_catalog = Puppet::Resource::Catalog.convert_from(:json, master_catalog.render(:json))
    [master_catalog, agent_catalog]
  end

  def resources_in(catalog)
    catalog.resources.map(&:ref)
  end
end