Commit graph

318 commits

Author SHA1 Message Date
Hunter Haugen
8a269c6722 Add build_csv 2014-04-08 16:38:33 -07:00
Hunter Haugen
f8f147e794 Add success/fail groups 2014-04-08 15:04:55 -07:00
Hunter Haugen
fcbc4b59a6 First set of tests 2014-04-03 16:58:12 -07:00
Ashley Penney
afb78e2b25 Add some acceptance tests for functions. 2014-04-03 16:58:12 -07:00
Yanis Guenane
d9b5e912bb (MODULES-603) Add defaults arguments to ensure_packages()
Without this patch one can not specify package resource specific
parameters. All the ensure_packages() function does it makes sure
the named packages are installed. This patch allows one to pass
default as a second argument and allow greater flexibility on
packages installations.

Use case like the following are now possible :
  * ensure_packages(['r10k', 'serverspec'], {'provider' => 'gem'})
  * ensure_packages(['ntp'], {'require' => 'Exec[foobar]'})
2014-03-30 18:47:36 -04:00
Ashley Penney
9a3107fed1 Add beaker framework.
This prepares the module for beaker acceptance tests.
2014-03-12 18:22:23 +00:00
Ashley Penney
e467d8f084 Merge pull request #220 from mediatemple/fix/master/deep_merge_fix
PUP-1724 Don't modify the paramaters to deep_merge
2014-03-11 09:31:23 -07:00
Ashley Penney
3854e076cc Numerous changes to update testing gems.
This work updates a number of Gems to the latest versions (rspec,
rspec-puppet), and updates and tweaks a bunch of tests to work
with the updated gems.
2014-03-08 00:42:51 +00:00
Martin Foot
35bf5fd8c9 Allow concat to take non-array second parameters
Also improve and extend concat tests to lock down functionality
2014-02-21 15:48:27 +00:00
Justin Burnham
c12e9afc97 PUP-1724 Don't modify the paramaters to deep_merge
Instead of modifying the first paramater of deep_merge due to the
use of the merge! function, instead use merge to return a copy of
the merged object. This allows one to continue to use the original
first parameter after the call to deep_merge.
2014-02-17 12:19:40 -08:00
Sharif Nassar
a972e0645b Remove trailing whitespace 2014-02-05 15:01:45 -08:00
David Schmitt
52fcef573f (PUP-638) Add a pick_default() function that always returns a value.
This version of pick() does not error out, instead always returning at least
the last argument, even if that too has no "real" value.
2014-01-29 09:26:35 -08:00
Andrew Parker
a2e9d005c7 Merge pull request #215 from blkperl/add_root_home_to_mavericks
(PUP-1459) Add support for root_home on OS X 10.9
2014-01-28 10:52:58 -08:00
Simon Effenberg
264dc9bbde (PUP-1195) Fix is_numeric/is_integer when checking non-string parameters
I expect a function called "is_numeric" or "is_integer" to check if a
variable is an integer or a number even if the variable passed by isn't
a string nor a number at all. Otherwise we should call them
is_string_a_number and is_string_an_integer and we have then to remove
the check for .is_a?(Number) and .is_a?(FixNum)

now checking also if it is a hex or octal number

improved/corrected checking for integer

* checking against Integer instead of Fixnum so that
  also Bignum is matching
* now .is_a? Integer is done first so this is quiet fast

Now many types of numerics are recognized.

1. Float/Integer values (signed or unsigned, with exponent or without)
2. octal and hex check
3. except hex numbers and the "0." in a float lower than 1 can be prefixed
   with a '0'.

whitespaces shouldn't be allowed as prefix/suffix

string representation of numbers should not contain any type of
whitespace.. the user is responsible to clean a string before checking
it..

fix documentation and added more checks

tried to be 99.9% backward compatible

* for now the decission is post poned if hex and octal numbers
  should be allowed or not (is_numeric)
* native Bignum is now also a valid integer class

fix problem with old 1.8 ruby and Hash.to_s/Array.to_s

In ruby < 1.9 array and hashes would be recognized as numeric
if they have a special format:

1.8:

  [1,2,3,4].to_s = "1234"
  {1=>2}.to_s    = "12"

1.9:

  [1,2,3,4].to_s = "[1, 2, 3, 4]"
  {1=>2}.to_s    = "{1=>2}"
2014-01-23 23:59:28 +01:00
William Van Hevelingen
fe676f0ac4 (PUP-1459) Add support for root_home on OS X 10.9
getent does not exist on 10.9 so this commit uses
dscacheutil to query the homedir for the root user.
2014-01-22 22:54:34 -08:00
Adrien Thebo
75341f01d9 (maint) Update ensure_package specs to confirm expected behavior
The previous behavior of the tests checked the behavior of the
underlying functions library when called with no arguments; this commit
updates the tests to conform to the functions API and test what happens
when a function is called with no args.
2014-01-15 11:04:03 -08:00
Tomas Doran
735db82bef Allow a single argument, rather than an array 2014-01-15 11:03:33 -08:00
Adrien Thebo
7085472e69 (maint) Improve test coverage for prefix and suffix 2013-12-20 15:03:40 -08:00
Andrew Parker
799e968f5c (Maint) Update stubbing to work with facter 1.7.4
Facter 1.7.4 changed how it decides on what directory to look in for
facts.d based on the user it is running as. This stubs out that bit of
code to make it think it is running as root.
2013-12-18 14:46:54 -08:00
Andrew Parker
1cf4b04b33 Merge pull request #211 from jhoblitt/function_is_bool
(#23381) add is_bool() function
2013-12-18 10:49:39 -08:00
Andrew Parker
210e3b7f6c Merge pull request #203 from dreamlibrarian/fix/is_function_available-ruby_c
calling rspec directly makes is_function_available.rb not pass ruby -c
2013-12-18 10:31:39 -08:00
Joshua Hoblitt
1077881873 (#23381) add is_bool() function 2013-12-09 11:50:03 -07:00
Tristan Smith
4241eb4806 calling rspec directly makes this not pass ruby -c. adjusting to be in line with the rest. 2013-11-20 18:30:46 -08:00
Tomas Doran
a1978698ef Fix the tests on osx 2013-11-19 18:42:19 +00:00
Justin Burnham
199ca9c78b (#20200) Add a recursive merge function.
Issue #20200 notes that the merge function does not
support nested hashes.

To prevent unintended side effects with changing merge,
add a deep_merge function instead.
2013-10-29 12:22:49 -07:00
Matthew Haughton
57a5c0b3e3 (Main) fix typo in pick error message
Update pick error message "at least one non empty value"
2013-10-29 12:01:25 -07:00
Adrien Thebo
d60d872c1a Merge branch 'pull-180'
This closes GH-180
2013-09-18 21:56:16 -07:00
Adrien Thebo
63811b9d59 (maint) Simplify validate_cmd specs 2013-09-18 21:48:45 -07:00
sgzijl
9e0d8a8e0a (#22214): close content file before executing checkscript
Right now validation seems to be done against zero byte generated temp
files. We need to close the file before executing validation against it.
2013-09-18 21:32:07 -07:00
Adrien Thebo
7ccf8cf09b Merge pull request #184 from lmello/fix_bug_20681_delete_undef_values
delete_undef_values function fix bug #20681
2013-09-18 10:08:49 -07:00
Leonardo Rodrigues de Mello
80a8b7bd1f (#20681) fix behaviour of delete_undef_values
The issue #20681 describe the error of delete() function
removing the elements from the origin array/hash/string.

This issue affected other delete functions. Because
ruby delete and delete_if functions make destructive
changes to the origin array/hash.

The delete_undef_values removed elements from the
origin array/hash and this is not the desired behaviour.

To solve this, we should dup or clone the array/hash
before using the delete or delete_if ruby functions.

We should also check if args[0] is not nil before using
dup, since dup on nil raises exception.

This fix the problem and add unit tests, so we could
enforce this behaviour and prevent regressions.
2013-09-18 11:19:52 -03:00
Adrien Thebo
c2f584d2c2 Merge pull request #183 from lmello/fix_bug_20681_delete_at
delete_at added spec to check against bug #20681
2013-09-17 11:39:29 -07:00
Adrien Thebo
1011670bad Merge pull request #182 from lmello/fix_bug_20681_delete_values
delete_values() fix bug #20681.
2013-09-17 11:35:57 -07:00
Adrien Thebo
f7f70fe9ee Merge pull request #185 from lmello/refactor_16498
(#16498) Added unit test for loadyaml function.
2013-09-17 11:33:57 -07:00
Leonardo Rodrigues de Mello
bcd84f5c3d (#16498) Added unit test for loadyaml function.
As stated on the issue #16498, it would be great to have unit tests
for all the functions.

Function loadyaml was missing a unit test. This commit added the
unit test to loadyaml function.
2013-09-17 15:16:25 -03:00
Adrien Thebo
5cc5e293cf Merge pull request #178 from lmello/fix_bug_20681
bug # 20681 delete() function should not remove elements from original list
2013-09-17 11:07:21 -07:00
Leonardo Rodrigues de Mello
b43c044581 (#20681) delete_at function unit test against issue
The issue #20681 describe the error of delete() function
removing the elements from the origin array/hash/string.

This issue affected the other delete functions.

The delete_at function is not afected by this bug, but
it did not had the unit test to check against it.

I had added the unit test so we could prevent regressions
on the future and also have better test coverage.
2013-09-17 12:09:50 -03:00
Leonardo Rodrigues de Mello
51d96088c1 (#20681) fix behaviour of delete_values
The issue #20681 describe the error of delete() function
removing the elements from the origin array/hash/string.

This issue affected other delete functions. Because
ruby delete and delete_if functions make destructive
changes to the origin array/hash.

The delete_undef_values removed elements from the
origin hash and this is not the desired behaviour.

To solve this, we should dup or clone the hash
before using the delete or delete_if ruby functions.

This fix the problem and add unit tests, so we could
enforce this behaviour and prevent regressions.
2013-09-17 12:05:23 -03:00
Adrien Thebo
ebec9de534 Merge pull request #179 from lmello/function_pick_error_msg
enhanced the error message of pick function.
2013-09-16 13:45:24 -07:00
Leonardo Rodrigues de Mello
c14cbf31e2 bug # 20681 delete() function should not remove elements from original list
The setup: list with 3 elements, delete one:
$test_list = [‘a’, ‘b’, ‘c’]
$test_deleted = delete($test_list, ‘a’)

Print out the elements in ‘test_deleted’:
notify { ‘group_output2’:  withpath => true, name     => “$cfeng::test_deleted”, }
Notice: /Stage[main]/Syslog/Notify[group_output2]/message: bc

Good!  Run-on output shows that ‘a’ was deleted

Print out the elements in ‘test_list’:
notify { ‘group_output1’: withpath => true, name     => “$cfeng::test_list”, }
Notice: /Stage[main]/Syslog/Notify[group_output1]/message: bc

WHAT!?  'a' was deleted from ‘test_list’ as well! Expected abc as output!

This behaviour is confirmed for string, hash and array.
This is fixed on this commit, I had  added two spec tests to cover that cases.

bug #20681 spec test for delete() function.

I had forgot in the last commit the spec test for hash in the
delete function.

bug # 20681 delete() function change aproach.

Instead of rejecting elements from the original list, we use
collection = arguments[0].dup .
then latter we could continue to use delete and gsub! on collection
without impact on original argument.

this is a better solution than the previous one, and works on ruby
1.8.7, 1.9.3 and 2.0.0.

The previous solution does not work on ruby 1.8.7.

delete function remove typo whitespace.

fix typo whitespaces.
2013-09-16 10:19:35 -03:00
Leonardo Rodrigues de Mello
30e994fb6e enhanced the error message of pick function.
When pick function fail return a better error message like
the other stdlib functions, indicating that the error
is on function pick.

This would help people that see the error to identity it is
related to a incorrect use of stdlib function pick, instead of having
to grep all puppet libraries and manifests source for the old message.

I had also changed the spec test.

pick function change spec  as suggested GH-179

Fix the spec test to use expect {}.to instead of lambda {}.should
as explained by Adrienthebo.

"Using expect { }.to is preferred over lambda { }.should.
 In addition it's best practice to do a string match against the
error message to ensure that we're catching the right error,
instead of any error of the right type."

Also fixed a typo on the error message, it was missing one space.

pick function stylish fix as suggested on GH179
2013-09-16 10:03:20 -03:00
Jeff McCune
948be0bb99 (maint) Improve the tests and readability of file_line
Without this patch the implementation of the file_line provider is a bit
convoluted with respect to the newly introduced "after" parameter.

This patch addresses the problem by separating out the concerns of each
case into their own methods of handling the behavior with the match
parameter, handling the behavior with the after parameter, or simply
appending the line.
2013-08-29 16:27:27 -07:00
Dan Prince
221277e852 Update file_line resource to support 'after'.
When adding new lines to a file the 'after' option can be useful
when you need to insert file lines into the middle of a file.

This is particularly helpful when using file_line with sectioned
config files.

NOTE: the after option only works when adding new lines. If you are
updating an existing (matched) line it will simply modify it in place.
This assumes it was in the right place to begin with.
2013-08-29 15:07:29 -07:00
Jeff McCune
806430224a (maint) Fix failing spec test with Puppet 3.3.0-rc2
Without this patch the stdlib spec tests are failing against recent
versions of Puppet.  The root cause of this problem is a change in the
behavior of create_resources in Puppet 6baa57b.  The change in behavior
caused the :name key to be omitted from the hash returned by
Puppet::Parser::Resource#to_hash which in turn is causing the test
failure.

This patch addresses the problem by updating the test to match the
description of the example.  Only the attribute :ensure is checked
instead of the full hash itself.
2013-08-29 13:02:31 -07:00
Adrien Thebo
6dd6d060df Merge pull request #172 from ptomulik/fix/delete_xxx_spec
small fix to delete_values_spec.rb and README.markdown
2013-08-28 15:39:32 -07:00
Paweł Tomulik
bb9f7d1726 small fix to delete_values_spec.rb and README.markdown 2013-08-14 02:23:36 +02:00
Adrien Thebo
200e585ea7 (maint) refactor validate_slength tests 2013-08-12 12:55:46 -07:00
Adrien Thebo
0a02295c42 Merge pull request #167 from mhellmic/minlength
extend the validate_slength function to accept a minimum length
2013-08-06 09:48:44 -07:00
Martin Hellmich
0206d367c0 changed the validate_slength function to accept a min length
An optional third parameter can be given a min length. The function
then only passes successfully, if all strings are in the range
min_length <= string <= max_length

update and fix function and unit tests

the check for the minlength has to be written differently
because 0 values should be possible. We now check
a) if the input is convertible, and throw a ParseError and
b) if the input .is_a?(Numeric) and ask for a positive number
it's not as clean as for maxlength, but keeps a similar behaviour

refined the error checking for the min length

try to convert to Integer(args[2]) and fail,
if it's not possible

changed the tests accordingly to the new parameter checking
2013-08-06 10:05:16 +02:00
Paweł Tomulik
2069415204 added delete_values() and delete_undef_values() functions 2013-08-05 22:12:26 +02:00
Tomas Doran
b2e23dc65b Adjust to use default URI.escape escape list
Conform to RFC per comments on: https://github.com/puppetlabs/puppetlabs-stdlib/pull/164

Conflicts:
	lib/puppet/parser/functions/uriescape.rb
	spec/unit/puppet/parser/functions/uriescape_spec.rb
2013-07-22 13:12:28 -07:00
Alex O'Rielly
964a9ad619 (#21416) Allow file_line to match multiple lines
Without this commit the file_line type will outright fail if multiple
lines match the given regex. This commit allows the file_line type and
provider to optionally match and modify all matching lines.

Changeset rebased into a single commit by Adrien Thebo <adrien@puppetlabs.com>
2013-07-11 16:25:56 -07:00
Adrien Thebo
ca7633c0e4 Merge pull request #158 from wfarr/validate_ip
[#20862] Add functions to validate ipv4 and ipv6 addresses
2013-06-07 15:06:41 -07:00
Adrien Thebo
77768e5d8d (maint) Remove syntax decoration from range_spec 2013-05-28 11:17:00 -07:00
Adrien Thebo
65380bcdfb (maint) Clean up range_spec error expectation
Replace `lambda` with `expect` for making an error expectation

Add an explicit error message in expectation
2013-05-28 11:14:28 -07:00
Adrien Thebo
dd0a4220d5 (maint) Use present tense in range_spec messages 2013-05-28 11:13:20 -07:00
Adrien Thebo
1fcb854f15 (maint) split up range spec with describe blocks 2013-05-28 11:11:50 -07:00
Adrien Thebo
0f2d69fdfd Merge remote-tracking branch 'pr/56' into pull-56
Conflicts:
	lib/puppet/parser/functions/range.rb
	spec/unit/puppet/parser/functions/range_spec.rb
2013-05-28 11:07:41 -07:00
fiddyspence
3707c47dcd Adding base64 function
Adding base64 function and spec test.  Included a bonus fix to
validate_slength_spec.rb to put the expectation message in the right
place.
2013-05-24 16:33:24 +01:00
Will Farrington
e0fd7299f6 Don't run certain tests under 1.8.7 2013-05-22 17:43:37 -07:00
Will Farrington
5d5796a7d5 Update ipv6 examples 2013-05-22 17:37:08 -07:00
Will Farrington
cf37a128a0 Add functions to validate ipv4 and ipv6 addresses 2013-05-22 17:10:45 -07:00
Hailee Kenney
a2abfb9894 Merge pull request #155 from AlexCline/feature/master/array_comparison_functions
(#20684) Add array comparison functions, difference, intersection and union
2013-05-15 13:56:15 -07:00
Adrien Thebo
dad3a2948f Merge pull request #147 from mhellmic/master
don't fail on undef variable in merge
2013-05-15 10:58:04 -07:00
Alex Cline
737aa31546 (#20684) Add array comparison functions, difference, intersection and union.
Included is code, tests and documentation for the difference, intersection
and union functions for comparing arrays.
2013-05-13 12:14:15 -04:00
Martin Hellmich
b975bd66aa Added rspec tests for the new behaviour of merge accepting empty strings
added test that '' is accepted
changed a test that a number is correctly rejected with a type error
2013-05-08 18:24:46 +02:00
Jeff McCune
226c191e27 Merge branch 'fix_facts_dot_d_with_pe'
* fix_facts_dot_d_with_pe:
  (maint) Indent facter_dot_d with 2 spaces
  (#20582) Restore facter_dot_d to stdlib for PE users
  Revert "Revert "Revert "Merge branch 'hkenney-ticket/master/2157_remove_facts_dot_d'"""
  (maint) Update Gemfile with GEM_FACTER_VERSION

closes #153
2013-05-07 12:10:06 -07:00
Jeff McCune
3b887c880c (#20582) Restore facter_dot_d to stdlib for PE users
Without this patch Puppet Enterprise users who install the most recent
version of stdlib lose the ability to resolve certain facts critical to
the operation of Puppet Enterprise.  These facts are defined externally
in the file
`/etc/puppetlabs/facter/facts.d/puppet_enterprise_installer.txt`.
As an example, Puppet Enterprise catalogs fail to compile if the
`fact_stomp_server`, and `fact_stomp_port` facts are not defined.

`facter_dot_d` was removed from stdlib version 4 because Facter version
1.7 now supports external facts defined in
`/etc/puppetlabs/facter/facts.d/puppet_enterprise_installer.txt`.
Puppet Enterprise does not yet include Facter 1.7, however.  The most
recent PE release, 2.8.1, includes Facter 1.6.17.  With this version of
Facter, users who replace the version of stdlib that ships with PE with
the most recent version from the Forge will lose the ability to resolve
facts from
`/etc/puppetlabs/facter/facts.d/puppet_enterprise_installer.txt`.

This patch addresses the problem by detecting if Facter version < 1.7 is
loaded.  If so, then the facter_dot_d.rb facts will be defined using the
stdlib custom fact.  If Facter >= 1.7 is being used then stdlib will not
define external facts.
2013-05-07 09:42:35 -07:00
Alex Cline
b33cc24a3c Refactor ensure_resource expectations
This splits out the ensure_resource expectations into separate
blocks for clarity.  Per adrienthebo's recommendation.
2013-05-06 15:30:35 -04:00
Alex Cline
e08734af5a (#20548) Allow an array of resource titles to be passed into the ensure_resource function
This patch allows an array of resource titles to be passed into
the ensure_resource function.  Each item in the array will be
checked for existence and will be created if it doesn't already
exist.
2013-05-03 15:47:27 -04:00
Raphaël Pinson
2ba9e4721b Add a dirname function 2013-05-02 15:17:35 +02:00
Jeff McCune
d2e692dce3 Add behavior example for anchor refresh propagation
Without this patch we don't have a spec test to make sure the anchor
resource type passes notify events along.  This patch addresses the
problem by using RSpec Puppet to build a catalog, apply the catalog,
then pull a resource out of the transaction and make sure the resource
was triggered.
2013-04-11 17:55:40 -07:00
Jeff McCune
435226abfd (maint) Add the behavior for count() with arrays and hashes
Without this patch the expected behavior of the count() function when
dealing with an out of bound array index and with a hash key that does
not exist is implicitly encoded in the spec examples.  This is a problem
because the expected behavior is not clear for something similar to the
following example:

    node default {
      $ary = [ 1, 2, 3 ]
      $ary_undef = $ary[100]
      $hsh = { 'one' => 1 }
      $hsh_undef = $hsh['dne']
      $count = count(['hi', $ary_undef, $hsh_undef])
      notice "Count is ${count}"
    }

This patch addresses the problem by making the expected behavior
explicit in the examples.
2013-04-10 14:33:10 -07:00
Erik Dalén
f28550e789 Add a count function
Similar to the ruby count method on arrays.
2013-04-10 14:39:25 +02:00
Amos Shapira
7a2fb80834 (#19998) Implement any2array
This change is to implement a new function "any2array", which will take any
argument or arguments and create an array which contains it. If the argument
is a single array then it will be returned as-is. If the argument is a single
hash then it will be converted into an array. Otherwise (if there are more than
one argument, or the only argument is not an array or a hash) the function will
return an array containing all the arguments.
2013-04-03 14:05:20 -07:00
Steve Huff
c372f17770 Cleanup per adrianthebo suggestions
* use Float() to process string arguments
* get rid of doubly nested arrays
* removing needless ternary operator
* improving error message handling
2013-04-01 11:44:09 -04:00
Steve Huff
8d217f0012 (19864) num2bool match fix
This is a bit more heavy-handed than I might like, but it does appear to
do the right things:

* accepts numeric input appropriately, truncating floats
* matches string input against a regex, then coerces number-looking
  strings to int
* makes a best effort to coerce anything else to a string, then subjects
  it to the same treatment
* raises an error in the event of incorrect number of arguments or
  non-number-looking strings

I've also included some additional unit tests.
2013-03-29 15:06:36 -04:00
Steve Huff
4a5218a8af Reworked number-handling logic
No more coercing to String and regex matching.  Instead, we now coerce
to Integer at the beginning or raise an error if we cannot coerce to
Integer.

A consequence of this change is that the function will now accept
blatantly non-numeric strings as input, and return false.  This seems a
bit goofy to me, but it's how String#to_i works.  If we really don't
like this, then I'm open to suggestions.
2013-03-29 12:54:37 -04:00
Steve Huff
e6916f83fd Enable num2bool to accept numeric input
Also ignore rspec fixtures directory
2013-03-29 12:53:56 -04:00
Adrien Thebo
4078a6ff44 Merge branch '4.x' 2013-03-27 14:04:19 -07:00
Adrien Thebo
87c0f0c454 Merge branch '2.x' into 3.x 2013-03-27 14:04:00 -07:00
Erik Dalén
ff5dd5d75a Allow comparisons of Numeric and number as String
Puppet passes numbers as String to functions, but it makes more sense to
compare them as Numeric.
But sometimes Puppet passes them as the wrong type, see:
https://projects.puppetlabs.com/issues/19812
2013-03-27 14:03:31 -07:00
Richard Soderberg
88a93ac6cd add suffix function to accompany the prefix function 2013-03-26 15:46:55 -07:00
Kristof Willaert
05273419e1 Add floor function implementation and unit tests 2013-03-19 10:00:57 +01:00
Eric Shamow
961dcab15d (#13610) Add is_function_available to stdlib
This function provides a simple wrapper around
Puppet::Parser::Functions.function for access within Puppet manifests.
This will allow users to check whether or not a plugin or functionality
such as hiera is installed on the server.
2013-03-18 15:44:50 -07:00
Adrien Thebo
6dfd7f6b73 Merge branch '4.x' 2013-03-18 15:38:14 -07:00
Adrien Thebo
c0a0682706 Merge branch '2.x' into 3.x 2013-03-18 15:37:56 -07:00
Justin Lambert
5d5a4d466e str2bool should return a boolean if called with a boolean 2013-03-18 15:37:36 -07:00
Uwe Stuehler
5a11279cc5 Fix number of arguments check in flatten()
The function only uses the first argument, so raise an error with
too few arguments *and* with too many arguments.
2013-03-18 15:07:13 -07:00
Adrien Thebo
c12d3d7d51 Merge branch '2.x' into 3.x 2013-03-18 15:06:07 -07:00
Uwe Stuehler
e80207bede Fix number of arguments check in flatten()
The function only uses the first argument, so raise an error with
too few arguments *and* with too many arguments.
2013-03-18 15:04:50 -07:00
Jeff McCune
a45d4f1307 Revert "Merge pull request #130 from jhoblitt/has_element"
This reverts commit f7a18189ec, reversing
changes made to 36a7b29630.

I'm reverting this change because of concerns raised by Peter Meier that
it duplicates the "in" operator in the DSL.  The "in" operator is new
information that I did not posses when I made the decision to merge.
Because of this new information I'm un-merging and continuing the
discussion in the comments of
https://projects.puppetlabs.com/issues/19272

Reference: GH-130
2013-02-15 11:57:42 -08:00
Joshua Hoblitt
95cf3fed68 (#19272) Add has_element() function
It is exceptionally difficult to determine if an array contains an element matching a specific value without an iteration or loop construct.

This function is the Puppet equivalent of Array.includes?(foo) in Ruby.  The implementation is a verbatim copy of has_key() with the minor modifications needed to support arrays instead of hashes.
2013-02-14 12:06:21 -07:00
Adrien Thebo
36a7b29630 Merge branch 'pull-126' 2013-02-12 10:20:22 -08:00
fatmcgav
3cef5d9e33 (#19201) Add concat function to join two arrays
Without this patch applied there is no easy way to append one array to
another.  This is a problem because it is often desirable to join two
arrays without flattening the contents into a single, one dimensional
array.

This patch addresses the problem by adding a `concat()` function which
takes two arguments.  The arguments will be concatenated together and a
new array returned to the caller.

Reviewed-by: Jeff McCune <jeff@puppetlabs.com>
2013-02-12 10:00:09 -08:00
Raphaël Pinson
683ac8f8aa validate_cmd: Use Puppet::Util.execute 2013-02-06 18:03:11 +01:00
stephen
5f22933e75 ammend .should raise_error to .to raise_error 2013-02-06 08:12:42 -08:00
Raphaël Pinson
3a97c2314c Add validate_augeas function 2013-01-18 22:02:13 +01:00
Raphaël Pinson
6902cc582e Add validate_cmd function 2013-01-18 09:06:02 -08:00
Jaka Hudoklin
20e0e07090 Add getparam function to get defined resource parameters
As far as i know there's no other puppet-dsl-like way to get parameter of
defined resource, so that's why i implemented getparam function, which takes
resource reference and parameter name and returns parameter value.

    Here's another example why this function is really useful:

    define config($path, $config_param1, $config_param2) { }

    define example_resource($config) {
        $path = getparam($config, "path")

        notice("Path is $path")
    }

    define example_resource2($example_resource, $config = getparam($example_resource, "config")) {
        $config_param1 = getparam($config, "config_param1")

        notice("Config parameter is $config_param1")
    }

    define example_resource3($example_resource, $config = getparam($example_resource, "config")) {
        $config_param2 = getparam($config, "config_param2")

        notice("Config parameter is $config_param2")
    }

    class test_getparam {

        config { "config_instance":
            path => "/some/config/path",
            config_param1 => "someconfigtext1",
            config_param2 => "someconfigtext2",
        }

        example_resource { "example_resource_instance":
            config => Config["config_instance"]
        }

        example_resource2 { "example_resource_instance":
            example_resource => Example_resource["example_resource_instance"]
        }

        example_resource3 { "example_resource_instance":
            example_resource => Example_resource2["example_resource_instance"]
        }
    }

    class { "test_getparam": }
2013-01-09 17:51:12 -08:00