| 1 | #! /usr/bin/env ruby -S rspec
|
|---|
| 2 | require 'beaker-rspec'
|
|---|
| 3 | require 'beaker/puppet_install_helper'
|
|---|
| 4 |
|
|---|
| 5 | UNSUPPORTED_PLATFORMS = []
|
|---|
| 6 |
|
|---|
| 7 | run_puppet_install_helper
|
|---|
| 8 |
|
|---|
| 9 | RSpec.configure do |c|
|
|---|
| 10 | # Project root
|
|---|
| 11 | proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
|---|
| 12 |
|
|---|
| 13 | # Readable test descriptions
|
|---|
| 14 | c.formatter = :documentation
|
|---|
| 15 |
|
|---|
| 16 | # Configure all nodes in nodeset
|
|---|
| 17 | c.before :suite do
|
|---|
| 18 | if ENV['FUTURE_PARSER'] == 'yes'
|
|---|
| 19 | default[:default_apply_opts] ||= {}
|
|---|
| 20 | default[:default_apply_opts].merge!({:parser => 'future'})
|
|---|
| 21 | end
|
|---|
| 22 |
|
|---|
| 23 | copy_root_module_to(default, :source => proj_root, :module_name => 'stdlib')
|
|---|
| 24 | end
|
|---|
| 25 | end
|
|---|
| 26 |
|
|---|
| 27 | def is_future_parser_enabled?
|
|---|
| 28 | if default[:type] == 'aio'
|
|---|
| 29 | return true
|
|---|
| 30 | elsif default[:default_apply_opts]
|
|---|
| 31 | return default[:default_apply_opts][:parser] == 'future'
|
|---|
| 32 | end
|
|---|
| 33 | return false
|
|---|
| 34 | end
|
|---|
| 35 |
|
|---|
| 36 | def get_puppet_version
|
|---|
| 37 | (on default, puppet('--version')).output.chomp
|
|---|
| 38 | end
|
|---|
| 39 |
|
|---|
| 40 | RSpec.shared_context "with faked facts" do
|
|---|
| 41 | let(:facts_d) do
|
|---|
| 42 | puppet_version = get_puppet_version
|
|---|
| 43 | if fact('osfamily') =~ /windows/i
|
|---|
| 44 | if fact('kernelmajversion').to_f < 6.0
|
|---|
| 45 | 'C:/Documents and Settings/All Users/Application Data/PuppetLabs/facter/facts.d'
|
|---|
| 46 | else
|
|---|
| 47 | 'C:/ProgramData/PuppetLabs/facter/facts.d'
|
|---|
| 48 | end
|
|---|
| 49 | elsif Puppet::Util::Package.versioncmp(puppet_version, '4.0.0') < 0 and fact('is_pe', '--puppet') == "true"
|
|---|
| 50 | '/etc/puppetlabs/facter/facts.d'
|
|---|
| 51 | else
|
|---|
| 52 | '/etc/facter/facts.d'
|
|---|
| 53 | end
|
|---|
| 54 | end
|
|---|
| 55 |
|
|---|
| 56 | before :each do
|
|---|
| 57 | #No need to create on windows, PE creates by default
|
|---|
| 58 | if fact('osfamily') !~ /windows/i
|
|---|
| 59 | shell("mkdir -p '#{facts_d}'")
|
|---|
| 60 | end
|
|---|
| 61 | end
|
|---|
| 62 |
|
|---|
| 63 | after :each do
|
|---|
| 64 | shell("rm -f '#{facts_d}/fqdn.txt'", :acceptable_exit_codes => [0,1])
|
|---|
| 65 | end
|
|---|
| 66 |
|
|---|
| 67 | def fake_fact(name, value)
|
|---|
| 68 | shell("echo #{name}=#{value} > '#{facts_d}/#{name}.txt'")
|
|---|
| 69 | end
|
|---|
| 70 | end
|
|---|