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
|
require 'spec_helper'
require 'puppet_spec/compiler'
require 'matchers/resource'
describe "Evaluation of Conditionals" do
include PuppetSpec::Compiler
include Matchers::Resource
context "a catalog built with conditionals" do
it "evaluates an if block correctly" do
catalog = compile_to_catalog(<<-CODE)
if( 1 == 1) {
notify { 'if': }
} elsif(2 == 2) {
notify { 'elsif': }
} else {
notify { 'else': }
}
CODE
expect(catalog).to have_resource("Notify[if]")
end
it "evaluates elsif block" do
catalog = compile_to_catalog(<<-CODE)
if( 1 == 3) {
notify { 'if': }
} elsif(2 == 2) {
notify { 'elsif': }
} else {
notify { 'else': }
}
CODE
expect(catalog).to have_resource("Notify[elsif]")
end
it "reaches the else clause if no expressions match" do
catalog = compile_to_catalog(<<-CODE)
if( 1 == 2) {
notify { 'if': }
} elsif(2 == 3) {
notify { 'elsif': }
} else {
notify { 'else': }
}
CODE
expect(catalog).to have_resource("Notify[else]")
end
it "evalutes false to false" do
catalog = compile_to_catalog(<<-CODE)
if false {
} else {
notify { 'false': }
}
CODE
expect(catalog).to have_resource("Notify[false]")
end
it "evaluates the string 'false' as true" do
catalog = compile_to_catalog(<<-CODE)
if 'false' {
notify { 'true': }
} else {
notify { 'false': }
}
CODE
expect(catalog).to have_resource("Notify[true]")
end
it "evaluates undefined variables as false" do
catalog = compile_to_catalog(<<-CODE)
if $undef_var {
} else {
notify { 'undef': }
}
CODE
expect(catalog).to have_resource("Notify[undef]")
end
it "evaluates empty string as true" do
catalog = compile_to_catalog(<<-CODE)
if '' {
notify { 'true': }
} else {
notify { 'empty': }
}
CODE
expect(catalog).to have_resource("Notify[true]")
end
end
end
|