File: environment_spec.rb

package info (click to toggle)
puppet 5.5.22-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 21,316 kB
  • sloc: ruby: 254,925; sh: 1,608; xml: 219; makefile: 153; sql: 103
file content (47 lines) | stat: -rw-r--r-- 1,436 bytes parent folder | download | duplicates (6)
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
require 'spec_helper'

describe "A parser environment setting" do

  let(:confdir) { Puppet[:confdir] }
  let(:environmentpath) { File.expand_path("envdir", confdir) }
  let(:testingdir) { File.join(environmentpath, "testing") }

  before(:each) do
    FileUtils.mkdir_p(testingdir)
  end

  it "selects the given parser when compiling" do
    manifestsdir = File.expand_path("manifests", confdir)
    FileUtils.mkdir_p(manifestsdir)

    File.open(File.join(testingdir, "environment.conf"), "w") do |f|
      f.puts(<<-ENVCONF)
        parser='future'
        manifest =#{manifestsdir}
      ENVCONF
    end

    File.open(File.join(confdir, "puppet.conf"), "w") do |f|
      f.puts(<<-EOF)
          environmentpath=#{environmentpath}
          parser='current'
      EOF
    end

    File.open(File.join(manifestsdir, "site.pp"), "w") do |f|
      f.puts("notice( [1,2,3].map |$x| { $x*10 })")
    end

    expect { a_catalog_compiled_for_environment('testing') }.to_not raise_error
  end

  def a_catalog_compiled_for_environment(envname)
    Puppet.initialize_settings
    expect(Puppet[:environmentpath]).to eq(environmentpath)
    node = Puppet::Node.new('testnode', :environment => 'testing')
    expect(node.environment).to eq(Puppet.lookup(:environments).get('testing'))
    Puppet.override(:current_environment => Puppet.lookup(:environments).get('testing')) do
      Puppet::Parser::Compiler.compile(node)
    end
  end
end