2012-07-20 01:14:37 +02:00
|
|
|
#! /usr/bin/env ruby -S rspec
|
|
|
|
require 'spec_helper'
|
2011-06-21 23:10:33 +02:00
|
|
|
|
|
|
|
describe Puppet::Parser::Functions.function(:getvar) do
|
2012-07-23 17:28:06 +02:00
|
|
|
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
2011-06-21 23:10:33 +02:00
|
|
|
describe 'when calling getvar from puppet' do
|
|
|
|
|
|
|
|
it "should not compile when no arguments are passed" do
|
2012-08-10 20:43:36 +02:00
|
|
|
pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
|
2012-08-09 23:18:30 +02:00
|
|
|
Puppet[:code] = '$foo = getvar()'
|
|
|
|
expect {
|
|
|
|
scope.compiler.compile
|
|
|
|
}.to raise_error(Puppet::ParseError, /wrong number of arguments/)
|
2011-06-21 23:10:33 +02:00
|
|
|
end
|
2012-08-09 23:18:30 +02:00
|
|
|
|
2011-06-21 23:10:33 +02:00
|
|
|
it "should not compile when too many arguments are passed" do
|
2012-08-10 20:43:36 +02:00
|
|
|
pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
|
2012-08-09 23:18:30 +02:00
|
|
|
Puppet[:code] = '$foo = getvar("foo::bar", "baz")'
|
|
|
|
expect {
|
|
|
|
scope.compiler.compile
|
|
|
|
}.to raise_error(Puppet::ParseError, /wrong number of arguments/)
|
2011-06-21 23:10:33 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should lookup variables in other namespaces" do
|
2012-08-10 20:43:36 +02:00
|
|
|
pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
|
2011-06-21 23:10:33 +02:00
|
|
|
Puppet[:code] = <<-'ENDofPUPPETcode'
|
|
|
|
class site::data { $foo = 'baz' }
|
|
|
|
include site::data
|
|
|
|
$foo = getvar("site::data::foo")
|
|
|
|
if $foo != 'baz' {
|
|
|
|
fail('getvar did not return what we expect')
|
|
|
|
}
|
|
|
|
ENDofPUPPETcode
|
2012-07-20 01:14:37 +02:00
|
|
|
scope.compiler.compile
|
2011-06-21 23:10:33 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|