2012-11-28 01:15:32 +01:00
|
|
|
#! /usr/bin/env ruby
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
require 'rspec-puppet'
|
2014-03-05 21:43:58 +01:00
|
|
|
require 'puppet_spec/compiler'
|
2012-11-28 01:15:32 +01:00
|
|
|
|
|
|
|
describe 'ensure_packages' do
|
2014-03-05 21:43:58 +01:00
|
|
|
include PuppetSpec::Compiler
|
|
|
|
|
|
|
|
before :each do
|
|
|
|
Puppet::Parser::Functions.autoloader.loadall
|
|
|
|
Puppet::Parser::Functions.function(:ensure_packages)
|
|
|
|
Puppet::Parser::Functions.function(:ensure_resource)
|
|
|
|
Puppet::Parser::Functions.function(:defined_with_params)
|
|
|
|
Puppet::Parser::Functions.function(:create_resources)
|
|
|
|
end
|
|
|
|
|
|
|
|
let :node do Puppet::Node.new('localhost') end
|
|
|
|
let :compiler do Puppet::Parser::Compiler.new(node) end
|
|
|
|
let :scope do
|
|
|
|
if Puppet.version.to_f >= 3.0
|
|
|
|
Puppet::Parser::Scope.new(compiler)
|
|
|
|
else
|
|
|
|
newscope = Puppet::Parser::Scope.new
|
|
|
|
newscope.compiler = compiler
|
|
|
|
newscope.source = Puppet::Resource::Type.new(:node, :localhost)
|
|
|
|
newscope
|
|
|
|
end
|
|
|
|
end
|
2012-11-28 01:15:32 +01:00
|
|
|
|
|
|
|
describe 'argument handling' do
|
|
|
|
it 'fails with no arguments' do
|
2014-01-15 20:04:03 +01:00
|
|
|
expect {
|
|
|
|
scope.function_ensure_packages([])
|
|
|
|
}.to raise_error(Puppet::ParseError, /0 for 1/)
|
2012-11-28 01:15:32 +01:00
|
|
|
end
|
2014-01-15 20:04:03 +01:00
|
|
|
|
|
|
|
it 'accepts an array of values' do
|
|
|
|
scope.function_ensure_packages([['foo']])
|
2012-11-28 01:15:32 +01:00
|
|
|
end
|
2013-11-19 19:38:12 +01:00
|
|
|
|
|
|
|
it 'accepts a single package name as a string' do
|
|
|
|
scope.function_ensure_packages(['foo'])
|
2012-11-28 01:15:32 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-05 21:43:58 +01:00
|
|
|
context 'given a catalog with puppet package => absent' do
|
|
|
|
let :catalog do
|
|
|
|
compile_to_catalog(<<-EOS
|
|
|
|
ensure_packages(['facter'])
|
|
|
|
package { puppet: ensure => absent }
|
|
|
|
EOS
|
|
|
|
)
|
2012-11-28 01:15:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has no effect on Package[puppet]' do
|
2014-03-05 21:43:58 +01:00
|
|
|
expect(catalog.resource(:package, 'puppet')['ensure']).to eq('absent')
|
2012-11-28 01:15:32 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'given a clean catalog' do
|
2014-03-05 21:43:58 +01:00
|
|
|
let :catalog do
|
|
|
|
compile_to_catalog('ensure_packages(["facter"])')
|
|
|
|
end
|
|
|
|
|
2012-11-28 01:15:32 +01:00
|
|
|
it 'declares package resources with ensure => present' do
|
2014-03-05 21:43:58 +01:00
|
|
|
expect(catalog.resource(:package, 'facter')['ensure']).to eq('present')
|
2012-11-28 01:15:32 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|