Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F8391028
attributes_spec.rb
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
17 KB
Subscribers
None
attributes_spec.rb
View Options
require
'spec_helper'
describe
'icinga2_attributes'
do
let
(
:pre_condition
)
do
[
"class { 'icinga2': }"
]
end
let
(
:facts
)
do
{
:kernel
=>
'Linux'
,
:os
=>
{
:family
=>
'Debian'
,
:name
=>
'Debian'
},
:osfamily
=>
'Debian'
,
}
end
it
'raises a ArgumentError if there is less than 1 arguments'
do
is_expected
.
to
run
.
with_params
.
and_raise_error
(
Puppet
::
ParseError
)
end
it
'raises a ArgumentError if there are more than 4 arguments'
do
is_expected
.
to
run
.
with_params
(
'one'
,
'two'
,
'three'
,
'four'
,
'five'
)
.
and_raise_error
(
Puppet
::
ParseError
)
end
it
'assign a string'
do
# foo = "some string"
is_expected
.
to
run
.
with_params
({
'foo'
=>
'some string, connected to another. Yeah!'
})
.
and_return
(
"foo =
\"
some string, connected to another. Yeah!
\"\n
"
)
# foo += "some string"
is_expected
.
to
run
.
with_params
({
'foo'
=>
'+ some string, connected to another. Yeah!'
})
.
and_return
(
"foo +=
\"
some string, connected to another. Yeah!
\"\n
"
)
# vars.foo = "some string"
is_expected
.
to
run
.
with_params
({
'vars'
=>
{
'foo'
=>
'some string, connected to another. Yeah!'
}
})
.
and_return
(
"vars.foo =
\"
some string, connected to another. Yeah!
\"\n
"
)
# vars.foo += "some string"
is_expected
.
to
run
.
with_params
({
'vars'
=>
{
'foo'
=>
'+ some string, connected to another. Yeah!'
}
})
.
and_return
(
"vars.foo +=
\"
some string, connected to another. Yeah!
\"\n
"
)
end
it
'assign a boolean'
do
# foo = false
is_expected
.
to
run
.
with_params
({
'foo'
=>
'false'
})
.
and_return
(
"foo = false
\n
"
)
# foo = true
is_expected
.
to
run
.
with_params
({
'foo'
=>
'true'
})
.
and_return
(
"foo = true
\n
"
)
# foo = null
is_expected
.
to
run
.
with_params
({
'foo'
=>
'null'
})
.
and_return
(
"foo = null
\n
"
)
# vars.foo = false
is_expected
.
to
run
.
with_params
({
'vars'
=>
{
'foo'
=>
'false'
}
})
.
and_return
(
"vars.foo = false
\n
"
)
# vars.foo = true
is_expected
.
to
run
.
with_params
({
'vars'
=>
{
'foo'
=>
'true'
}
})
.
and_return
(
"vars.foo = true
\n
"
)
# vars.foo = null
is_expected
.
to
run
.
with_params
({
'vars'
=>
{
'foo'
=>
'null'
}
})
.
and_return
(
"vars.foo = null
\n
"
)
end
it
'assign a number'
do
# foo = 42
is_expected
.
to
run
.
with_params
({
'foo'
=>
'42'
})
.
and_return
(
"foo = 42
\n
"
)
# foo += 42
is_expected
.
to
run
.
with_params
({
'foo'
=>
'+ 42'
})
.
and_return
(
"foo += 42
\n
"
)
# foo -= 42
is_expected
.
to
run
.
with_params
({
'foo'
=>
'- 42'
})
.
and_return
(
"foo -= 42
\n
"
)
# foo = -42
is_expected
.
to
run
.
with_params
({
'foo'
=>
'-42'
})
.
and_return
(
"foo = -42
\n
"
)
# foo += -42
is_expected
.
to
run
.
with_params
({
'foo'
=>
'+ -42'
})
.
and_return
(
"foo += -42
\n
"
)
# foo -= -42
is_expected
.
to
run
.
with_params
({
'foo'
=>
'- -42'
})
.
and_return
(
"foo -= -42
\n
"
)
# vars.foo = 42
is_expected
.
to
run
.
with_params
({
'vars'
=>
{
'foo'
=>
'42'
}
})
.
and_return
(
"vars.foo = 42
\n
"
)
# vars.foo += 42
is_expected
.
to
run
.
with_params
({
'vars'
=>
{
'foo'
=>
'+ 42'
}
})
.
and_return
(
"vars.foo += 42
\n
"
)
# vars.foo -= 42
is_expected
.
to
run
.
with_params
({
'vars'
=>
{
'foo'
=>
'- 42'
}
})
.
and_return
(
"vars.foo -= 42
\n
"
)
# vars.foo = -42
is_expected
.
to
run
.
with_params
({
'vars'
=>
{
'foo'
=>
'-42'
}
})
.
and_return
(
"vars.foo = -42
\n
"
)
# vars.foo += -42
is_expected
.
to
run
.
with_params
({
'vars'
=>
{
'foo'
=>
'+ -42'
}
})
.
and_return
(
"vars.foo += -42
\n
"
)
# vars.foo -= -42
is_expected
.
to
run
.
with_params
({
'vars'
=>
{
'foo'
=>
'- -42'
}
})
.
and_return
(
"vars.foo -= -42
\n
"
)
end
it
'assign a floating point number'
do
# foo = 3.141
is_expected
.
to
run
.
with_params
({
'foo'
=>
'3.141'
})
.
and_return
(
"foo = 3.141
\n
"
)
# foo += 3.141
is_expected
.
to
run
.
with_params
({
'foo'
=>
'+ 3.141'
})
.
and_return
(
"foo += 3.141
\n
"
)
# foo -= 3.141
is_expected
.
to
run
.
with_params
({
'foo'
=>
'- 3.141'
})
.
and_return
(
"foo -= 3.141
\n
"
)
# foo = -3.141
is_expected
.
to
run
.
with_params
({
'foo'
=>
'-3.141'
})
.
and_return
(
"foo = -3.141
\n
"
)
# foo += -3.141
is_expected
.
to
run
.
with_params
({
'foo'
=>
'+ -3.141'
})
.
and_return
(
"foo += -3.141
\n
"
)
# foo -= -3.141
is_expected
.
to
run
.
with_params
({
'foo'
=>
'- -3.141'
})
.
and_return
(
"foo -= -3.141
\n
"
)
# vars.foo = 3.141
is_expected
.
to
run
.
with_params
({
'vars'
=>
{
'foo'
=>
'3.141'
}
})
.
and_return
(
"vars.foo = 3.141
\n
"
)
# vars.foo += 3.141
is_expected
.
to
run
.
with_params
({
'vars'
=>
{
'foo'
=>
'+ 3.141'
}
})
.
and_return
(
"vars.foo += 3.141
\n
"
)
# vars.foo -= 3.141
is_expected
.
to
run
.
with_params
({
'vars'
=>
{
'foo'
=>
'- 3.141'
}
})
.
and_return
(
"vars.foo -= 3.141
\n
"
)
# vars.foo = -3.141
is_expected
.
to
run
.
with_params
({
'vars'
=>
{
'foo'
=>
'-3.141'
}
})
.
and_return
(
"vars.foo = -3.141
\n
"
)
# vars.foo += -3.141
is_expected
.
to
run
.
with_params
({
'vars'
=>
{
'foo'
=>
'+ -3.141'
}
})
.
and_return
(
"vars.foo += -3.141
\n
"
)
# vars.foo -= -3.141
is_expected
.
to
run
.
with_params
({
'vars'
=>
{
'foo'
=>
'- -3.141'
}
})
.
and_return
(
"vars.foo -= -3.141
\n
"
)
end
it
'assign numbers with time units'
do
# foo_s = 60s
# foo_m = 5m
# foo_h = 2.5h
# foo_d = 2d
is_expected
.
to
run
.
with_params
({
'foo_s'
=>
'60s'
,
'foo_m'
=>
'5m'
,
'foo_h'
=>
'2.5h'
,
'foo_d'
=>
'2d'
})
.
and_return
(
"foo_s = 60s
\n
foo_m = 5m
\n
foo_h = 2.5h
\n
foo_d = 2d
\n
"
)
# vars.foo_s = 60s
# vars.foo_m = 5m
# vars.foo_h = 2.5h
# vars.foo_d = 2d
is_expected
.
to
run
.
with_params
({
'vars'
=>
{
'foo_s'
=>
'60s'
,
'foo_m'
=>
'5m'
,
'foo_h'
=>
'2.5h'
,
'foo_d'
=>
'2d'
}
})
.
and_return
(
"vars.foo_s = 60s
\n
vars.foo_m = 5m
\n
vars.foo_h = 2.5h
\n
vars.foo_d = 2d
\n
"
)
end
it
'assign an array'
do
# foo = [ "some string, connected to another. Yeah!", NodeName, 42, 3.141, 2d, true, ]
is_expected
.
to
run
.
with_params
({
'foo'
=>
[
'some string, connected to another. Yeah!'
,
'NodeName'
,
'42'
,
'3.141'
,
'2.5d'
,
'true'
]
})
.
and_return
(
"foo = [
\"
some string, connected to another. Yeah!
\"
, NodeName, 42, 3.141, 2.5d, true, ]
\n
"
)
# foo += [ "some string, connected to another. Yeah!", NodeName, 42, 3.141, 2d, true, ]
is_expected
.
to
run
.
with_params
({
'foo'
=>
[
'+'
,
'some string, connected to another. Yeah!'
,
'NodeName'
,
'42'
,
'3.141'
,
'2.5d'
,
'true'
]
})
.
and_return
(
"foo += [
\"
some string, connected to another. Yeah!
\"
, NodeName, 42, 3.141, 2.5d, true, ]
\n
"
)
# foo -= [ "some string, connected to another. Yeah!", NodeName, 42, 3.141, 2d, true, ]
is_expected
.
to
run
.
with_params
({
'foo'
=>
[
'-'
,
'some string, connected to another. Yeah!'
,
'NodeName'
,
'42'
,
'3.141'
,
'2.5d'
,
'true'
]
})
.
and_return
(
"foo -= [
\"
some string, connected to another. Yeah!
\"
, NodeName, 42, 3.141, 2.5d, true, ]
\n
"
)
# vars.foo = [ "some string, connected to another. Yeah!", NodeName, 42, 3.141, 2d, true, ]
is_expected
.
to
run
.
with_params
({
'vars'
=>
{
'foo'
=>
[
'some string, connected to another. Yeah!'
,
'NodeName'
,
'42'
,
'3.141'
,
'2.5d'
,
'true'
]
}
})
.
and_return
(
"vars.foo = [
\"
some string, connected to another. Yeah!
\"
, NodeName, 42, 3.141, 2.5d, true, ]
\n
"
)
# vars.foo += [ "some string, connected to another. Yeah!", NodeName, 42, 3.141, 2d, true, ]
is_expected
.
to
run
.
with_params
({
'vars'
=>
{
'foo'
=>
[
'+'
,
'some string, connected to another. Yeah!'
,
'NodeName'
,
'42'
,
'3.141'
,
'2.5d'
,
'true'
]
}
})
.
and_return
(
"vars.foo += [
\"
some string, connected to another. Yeah!
\"
, NodeName, 42, 3.141, 2.5d, true, ]
\n
"
)
# vars.foo -= [ "some string, connected to another. Yeah!", NodeName, 42, 3.141, 2d, true, ]
is_expected
.
to
run
.
with_params
({
'vars'
=>
{
'foo'
=>
[
'-'
,
'some string, connected to another. Yeah!'
,
'NodeName'
,
'42'
,
'3.141'
,
'2.5d'
,
'true'
]
}
})
.
and_return
(
"vars.foo -= [
\"
some string, connected to another. Yeah!
\"
, NodeName, 42, 3.141, 2.5d, true, ]
\n
"
)
end
it
'assign a hash'
do
# foo = {}
is_expected
.
to
run
.
with_params
({
'foo'
=>
{}
})
.
and_return
(
"foo = {}
\n
"
)
# foo += {}
is_expected
.
to
run
.
with_params
({
'foo'
=>
{
'+'
=>
true
,
}
})
.
and_return
(
"foo += {}
\n
"
)
# foo = {
# string = "some string, connected to another. Yeah!"
# constant = NodeName
# numbers = [ 42, 3.141, -42, -3.141, ]
# time = 2.5d
# bool = true
# }
is_expected
.
to
run
.
with_params
({
'foo'
=>
{
'string'
=>
'some string, connected to another. Yeah!'
,
'constant'
=>
'NodeName'
,
'numbers'
=>
[
'42'
,
'3.141'
,
'-42'
,
'-3.141'
]
,
'merge_array'
=>
[
'+'
,
'42'
,
'3.141'
,
'-42'
,
'-3.141'
]
,
'time'
=>
'2.5d'
,
'bool'
=>
'true'
,
}
})
.
and_return
(
"foo = {
\n
string =
\"
some string, connected to another. Yeah!
\"\n
constant = NodeName
\n
numbers = [ 42, 3.141, -42, -3.141, ]
\n
merge_array += [ 42, 3.141, -42, -3.141, ]
\n
time = 2.5d
\n
bool = true
\n
}
\n
"
)
# foo += {
# string = "some string, connected to another. Yeah!"
# constant = NodeName
# numbers = [ 42, 3.141, -42, -3.141, ]
# time = 2.5d
# bool = true
# }
is_expected
.
to
run
.
with_params
({
'foo'
=>
{
'+'
=>
true
,
'string'
=>
'some string, connected to another. Yeah!'
,
'constant'
=>
'NodeName'
,
'numbers'
=>
[
'42'
,
'3.141'
,
'-42'
,
'-3.141'
]
,
'merge_array'
=>
[
'+'
,
'42'
,
'3.141'
,
'-42'
,
'-3.141'
]
,
'time'
=>
'2.5d'
,
'bool'
=>
'true'
,
}
})
.
and_return
(
"foo += {
\n
string =
\"
some string, connected to another. Yeah!
\"\n
constant = NodeName
\n
numbers = [ 42, 3.141, -42, -3.141, ]
\n
merge_array += [ 42, 3.141, -42, -3.141, ]
\n
time = 2.5d
\n
bool = true
\n
}
\n
"
)
# vars.foo["string"] = "some string, connected to another. Yeah!"
# vars.foo["constant"] = NodeName
# vars.foo["numbers"] = [ 42, 3.141, -42, -3.141, ]
# vars.foo["merge_array"] += [ 42, 3.141, -42, -3.141, ]
# vars.foo["time"] = 2.5d
# vars.foo["bool"] = true
is_expected
.
to
run
.
with_params
({
'vars'
=>
{
'foo'
=>
{
'string'
=>
'some string, connected to another. Yeah!'
,
'constant'
=>
'NodeName'
,
'numbers'
=>
[
'42'
,
'3.141'
,
'-42'
,
'-3.141'
]
,
'merge_array'
=>
[
'+'
,
'42'
,
'3.141'
,
'-42'
,
'-3.141'
]
,
'time'
=>
'2.5d'
,
'bool'
=>
'true'
}
}
})
.
and_return
(
"vars.foo[
\"
string
\"
] =
\"
some string, connected to another. Yeah!
\"\n
vars.foo[
\"
constant
\"
] = NodeName
\n
vars.foo[
\"
numbers
\"
] = [ 42, 3.141, -42, -3.141, ]
\n
vars.foo[
\"
merge_array
\"
] += [ 42, 3.141, -42, -3.141, ]
\n
vars.foo[
\"
time
\"
] = 2.5d
\n
vars.foo[
\"
bool
\"
] = true
\n
"
)
end
it
'assign a nested hash'
do
# foobar = {
# foo += {
# string = "some string, connected to another. Yeah!"
# constant = NodeName
# bool = true
# }
# fooz += {}
# bar = {
# numbers = [ 42, 3.141, -42, -3,141, ]
# merge_array += [ 42, 3.141, -42, -3,141, ]
# time = 2.5d
# }
# baz = {}
# }
is_expected
.
to
run
.
with_params
({
'foobar'
=>
{
'foo'
=>
{
'+'
=>
true
,
'string'
=>
'some string, connected to another. Yeah!'
,
'constant'
=>
'NodeName'
,
'bool'
=>
'true'
},
'fooz'
=>
{
'+'
=>
true
,
},
'bar'
=>
{
'numbers'
=>
[
'42'
,
'3.141'
,
'-42'
,
'-3.141'
]
,
'merge_array'
=>
[
'+'
,
'42'
,
'3.141'
,
'-42'
,
'-3.141'
]
,
'time'
=>
'2.5d'
},
'baz'
=>
{},
}
})
.
and_return
(
"foobar = {
\n
foo += {
\n
string =
\"
some string, connected to another. Yeah!
\"\n
constant = NodeName
\n
bool = true
\n
}
\n
fooz += {}
\n
bar = {
\n
numbers = [ 42, 3.141, -42, -3.141, ]
\n
merge_array += [ 42, 3.141, -42, -3.141, ]
\n
time = 2.5d
\n
}
\n
baz = {}
\n
}
\n
"
)
# vars.foobar["foo"] += {
# string = "some string, connected to another. Yeah!"
# constant = NodeName
# bool = true
# }
# vars.foobar["fooz"] += {}
# vars.foobar["bar"] = {
# numbers = [ 42, 3.141, -42, -3,141, ]
# merge_array += [ 42, 3.141, -42, -3,141, ]
# time = 2.5d
# }
# vars.foobar["baz"] = {}
is_expected
.
to
run
.
with_params
({
'vars'
=>
{
'foobar'
=>
{
'foo'
=>
{
'+'
=>
true
,
'string'
=>
'some string, connected to another. Yeah!'
,
'constant'
=>
'NodeName'
,
'bool'
=>
'true'
},
'fooz'
=>
{
'+'
=>
true
,
},
'bar'
=>
{
'numbers'
=>
[
'42'
,
'3.141'
,
'-42'
,
'-3.141'
]
,
'merge_array'
=>
[
'+'
,
'42'
,
'3.141'
,
'-42'
,
'-3.141'
]
,
'time'
=>
'2.5d'
},
'baz'
=>
{},
}
}
})
.
and_return
(
"vars.foobar[
\"
foo
\"
] += {
\n
string =
\"
some string, connected to another. Yeah!
\"\n
constant = NodeName
\n
bool = true
\n
}
\n
vars.foobar[
\"
fooz
\"
] += {}
\n
vars.foobar[
\"
bar
\"
] = {
\n
numbers = [ 42, 3.141, -42, -3.141, ]
\n
merge_array += [ 42, 3.141, -42, -3.141, ]
\n
time = 2.5d
\n
}
\n
vars.foobar[
\"
baz
\"
] = {}
\n
"
)
end
# vars = +config1
it
'assign multiple custom attributes'
do
is_expected
.
to
run
.
with_params
({
'vars'
=>
'+ config'
,
})
.
and_return
(
"vars += config
\n
"
)
# vars += config1
# vars += {}
# vars.foo = "some string"
# vars.bar += [ 42, 3.141, -42, -3.141, ]
# vars.baz["number"] -= 42
# vars.baz["floating"] += 3.141
# vars += config2
is_expected
.
to
run
.
with_params
({
'vars'
=>
[
'+ config1'
,
{},
{
'foo'
=>
'some string'
,
'bar'
=>
[
'+'
,
'42'
,
'3.141'
,
'-42'
,
'-3.141'
]
,
'baz'
=>
{
'+'
=>
true
,
'number'
=>
'- 42'
,
'floating'
=>
'+ 3.141'
,
},
},
'+ config2'
,
]
,
})
.
and_return
(
"vars += config1
\n
vars += {}
\n
vars.foo =
\"
some string
\"\n
vars.bar += [ 42, 3.141, -42, -3.141, ]
\n
vars.baz[
\"
number
\"
] -= 42
\n
vars.baz[
\"
floating
\"
] += 3.141
\n
vars += config2
\n
"
)
end
it
'arithmetic and logical expressions'
do
# result = 3 + 2 * 4 - (4 + (-2.5)) * 8 + func(3 * 2 + 1, funcN(-42)) + str(NodeName, "some string", "another string")
is_expected
.
to
run
.
with_params
({
'result'
=>
'3 + 2 * 4 - (4 + (-2.5)) * 8 + func(3 * 2 + 1, funcN(-42)) + str(NodeName, some string, another string)'
})
.
and_return
(
"result = 3 + 2 * 4 - (4 + (-2.5)) * 8 + func(3 * 2 + 1, funcN(-42)) + str(NodeName,
\"
some string
\"
,
\"
another string
\"
)
\n
"
)
# result += 3 + 2 * 4 - (4 + (-2.5)) * 8 + func(3 * 2 + 1, funcN(-42)) + str(NodeName, "some string", "another string")
is_expected
.
to
run
.
with_params
({
'result'
=>
'+ 3 + 2 * 4 - (4 + (-2.5)) * 8 + func(3 * 2 + 1, funcN(-42)) + str(NodeName, some string, another string)'
})
.
and_return
(
"result += 3 + 2 * 4 - (4 + (-2.5)) * 8 + func(3 * 2 + 1, funcN(-42)) + str(NodeName,
\"
some string
\"
,
\"
another string
\"
)
\n
"
)
# result = [ 3 + 4, 4 - (4 + (-2.5)) * 8, func(3 * 2 + 1, funcN(-42)) + str(NodeName, "some string", "another string"), ]
is_expected
.
to
run
.
with_params
({
'result'
=>
[
'3 + 4'
,
'4 - (4 + (-2.5)) * 8'
,
'func(3 * 2 + 1, funcN(-42)) + str(NodeName, some string, another string)'
]
})
.
and_return
(
"result = [ 3 + 4, 4 - (4 + (-2.5)) * 8, func(3 * 2 + 1, funcN(-42)) + str(NodeName,
\"
some string
\"
,
\"
another string
\"
), ]
\n
"
)
# result = {
# add = 3 + 4
# expr = 4 - (4 + (-2.5)) * 8
# func = func(3 * 2 + 1, funcN(-42)) + str(NodeName, "some string", "another string")
# }
is_expected
.
to
run
.
with_params
({
'result'
=>
{
'add'
=>
'3 + 4'
,
'expr'
=>
'4 - (4 + (-2.5)) * 8'
,
'func'
=>
'func(3 * 2 + 1, funcN(-42)) + str(NodeName, some string, another string)'
}
})
.
and_return
(
"result = {
\n
add = 3 + 4
\n
expr = 4 - (4 + (-2.5)) * 8
\n
func = func(3 * 2 + 1, funcN(-42)) + str(NodeName,
\"
some string
\"
,
\"
another string
\"
)
\n
}
\n
"
)
# assign where (host.address || host.address6) && host.vars.os == "Linux"
# assign where get_object("Endpoint", host.name)
is_expected
.
to
run
.
with_params
({
'assign where'
=>
[
'(host.address || host.address6) && host.vars.os == Linux'
,
'get_object(Endpoint, host.name)'
]
})
.
and_return
(
"assign where (host.address || host.address6) && host.vars.os ==
\"
Linux
\"\n
assign where get_object(
\"
Endpoint
\"
, host.name)
\n
"
)
# ignore where get_object("Endpoint", host.name) || host.vars.os != "Windows"
is_expected
.
to
run
.
with_params
({
'ignore where'
=>
[
'get_object(Endpoint, host.name) || host.vars.os != Windows'
]
})
.
and_return
(
"ignore where get_object(
\"
Endpoint
\"
, host.name) || host.vars.os !=
\"
Windows
\"\n
"
)
end
it
'disable parsing'
do
# result = "unparsed string NodeName with quotes"
is_expected
.
to
run
.
with_params
({
'result'
=>
'-:"unparsed string NodeName with quotes"'
})
.
and_return
(
"result =
\"
unparsed string NodeName with quotes
\"\n
"
)
# result = "unparsed string NodeName with quotes", ]
is_expected
.
to
run
.
with_params
({
'result'
=>
[
'-:"unparsed string NodeName with quotes"'
]
})
.
and_return
(
"result = [
\"
unparsed string NodeName with quotes
\"
, ]
\n
"
)
# result = {
# string = "unparsed string NodeName with quotes",
# }
is_expected
.
to
run
.
with_params
({
'result'
=>
{
'string'
=>
'-:"unparsed string NodeName with quotes"'
}
})
.
and_return
(
"result = {
\n
string =
\"
unparsed string NodeName with quotes
\"\n
}
\n
"
)
end
end
File Metadata
Details
Attached
Mime Type
text/x-ruby
Expires
Jun 4 2025, 6:37 PM (14 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3398660
Attached To
rSPICI Icinga 2 Puppet Module
Event Timeline
Log In to Comment