Skip to content

Commit

Permalink
Add some tests of writing functions in the puppet language
Browse files Browse the repository at this point in the history
  • Loading branch information
nfagerlund committed Sep 22, 2015
1 parent 07d7837 commit 1ac91ea
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
31 changes: 31 additions & 0 deletions functions_in_puppet.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function none::square_me(Numeric $number, Numeric *$numbers) {
if $numbers != [] {
$all = [$number, $numbers].flatten
$all.map |$x| {$x * $x}
}
else {
$number * $number
}
}

notice( spew( none::square_me(200) ))
# Notice: Scope(Class[main]): [40000]
# [Fixnum]

#notice( spew( square_me('NaN') ))
# Error: Evaluation Error: Error while evaluating a Function Call, 'square_me' parameter 'number' expects a Numeric value, got String at /Users/nick/Documents/manifests/functions_in_puppet.pp:7:15 on node magpie.lan

notice( spew( none::square_me(200, 300, 400) ))
# Notice: Scope(Class[main]): [[40000, 90000, 160000]]
# [Array]

# Cool.

function make_resource(String $thing) {
file {"/tmp/$thing":
ensure => file,
content => "made by function thingy thing.",
}
}

notice( spew( make_resource("hey_hey_hey_hi") ))
25 changes: 25 additions & 0 deletions functions_in_puppet_in_module.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
notice( spew( functionbucket::square_me(200) ))
# Notice: Scope(Class[main]): [40000]
# [Fixnum]

#notice( spew( functionbucket::square_me('NaN') ))
# Error: Evaluation Error: Error while evaluating a Function Call, 'square_me' parameter 'number' expects a Numeric value, got String at /Users/nick/Documents/manifests/functions_in_puppet.pp:7:15 on node magpie.lan

notice( spew( functionbucket::square_me(200, 300, 400) ))
# Notice: Scope(Class[main]): [[40000, 90000, 160000]]
# [Array]

# notice( spew( functionbucket::square_me(200, 300, 'NaN', 500) ))
# Error: Evaluation Error: Error while evaluating a Function Call, 'functionbucket::square_me' parameter 'numbers' expects a Numeric value, got String at /Users/nick/Documents/manifests/functions_in_puppet_in_module.pp:12:15 on node magpie.lan

# Cool.

# include at_tester
# notice( functionbucket::default_value() )

class hey {
$fqdn = "overridden"
notice( functionbucket::default_value() )
# Notice: Scope(Class[Hey]): wren
}
include hey

0 comments on commit 1ac91ea

Please sign in to comment.