|
| 1 | +#!/usr/bin/env ruby -S rspec |
| 2 | +require 'spec_helper' |
| 3 | + |
| 4 | +describe "the pick_default function" do |
| 5 | + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } |
| 6 | + |
| 7 | + it "should exist" do |
| 8 | + Puppet::Parser::Functions.function("pick_default").should == "function_pick_default" |
| 9 | + end |
| 10 | + |
| 11 | + it 'should return the correct value' do |
| 12 | + scope.function_pick_default(['first', 'second']).should == 'first' |
| 13 | + end |
| 14 | + |
| 15 | + it 'should return the correct value if the first value is empty' do |
| 16 | + scope.function_pick_default(['', 'second']).should == 'second' |
| 17 | + end |
| 18 | + |
| 19 | + it 'should skip empty string values' do |
| 20 | + scope.function_pick_default(['', 'first']).should == 'first' |
| 21 | + end |
| 22 | + |
| 23 | + it 'should skip :undef values' do |
| 24 | + scope.function_pick_default([:undef, 'first']).should == 'first' |
| 25 | + end |
| 26 | + |
| 27 | + it 'should skip :undefined values' do |
| 28 | + scope.function_pick_default([:undefined, 'first']).should == 'first' |
| 29 | + end |
| 30 | + |
| 31 | + it 'should return the empty string if it is the last possibility' do |
| 32 | + scope.function_pick_default([:undef, :undefined, '']).should == '' |
| 33 | + end |
| 34 | + |
| 35 | + it 'should return :undef if it is the last possibility' do |
| 36 | + scope.function_pick_default(['', :undefined, :undef]).should == :undef |
| 37 | + end |
| 38 | + |
| 39 | + it 'should return :undefined if it is the last possibility' do |
| 40 | + scope.function_pick_default([:undef, '', :undefined]).should == :undefined |
| 41 | + end |
| 42 | + |
| 43 | + it 'should return the empty string if it is the only possibility' do |
| 44 | + scope.function_pick_default(['']).should == '' |
| 45 | + end |
| 46 | + |
| 47 | + it 'should return :undef if it is the only possibility' do |
| 48 | + scope.function_pick_default([:undef]).should == :undef |
| 49 | + end |
| 50 | + |
| 51 | + it 'should return :undefined if it is the only possibility' do |
| 52 | + scope.function_pick_default([:undefined]).should == :undefined |
| 53 | + end |
| 54 | + |
| 55 | + it 'should error if no values are passed' do |
| 56 | + expect { scope.function_pick_default([]) }.to raise_error(Puppet::Error, /Must receive at least one argument./) |
| 57 | + end |
| 58 | +end |
0 commit comments