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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
require 'spec_helper'
require 'rspec-puppet/adapters'
def context_double(options = {})
double({:environment => 'rp_puppet'}.merge(options))
end
describe RSpec::Puppet::Adapters::Base do
describe '#setup_puppet' do
it "sets up all settings listed in the settings map" do
context = context_double
expected_settings = Hash[*subject.settings_map.map { |r| [r.first, anything] }.flatten]
expect(Puppet.settings).to receive(:initialize_app_defaults).with(hash_including(expected_settings))
subject.setup_puppet(context)
end
end
describe 'default settings' do
before do
subject.setup_puppet(context_double)
end
null_path = windows? ? 'c:/nul/' : '/dev/null'
[:vardir, :confdir].each do |setting|
it "sets #{setting} to #{null_path}" do
expect(Puppet[setting]).to eq(File.expand_path(null_path))
end
end
end
describe '#set_setting' do
describe "with a context specific setting" do
it "sets the Puppet setting based on the example group setting" do
context = context_double :confdir => "/etc/fingerpuppet"
subject.setup_puppet(context)
expect(Puppet[:confdir]).to match(%r{(C:)?/etc/fingerpuppet})
end
it "does not persist settings between example groups" do
context1 = context_double :confdir => "/etc/fingerpuppet"
context2 = context_double
subject.setup_puppet(context1)
expect(Puppet[:confdir]).to match(%r{(C:)?/etc/fingerpuppet})
subject.setup_puppet(context2)
expect(Puppet[:confdir]).not_to match(%r{(C:)?/etc/fingerpuppet})
end
end
describe "with a global RSpec configuration setting" do
before do
allow(RSpec.configuration).to receive(:confdir).and_return("/etc/bunraku")
end
it "sets the Puppet setting based on the global configuration value" do
subject.setup_puppet(context_double)
expect(Puppet[:confdir]).to match(%r{(C:)?/etc/bunraku})
end
end
describe "with both a global RSpec configuration setting and a context specific setting" do
before do
allow(RSpec.configuration).to receive(:confdir).and_return("/etc/bunraku")
end
it "prefers the context specific setting" do
context = context_double :confdir => "/etc/sockpuppet"
subject.setup_puppet(context)
expect(Puppet[:confdir]).to match(%r{(C:)?/etc/sockpuppet})
end
end
describe "when the setting is not available on the given version of Puppet" do
it "logs a warning about the setting" do
end
end
end
end
describe RSpec::Puppet::Adapters::Adapter35, :if => (3.5 ... 4.0).include?(Puppet.version.to_f) do
let(:test_context) { double :environment => 'rp_env' }
context 'when running on puppet 3.5 or later', :if => (3.5 ... 4.0).include?(Puppet.version.to_f) do
it 'sets Puppet[:strict_variables] to false by default' do
subject.setup_puppet(test_context)
expect(Puppet[:strict_variables]).to eq(false)
end
it 'reads the :strict_variables setting' do
allow(test_context).to receive(:strict_variables).and_return true
subject.setup_puppet(test_context)
expect(Puppet[:strict_variables]).to eq(true)
end
end
end
describe RSpec::Puppet::Adapters::Adapter34, :if => (3.4 ... 4.0).include?(Puppet.version.to_f) do
let(:test_context) { double :environment => 'rp_env' }
context 'when running on puppet 3.4 or later', :if => (3.4 ... 4.0).include?(Puppet.version.to_f) do
it 'sets Puppet[:trusted_node_data] to false by default' do
subject.setup_puppet(test_context)
expect(Puppet[:trusted_node_data]).to eq(false)
end
it 'reads the :trusted_node_data setting' do
allow(test_context).to receive(:trusted_node_data).and_return(true)
subject.setup_puppet(test_context)
expect(Puppet[:trusted_node_data]).to eq(true)
end
end
end
describe RSpec::Puppet::Adapters::Adapter33, :if => (3.3 ... 4.0).include?(Puppet.version.to_f) do
let(:test_context) { double :environment => 'rp_env' }
context 'when running on puppet ~> 3.3', :if => (3.3 ... 4.0).include?(Puppet.version.to_f) do
it 'sets Puppet[:stringify_facts] to true by default' do
subject.setup_puppet(test_context)
expect(Puppet[:stringify_facts]).to eq(true)
end
it 'reads the :stringify_facts setting' do
allow(test_context).to receive(:stringify_facts).and_return false
subject.setup_puppet(test_context)
expect(Puppet[:stringify_facts]).to eq(false)
end
it 'sets Puppet[:ordering] to title-hash by default' do
subject.setup_puppet(test_context)
expect(Puppet[:ordering]).to eq('title-hash')
end
it 'reads the :ordering setting' do
allow(test_context).to receive(:ordering).and_return("manifest")
subject.setup_puppet(test_context)
expect(Puppet[:ordering]).to eq('manifest')
end
end
end
describe RSpec::Puppet::Adapters::Adapter32, :if => (3.2 ... 4.0).include?(Puppet.version.to_f) do
let(:test_context) { double :environment => 'rp_env' }
context 'when running on puppet ~> 3.2', :if => (3.2 ... 4.0).include?(Puppet.version.to_f) do
it 'sets Puppet[:parser] to "current" by default' do
subject.setup_puppet(test_context)
expect(Puppet[:parser]).to eq("current")
end
it 'reads the :parser setting' do
allow(test_context).to receive(:parser).and_return("future")
subject.setup_puppet(test_context)
expect(Puppet[:parser]).to eq("future")
end
end
describe 'default settings' do
before do
subject.setup_puppet(context_double)
end
null_path = windows? ? 'c:/nul/' : '/dev/null'
[:vardir, :rundir, :logdir, :hiera_config, :confdir].each do |setting|
it "sets #{setting} to #{null_path}" do
expect(Puppet[setting]).to eq(File.expand_path(null_path))
end
end
end
end
describe RSpec::Puppet::Adapters::Adapter4X, :if => (4.0 ... 6.0).include?(Puppet.version.to_f) do
let(:test_context) { double :environment => 'rp_env' }
it 'sets Puppet[:strict_variables] to false by default' do
subject.setup_puppet(test_context)
expect(Puppet[:strict_variables]).to eq(false)
end
it 'reads the :strict_variables setting' do
allow(test_context).to receive(:strict_variables).and_return(true)
subject.setup_puppet(test_context)
expect(Puppet[:strict_variables]).to eq(true)
end
it 'overrides the environmentpath set by Puppet::Test::TestHelper' do
allow(test_context).to receive(:environmentpath).and_return('/path/to/my/environments')
subject.setup_puppet(test_context)
expect(Puppet[:environmentpath]).to match(%r{(C:)?/path/to/my/environments})
end
describe '#manifest' do
it 'returns the configured environment manifest when set' do
allow(RSpec.configuration).to receive(:manifest).and_return("/path/to/manifest")
subject.setup_puppet(double(:environment => 'rp_puppet'))
expect(subject.manifest).to match(%r{(C:)?/path/to/manifest})
end
it 'returns nil when the configured environment manifest is not set' do
allow(RSpec.configuration).to receive(:manifest)
allow(RSpec.configuration).to receive(:environmentpath).and_return("/some/missing/path:/another/missing/path")
subject.setup_puppet(double(:environment => 'rp_puppet'))
expect(subject.manifest).to be_nil
end
end
describe 'default settings' do
before do
subject.setup_puppet(context_double)
end
null_path = windows? ? 'c:/nul/' : '/dev/null'
[:vardir, :codedir, :rundir, :logdir, :hiera_config, :confdir].each do |setting|
it "sets #{setting} to #{null_path}" do
expect(Puppet[setting]).to eq(File.expand_path(null_path))
end
end
end
end
|