Commit graph

512 commits

Author SHA1 Message Date
Hunter Haugen
7c8ae311ca (MODULES-1473) Deprecate type() function for new parser
The `type()` function will cease to work on the new parser because 'type'
is a reserved keyword. The `type3x()` function may be used to continue
similar functionality, but will be deprecated in favor of the built-in
typing system.

The `type_of()` function has been included to introspect types in the
new parser.
2015-01-07 16:40:06 -08:00
Travis Fields
8ec6f8dbfd MODULES-1606 add ability to pass array to delete for items to delete 2014-12-19 10:26:01 -08:00
Morgan Haskel
31a6d89410 Fix bad check in test 2014-12-18 16:20:02 -08:00
Hunter Haugen
1ae0a10707 Merge pull request #388 from mhaskel/merge_4.5.x_into_master
Merge 4.5.x into master
2014-12-18 15:55:33 -08:00
Peter Souter
cc8b147b5d (MODULES-1582) Specs for the new % placeholder
These specs are pretty much the same as the originals, but now check that the output has the correct replacement for file location
2014-12-18 23:08:33 +00:00
Morgan Haskel
696c89de99 Merge pull request #372 from poikilotherm/feature/master/validate_absolute_path_allow_arrays
Allow array of pathes in validate_absolute_path
2014-12-17 14:19:30 -08:00
Morgan Haskel
841b0df210 Merge pull request #368 from rfugina/basename
Basename implementation
2014-12-17 11:00:23 -08:00
Rob Fugina
2a3babc348 Added type checks for dirname(), and additional tests 2014-12-17 12:55:48 -06:00
Rob Fugina
ef3d42f7bb Added basename() based on Ruby's File.basename
Based on dirname code.  Includes RSpec tests and docs.
2014-12-17 12:39:40 -06:00
Hunter Haugen
c6c203fca8 Remove line match validation
The `match` attribute was validated to match `line`, except that in many
cases (even the example given in the docs) a user would want to match a
line entirely different from the new line.

See comments on the original commit
a06c0d8115
and ask
https://ask.puppetlabs.com/question/14366/file_line-resource-match-problems/
for further examples of confusion.
2014-12-16 15:05:31 -08:00
Oliver Bertuch
260c1f4b92 Add new functions validate_numeric() and validate_integer(). 2014-12-04 22:33:15 +01:00
Peter Souter
368c97f080 (MODULES-444) - Check for accepting > 2 args 2014-12-04 14:27:55 +00:00
Peter Souter
7a1c4a6d9e (MODULES-444) Change test to > 2 arguments
Also add extra test for just 1 argument
2014-12-04 14:27:38 +00:00
Peter Souter
5e49c50458 (MODULES-444) Acceptance for multiple arrays
Acceptance test to take multiple arrays for concatenation
2014-12-04 14:15:33 +00:00
Peter Souter
7c570f75a5 (MODULES-444) Acceptance test for primitives
`concat` should be able to concat arrays and primitives
2014-12-04 14:15:03 +00:00
Peter Souter
ed192a0464 (MODULES-444) Add specs for new behaviour
`concat` can now take multiple arguments
2014-12-04 14:12:55 +00:00
Oliver Bertuch
89995e4db0 Allow array of pathes in validate_absolute_path 2014-11-25 12:45:23 +01:00
Hunter Haugen
fb42396c75 Merge pull request #319 from Spredzy/member_array_in_array
(MODULES-1329) Allow member to look for array
2014-11-13 12:27:14 -08:00
Hunter Haugen
b6830f1ade Merge pull request #365 from dalen/range-integers
Make the range function work with integers
2014-11-13 10:16:21 -08:00
Yanis Guenane
c9f906f803 (MODULES-1329) Allow member function to look for array
Currently, the member function allows one to only find if a variable
is part of an array. Sometimes it is useful to find if an array is part
of a bigger array for validation purpose.
2014-11-12 14:40:34 -05:00
Erik Dalén
af0a2779cb Add range tests for numeric with step and mixed arguments 2014-11-12 16:52:36 +01:00
Erik Dalén
ce995e15d5 Make the range function work with integers
This is needed for the future parser which actually treats numbers as
numbers and strings as strings. With this patch you can use range(1,5)
instead of having to quote them like range('1','5').
2014-11-12 16:02:05 +01:00
Travis Fields
3584485902 Fix exclude windows test on ensure_package
Update to fix ensure_resource as well
2014-11-11 16:41:53 -08:00
Hunter Haugen
970141e36a Correct type() logic
It should NOT run if the future parser is enabled
2014-11-11 10:46:01 -08:00
Travis Fields
992ed8ffa8 Remove windows from ensure_package and ensure_resource testing 2014-11-10 16:34:05 -08:00
Morgan Haskel
850297b560 Merge pull request #354 from puppetlabs/4.3.x
4.3.x
2014-11-10 11:10:41 -08:00
Travis Fields
406e9dbda2 Merge pull request #343 from zacharyalexstern/fix_to_bytes
Added correct converstions for PB and EB.
2014-11-07 13:42:48 -08:00
Morgan Haskel
03f0ecd128 Merge pull request #350 from cyberious/modules1413
MODULES-1413 Add ability for member to take numeric objects
2014-11-04 15:29:25 -08:00
Travis Fields
f19aea5a75 MODULES-1413 Ability to for future parser to use member with FixNum types 2014-11-04 14:33:34 -08:00
Travis Fields
4bff0d2d61 Merge branch '4.3.x'
Conflicts:
	spec/acceptance/ensure_packages_spec.rb
	spec/acceptance/ensure_resource_spec.rb
2014-11-04 14:17:03 -08:00
Travis Fields
26e864f224 Fix the unless for test cases on ensure_package and ensure_resource
Conflicts:
	spec/acceptance/ensure_packages_spec.rb
	spec/acceptance/ensure_resource_spec.rb
2014-11-04 10:45:13 -08:00
Travis Fields
35c2dc7ca3 Merge branch '4.3.x' 2014-10-30 10:23:12 -07:00
Travis Fields
6c7da72c0f Fix validate_cmd, previous addition of SystemCallError only works for Puppet 3.7, previous version throw different exception. Wrapping in generic Exception catch all 2014-10-29 20:03:07 -07:00
Travis Fields
2b1cc82d24 Add windows test exclusion to ensure_resource 2014-10-28 16:43:15 -07:00
Travis Fields
9f68fd300f Fixed a mistake where we were trying to touch a host file using the default which was not relavent to the host we were modifying 2014-10-28 16:10:50 -07:00
Travis Fields
5497f83507 Fix logic issue with not including windows for testing ensure_packages as ruby and gem are not on the install path 2014-10-28 15:35:56 -07:00
Travis Fields
a6f3f781d1 Merge remote-tracking branch 'origin/4.3.x' back to master 2014-10-28 15:31:37 -07:00
Travis Fields
51f1d574d9 Fix testcases for Future Parser and resolve issue with values_at in assuming that it was dealing with a string 2014-10-28 15:27:24 -07:00
Zachary Alex Stern
9295d0d5ca Added correct converstions for PB and EB.
* We were converting Exabytes to bytes as Petabytes.
 * Updated tests to cover ever unit.
 * Added note that we're going by the old, inaccurate definitions of
   Kilobytes, Megabytes, etc, in that we treat them as powers of 2.
2014-10-28 13:14:06 -07:00
Mark Chappell
e2d7f3bb89 (MODULES-707) chomp() fails because generate() no longer returns a string
We need to use

  unless value.is_a?(String) || value.is_a?(Array)

rather than

  klass = value.class
  unless [String, Array].include?(klass)

because the klass version enforces type checking which is too strict, and does
not allow us to accept objects wich have extended String (or Array).

For example, generate() function now returns Puppet::Util::Execution::ProcessOutput
which is just a very simple extension of String.  While this in it's self was
not intentional (PUP-2306) it is not unreasonable to cope with objects which
extend Strings
2014-09-22 19:49:50 +02:00
Hunter Haugen
cf8d144caf Remove simplecov
simplecov 0.9 dropped ruby 1.8 support, and stdlib is one of the oddball
modules that uses it. So we could probably just remove it and be okay.

(cherry picked from commit a7c129b22d)
2014-09-16 12:01:24 -07:00
Morgan Haskel
2023692fc9 Update spec_helper for more consistency 2014-08-28 18:30:39 -04:00
Hunter Haugen
a7c129b22d Remove simplecov
simplecov 0.9 dropped ruby 1.8 support, and stdlib is one of the oddball
modules that uses it. So we could probably just remove it and be okay.
2014-08-05 11:28:18 -07:00
Hunter Haugen
2ba0e375e2 Merge branch '4.3.x' 2014-08-05 10:55:58 -07:00
Spencer Krum
a6ad0af08e Introduce test for array destruction
It was discovered that the concat array modifies the arrays passed to it
as an argument as a side effect. This test will ensure that doesn't
happen again.
2014-07-31 11:23:34 -07:00
Hunter Haugen
07462f2c36 AIX has no facter network support
These functions take advantage of IP fact information and AIX does not
appear to support dynamic interface detection in facter.
2014-07-08 13:45:36 -07:00
Hunter Haugen
ec607827ad Gotta single quote yer typewriter buttons 2014-06-26 13:55:57 -07:00
Hunter Haugen
1b893ff653 Need quotes for spaces in path 2014-06-26 13:17:07 -07:00
Hunter Haugen
b93f71f0ce has_ip_network doesn't work on windows either 2014-06-26 13:12:39 -07:00
Colleen Murphy
2fefd9c1e0 Sync files 2014-06-25 18:00:57 -07:00
Hunter Haugen
05b79dcabb Disable windows network stuff and quote path 2014-06-25 10:16:06 -07:00
Hunter Haugen
0cac9fd048 Not enough escape velocity 2014-06-24 15:03:58 -07:00
Hunter Haugen
ca35be6480 Fix pe facts and slashes 2014-06-24 11:37:34 -07:00
Travis Fields
eb507c9a54 Fixed fqdn,getparam and has_interface_with spec tests 2014-06-23 23:27:59 -07:00
Hunter Haugen
0427248cf0 Merge pull request #283 from cyberious/4.3.x
Add windows support and work around issue with SCP_TO on windows systems
2014-06-23 18:58:37 -07:00
Travis Fields
78f5141290 Removed platform check for facts.d mkdir 2014-06-23 18:30:42 -07:00
Travis Fields
0199e2396a Add windows support and work around issue with SCP_TO on windows systems 2014-06-23 16:59:46 -07:00
Hunter Haugen
f7b7c4a6ec Windows needs a tmpdir path 2014-06-23 15:13:29 -07:00
Travis Fields
d38ccfc9d2 Merge pull request #280 from hunner/win_aug
Augeas isn't present on windows
2014-06-23 13:51:33 -07:00
Hunter Haugen
280d808eb4 Augeas isn't present on windows 2014-06-23 13:50:24 -07:00
Hunter Haugen
4b7162896a OS X also has lo0 and can't manage user homedirs 2014-06-23 13:45:06 -07:00
Travis Fields
24a6fecc78 Add windows Nodesets and remove Beaker from Gemfile 2014-06-20 16:39:15 -07:00
Hunter Haugen
7eda161be8 Patch ensure_* tests 2014-06-20 10:41:43 -07:00
Hunter Haugen
4523bc50ca Merge branch 'master' into 4.3.x 2014-06-19 16:25:16 -07:00
Hunter Haugen
197e2d7e70 (FM-1587) Fix test issues on solaris 10
- ensure_packages fails because Error: Sun packages must specify a package source
- ensure_resource fails for the same reason
- get_module_path fails because the modulepath is different
- has_interface_with fails because the interface is lo0 not lo
2014-06-19 15:38:23 -07:00
Raphaël Pinson
2062f9734b Add private() function 2014-06-11 16:35:32 +02:00
Ashley Penney
6287a200af Convert specs to RSpec 2.99.0 syntax with Transpec
This conversion is done by Transpec 2.2.1 with the following command:
    transpec spec/functions

* 345 conversions
    from: obj.should
      to: expect(obj).to

* 122 conversions
    from: == expected
      to: eq(expected)

* 85 conversions
    from: lambda { }.should
      to: expect { }.to

* 22 conversions
    from: be_true
      to: be_truthy

* 16 conversions
    from: be_false
      to: be_falsey

* 11 conversions
    from: pending
      to: skip

* 9 conversions
    from: it { should ... }
      to: it { is_expected.to ... }

* 5 conversions
    from: =~ [1, 2]
      to: match_array([1, 2])

* 2 conversions
    from: =~ /pattern/
      to: match(/pattern/)

* 2 conversions
    from: obj.should_not
      to: expect(obj).not_to

For more details: https://github.com/yujinakayama/transpec#supported-conversions
2014-06-04 14:38:37 -04:00
Ashley Penney
d65d2354a7 Convert specs to RSpec 2.99.0 syntax with Transpec
This conversion is done by Transpec 2.2.1 with the following command:
    transpec spec/unit

* 53 conversions
    from: obj.should
      to: expect(obj).to

* 19 conversions
    from: == expected
      to: eq(expected)

* 5 conversions
    from: lambda { }.should
      to: expect { }.to

* 2 conversions
    from: be_true
      to: be_truthy

For more details: https://github.com/yujinakayama/transpec#supported-conversions
2014-06-04 14:37:45 -04:00
Morgan Haskel
af71faa247 Merge pull request #265 from apenney/fix-tests
Further fixes to tests for 14.04.
2014-06-03 15:01:12 -04:00
Ashley Penney
6010e9bd93 Further fixes to tests for 14.04. 2014-06-03 14:52:10 -04:00
Morgan Haskel
a364605f3b Merge pull request #264 from apenney/fixes-for-tests
Fixes for PE3.3.
2014-06-03 11:15:20 -04:00
Ashley Penney
08f7553fb6 Fixes for PE3.3. 2014-06-03 11:11:08 -04:00
Ashley Penney
0cda858744 Merge pull request #258 from mckern/enhancement/master/camelcasedembools
(MODULES-905) Narrow the confinement in bool2str
2014-05-15 21:48:40 -04:00
Ryan McKern
557d38bdc6 (MODULES-905) Extend spec tests for bool2str
The extended spec tests validate that the common types of values
that could be passed to bool2str() are rejected.
2014-05-15 16:45:02 -07:00
Ashley Penney
c5b06f9bbc Revert "Merge pull request #256 from stbenjam/2571-before"
This reverts commit 8499ebdb7f, reversing
changes made to 08b00d9229.
2014-05-15 17:28:59 -04:00
Ashley Penney
430d821ad3 Merge pull request #255 from mckern/enhancement/master/camelcasedembools
(MODULES-905) Add bool2str() and camelcase() for string manipulation
2014-05-15 17:03:18 -04:00
Stephen Benjamin
6eaa592cd8 (PUP-2571) add 'before' functionality to file_line
file_line supports adding lines after a match, but there are use cases when
having "before" would be useful. For example, in Debian-based OS's, the last
line of /etc/rc.local is "exit 0" it's an incredible pain to deal with
that scenario today.

This commit adds a 'before' parameter to the file_line type, and implements
it for the ruby provider.
2014-05-14 20:33:57 +02:00
Ryan McKern
0761fcf043 (maint) Add bool2str & camelcase spec tests 2014-05-13 15:46:50 -07:00
Ashley Penney
14c9155745 Prepare a 4.2.1 release. 2014-05-09 16:57:32 +02:00
Hunter Haugen
0804121719 Fix the stdlib functions that fail tests 2014-05-08 14:55:23 -07:00
Hunter Haugen
96e43e69d8 Move unit tests to spec/functions
rspec-puppet matchers are defined for tests which exist in
spec/functions, but the function unit tests lived in
spec/unit/puppet/parser/functions. This moves them to the correct place
for using rspec-puppet
2014-05-08 10:47:24 -07:00
Hunter Haugen
c66a2e4f49 Add mode +x to spec .rb files 2014-05-07 15:00:30 -07:00
Hunter Haugen
78982c9238 Move the 4 misplaced tests 2014-05-07 15:00:30 -07:00
Hunter Haugen
890ef5c471 Adding more spec coverage 2014-05-07 15:00:30 -07:00
Andrea Veri
09f892023c Add the missing shebangs and fix the wrong ones for rpmlint to stop complaining loudly 2014-05-07 11:49:25 +02:00
Hunter Haugen
226cc7653c Update build_csv to understand contexts 2014-05-02 13:44:20 -07:00
Hunter Haugen
af49ef4ca2 Fix the validate_augeas beaker tests 2014-05-02 12:56:22 -07:00
Hunter Haugen
80590a9bfe Add more specs 2014-05-01 14:07:54 -07:00
Ashley Penney
f8bfe46bbf Merge pull request #243 from hunner/add_beaker
Add beaker tests for functions.
2014-04-28 14:55:29 -04:00
Ashley Penney
0b59dfe642 Merge pull request #222 from mfoo/fix/master/concat-primitives
Allow concat to take non-array second parameters
2014-04-24 13:41:42 -04:00
Ashley Penney
f42fc4bfd8 Merge pull request #238 from Spredzy/add_default_ensure_packages
(MODULES-603) Add defaults arguments to ensure_packages()
2014-04-24 13:38:07 -04:00
Ashley Penney
68acb59bf7 Adjust the regular expression for facts.
Previously this was incorrectly handling facts that were of the form
foo=1+1=2 due to the ='s in the actual fact contents.  Fix this and
add tests to try and prevent regressions.
2014-04-22 23:15:16 +02:00
Kylo Ginsberg
b691be7ea9 (maint) Remove facter versions test
This test attempts to emulate various versions of facter, but is
still dependent on the version of facter it is running against. The
immediate symptom was that the test breaks with facter 2.0.1 because
it adds another external facts search directory.

I tried a couple ways to stub this but allowing it to pretend
to run against one set of facters, while actually running against
one real facter (which might itself be one of several versions)
eluded me.

So this patch just removes the test.
2014-04-16 12:30:24 -07:00
Hunter Haugen
90222959b1 Adding more tests 2014-04-09 14:35:34 -07:00
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
Jeff McCune
388cfa547d Merge branch '4.x'
* 4.x:
  Add test/validation for is_float if created from an arithmetical operation
  Add test/validation for is_integer if created from an arithmetical operation
  Add test/validation for is_numeric if created from an arithmetical operation
2013-01-03 13:39:42 -08:00
stephen
a773281760 Add test/validation for is_float if created from an arithmetical operation 2013-01-03 13:37:55 -08:00
stephen
b86f5dc129 Add test/validation for is_integer if created from an arithmetical operation 2013-01-03 13:37:55 -08:00
stephen
190b9438c5 Add test/validation for is_numeric if created from an arithmetical operation 2013-01-03 13:37:55 -08:00
Jeff McCune
bdef98d632 Merge branch '4.x'
* 4.x:
  Add reject() function
2012-11-28 14:29:39 -08:00
Jeff McCune
16fe71867c Merge branch '2.x' into 3.x
* 2.x:
  Add reject() function
2012-11-28 14:29:14 -08:00