summaryrefslogtreecommitdiff
path: root/code/environments/production/modules/stdlib/spec/functions
diff options
context:
space:
mode:
Diffstat (limited to 'code/environments/production/modules/stdlib/spec/functions')
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/abs_spec.rb45
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/any2array_spec.rb20
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/any2bool_spec.rb41
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/assert_private_spec.rb41
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/base64_spec.rb60
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/basename_spec.rb19
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/bool2num_spec.rb14
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/bool2str_spec.rb16
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/camelcase_spec.rb17
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/capitalize_spec.rb15
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/ceiling_spec.rb12
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/chomp_spec.rb25
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/chop_spec.rb25
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/clamp_spec.rb16
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/concat_spec.rb28
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/convert_base_spec.rb24
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/count_spec.rb23
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/deep_merge_spec.rb58
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/defined_with_params_spec.rb72
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/delete_at_spec.rb29
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/delete_regex_spec.rb56
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/delete_spec.rb79
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/delete_undef_values_spec.rb58
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/delete_values_spec.rb45
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/deprecation_spec.rb63
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/difference_spec.rb23
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/dig44_spec.rb128
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/dig_spec.rb12
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/dirname_spec.rb18
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/dos2unix_spec.rb47
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/downcase_spec.rb15
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/empty_spec.rb22
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/ensure_packages_spec.rb72
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/ensure_resource_spec.rb137
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/ensure_resources_spec.rb25
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/flatten_spec.rb15
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/floor_spec.rb12
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/fqdn_rand_string_spec.rb67
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/fqdn_rotate_spec.rb74
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/fqdn_uuid_spec.rb12
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/get_module_path_spec.rb49
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/getparam_spec.rb34
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/getvar_spec.rb36
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/glob_spec.rb11
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/grep_spec.rb20
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/has_interface_with_spec.rb39
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/has_ip_address_spec.rb22
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/has_ip_network_spec.rb21
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/has_key_spec.rb20
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/hash_spec.rb15
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/intersection_spec.rb22
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/is_a_spec.rb32
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/is_array_spec.rb35
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/is_bool_spec.rb31
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/is_domain_name_spec.rb43
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/is_email_address_spec.rb14
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/is_float_spec.rb40
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/is_function_available_spec.rb9
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/is_hash_spec.rb11
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/is_integer_spec.rb46
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/is_ip_address_spec.rb40
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/is_ipv4_address_spec.rb31
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/is_ipv6_address_spec.rb29
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/is_mac_address_spec.rb30
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/is_numeric_spec.rb46
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/is_string_spec.rb45
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/join_keys_to_values_spec.rb29
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/join_spec.rb20
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/keys_spec.rb24
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/length_spec.rb31
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/load_module_metadata_spec.rb47
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/loadjson_spec.rb69
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/loadyaml_spec.rb39
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/lstrip_spec.rb35
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/max_spec.rb21
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/member_spec.rb23
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/merge_spec.rb25
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/min_spec.rb22
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/num2bool_spec.rb22
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/parsejson_spec.rb66
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/parseyaml_spec.rb83
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/pick_default_spec.rb26
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/pick_spec.rb17
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/prefix_spec.rb29
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/private_spec.rb52
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/pw_hash_spec.rb79
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/range_spec.rb157
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/regexpescape_spec.rb41
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/reject_spec.rb20
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/reverse_spec.rb33
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/round_spec.rb14
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/rstrip_spec.rb35
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/seeded_rand_spec.rb58
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/shell_escape_spec.rb29
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/shell_join_spec.rb30
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/shell_split_spec.rb33
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/shuffle_spec.rb38
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/size_spec.rb38
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/sort_spec.rb33
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/sprintf_hash_spec.rb33
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/squeeze_spec.rb50
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/str2bool_spec.rb23
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/str2saltedsha512_spec.rb26
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/strftime_spec.rb26
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/strip_spec.rb35
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/suffix_spec.rb40
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/swapcase_spec.rb40
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/time_spec.rb21
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/to_bytes_spec.rb70
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/to_json_pretty_spec.rb16
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/to_json_spec.rb22
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/to_yaml_spec.rb20
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/try_get_value_spec.rb108
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/type3x_spec.rb41
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/type_of_spec.rb25
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/type_spec.rb42
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/union_spec.rb25
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/unique_spec.rb31
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/unix2dos_spec.rb40
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/upcase_spec.rb26
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/uriescape_spec.rb36
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/validate_absolute_path_spec.rb72
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/validate_array_spec.rb35
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/validate_augeas_spec.rb75
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/validate_bool_spec.rb36
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/validate_cmd_spec.rb41
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/validate_domain_name_spec.rb35
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/validate_email_address_spec.rb23
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/validate_hash_spec.rb38
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/validate_integer_spec.rb101
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/validate_ip_address_spec.rb64
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/validate_ipv4_address_spec.rb40
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/validate_ipv6_address_spec.rb59
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/validate_legacy_spec.rb68
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/validate_numeric_spec.rb100
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/validate_re_spec.rb56
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/validate_slength_spec.rb81
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/validate_string_spec.rb33
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/validate_x509_rsa_key_pair_spec.rb181
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/values_at_spec.rb54
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/values_spec.rb24
-rw-r--r--code/environments/production/modules/stdlib/spec/functions/zip_spec.rb20
142 files changed, 5701 insertions, 0 deletions
diff --git a/code/environments/production/modules/stdlib/spec/functions/abs_spec.rb b/code/environments/production/modules/stdlib/spec/functions/abs_spec.rb
new file mode 100644
index 0000000..a151a7e
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/abs_spec.rb
@@ -0,0 +1,45 @@
+require 'spec_helper'
+
+describe 'abs' do
+ it { is_expected.not_to eq(nil) }
+
+ describe 'signature validation in puppet3', :unless => RSpec.configuration.puppet_future do
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it {
+ pending('Current implementation ignores parameters after the first.')
+ is_expected.to run.with_params(1, 2).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
+ }
+ end
+
+ describe 'signature validation in puppet4', :if => RSpec.configuration.puppet_future do
+ it {
+ pending 'the puppet 4 implementation'
+ is_expected.to run.with_params.and_raise_error(ArgumentError)
+ }
+ it {
+ pending 'the puppet 4 implementation'
+ is_expected.to run.with_params(1, 2).and_raise_error(ArgumentError)
+ }
+ it {
+ pending 'the puppet 4 implementation'
+ is_expected.to run.with_params([]).and_raise_error(ArgumentError)
+ }
+ it {
+ pending 'the puppet 4 implementation'
+ is_expected.to run.with_params({}).and_raise_error(ArgumentError)
+ }
+ it {
+ pending 'the puppet 4 implementation'
+ is_expected.to run.with_params(true).and_raise_error(ArgumentError)
+ }
+ end
+
+ it { is_expected.to run.with_params(-34).and_return(34) }
+ it { is_expected.to run.with_params('-34').and_return(34) }
+ it { is_expected.to run.with_params(34).and_return(34) }
+ it { is_expected.to run.with_params('34').and_return(34) }
+ it { is_expected.to run.with_params(-34.5).and_return(34.5) }
+ it { is_expected.to run.with_params('-34.5').and_return(34.5) }
+ it { is_expected.to run.with_params(34.5).and_return(34.5) }
+ it { is_expected.to run.with_params('34.5').and_return(34.5) }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/any2array_spec.rb b/code/environments/production/modules/stdlib/spec/functions/any2array_spec.rb
new file mode 100644
index 0000000..345adc2
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/any2array_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe 'any2array' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_return([]) }
+ it { is_expected.to run.with_params(true).and_return([true]) }
+ it { is_expected.to run.with_params('one').and_return(['one']) }
+ it { is_expected.to run.with_params('one', 'two').and_return(%w[one two]) }
+ it { is_expected.to run.with_params([]).and_return([]) }
+ it { is_expected.to run.with_params(['one']).and_return(['one']) }
+ it { is_expected.to run.with_params(%w[one two]).and_return(%w[one two]) }
+ it { is_expected.to run.with_params({}).and_return([]) }
+ it { is_expected.to run.with_params('key' => 'value').and_return(%w[key value]) }
+
+ it { is_expected.to run.with_params('‰').and_return(['‰']) }
+ it { is_expected.to run.with_params('竹').and_return(['竹']) }
+ it { is_expected.to run.with_params('Ü').and_return(['Ü']) }
+ it { is_expected.to run.with_params('∇').and_return(['∇']) }
+ it { is_expected.to run.with_params('€', '万', 'Ö', '♥', '割').and_return(['€', '万', 'Ö', '♥', '割']) }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/any2bool_spec.rb b/code/environments/production/modules/stdlib/spec/functions/any2bool_spec.rb
new file mode 100644
index 0000000..eaead8f
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/any2bool_spec.rb
@@ -0,0 +1,41 @@
+require 'spec_helper'
+
+describe 'any2bool' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+
+ it { is_expected.to run.with_params(true).and_return(true) }
+ it { is_expected.to run.with_params(false).and_return(false) }
+
+ it { is_expected.to run.with_params('1.5').and_return(true) }
+
+ describe 'when testing stringy values that mean "true"' do
+ %w[TRUE 1 t y true yes].each do |value|
+ it { is_expected.to run.with_params(value).and_return(true) }
+ end
+ end
+
+ describe 'when testing stringy values that mean "false"' do
+ ['FALSE', '', '0', 'f', 'n', 'false', 'no', 'undef', 'undefined', nil, :undef].each do |value|
+ it { is_expected.to run.with_params(value).and_return(false) }
+ end
+ end
+
+ describe 'when testing numeric values that mean "true"' do
+ [1, '1', 1.5, '1.5'].each do |value|
+ it { is_expected.to run.with_params(value).and_return(true) }
+ end
+ end
+
+ describe 'when testing numeric that mean "false"' do
+ [-1, '-1', -1.5, '-1.5', '0', 0].each do |value|
+ it { is_expected.to run.with_params(value).and_return(false) }
+ end
+ end
+
+ describe 'everything else returns true' do
+ [[], {}, ['1'], [1], { :one => 1 }].each do |value|
+ it { is_expected.to run.with_params(value).and_return(true) }
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/assert_private_spec.rb b/code/environments/production/modules/stdlib/spec/functions/assert_private_spec.rb
new file mode 100644
index 0000000..09abc77
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/assert_private_spec.rb
@@ -0,0 +1,41 @@
+require 'spec_helper'
+
+describe 'assert_private' do
+ context 'when called from inside module' do
+ it 'does not fail' do
+ scope.expects(:lookupvar).with('module_name').returns('foo')
+ scope.expects(:lookupvar).with('caller_module_name').returns('foo')
+
+ is_expected.to run.with_params
+ end
+ end
+
+ context 'when called from private class' do
+ before :each do
+ scope.expects(:lookupvar).with('module_name').returns('foo')
+ scope.expects(:lookupvar).with('caller_module_name').returns('bar')
+ end
+
+ it 'fails with a class error message' do
+ scope.source.expects(:name).returns('foo::baz')
+ scope.source.expects(:type).returns('hostclass')
+
+ is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{Class foo::baz is private})
+ end
+
+ context 'with an explicit failure message' do
+ it { is_expected.to run.with_params('failure message!').and_raise_error(Puppet::ParseError, %r{failure message!}) }
+ end
+ end
+
+ context 'when called from private definition' do
+ it 'fails with a class error message' do
+ scope.expects(:lookupvar).with('module_name').returns('foo')
+ scope.expects(:lookupvar).with('caller_module_name').returns('bar')
+ scope.source.expects(:name).returns('foo::baz')
+ scope.source.expects(:type).returns('definition')
+
+ is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{Definition foo::baz is private})
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/base64_spec.rb b/code/environments/production/modules/stdlib/spec/functions/base64_spec.rb
new file mode 100644
index 0000000..dafab36
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/base64_spec.rb
@@ -0,0 +1,60 @@
+require 'spec_helper'
+
+describe 'base64' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, %r{first argument must be one of}) }
+ it { is_expected.to run.with_params('encode', ['two']).and_raise_error(Puppet::ParseError, %r{second argument must be a string}) }
+ it { is_expected.to run.with_params('encode', 2).and_raise_error(Puppet::ParseError, %r{second argument must be a string}) }
+ it { is_expected.to run.with_params('encode', 'thestring', 'three').and_raise_error(Puppet::ParseError, %r{third argument must be one of}) }
+ it { is_expected.to run.with_params('decode', "dGhlc3RyaW5n\n", 'strict').and_raise_error(ArgumentError) }
+
+ it { is_expected.to run.with_params('encode', 'thestring').and_return("dGhlc3RyaW5n\n") }
+ it { is_expected.to run.with_params('decode', 'dGhlc3RyaW5n').and_return('thestring') }
+ it { is_expected.to run.with_params('decode', "dGhlc3RyaW5n\n").and_return('thestring') }
+
+ it { is_expected.to run.with_params('encode', 'thestring', 'default').and_return("dGhlc3RyaW5n\n") }
+ it { is_expected.to run.with_params('decode', 'dGhlc3RyaW5n', 'default').and_return('thestring') }
+ it { is_expected.to run.with_params('decode', "dGhlc3RyaW5n\n", 'default').and_return('thestring') }
+
+ it { is_expected.to run.with_params('encode', 'thestring', 'strict').and_return('dGhlc3RyaW5n') }
+ it { is_expected.to run.with_params('decode', 'dGhlc3RyaW5n', 'strict').and_return('thestring') }
+
+ it {
+ is_expected.to run.with_params('encode', 'a very long string that will cause the base64 encoder to produce output with multiple lines')
+ .and_return("YSB2ZXJ5IGxvbmcgc3RyaW5nIHRoYXQgd2lsbCBjYXVzZSB0aGUgYmFzZTY0\nIGVuY29kZXIgdG8gcHJvZHVjZSBvdXRwdXQgd2l0aCBtdWx0aXBsZSBsaW5l\ncw==\n")
+ }
+ it {
+ is_expected.to run.with_params('decode', "YSB2ZXJ5IGxvbmcgc3RyaW5nIHRoYXQgd2lsbCBjYXVzZSB0aGUgYmFzZTY0\nIGVuY29kZXIgdG8gcHJvZHVjZSBvdXRwdXQgd2l0aCBtdWx0aXBsZSBsaW5l\ncw==\n")
+ .and_return('a very long string that will cause the base64 encoder to produce output with multiple lines')
+ }
+ it {
+ is_expected.to run.with_params('decode', 'YSB2ZXJ5IGxvbmcgc3RyaW5nIHRoYXQgd2lsbCBjYXVzZSB0aGUgYmFzZTY0IGVuY29kZXIgdG8gcHJvZHVjZSBvdXRwdXQgd2l0aCBtdWx0aXBsZSBsaW5lcw==')
+ .and_return('a very long string that will cause the base64 encoder to produce output with multiple lines')
+ }
+ it {
+ is_expected.to run.with_params('encode', 'a very long string that will cause the base64 encoder to produce output with multiple lines', 'strict')
+ .and_return('YSB2ZXJ5IGxvbmcgc3RyaW5nIHRoYXQgd2lsbCBjYXVzZSB0aGUgYmFzZTY0IGVuY29kZXIgdG8gcHJvZHVjZSBvdXRwdXQgd2l0aCBtdWx0aXBsZSBsaW5lcw==')
+ }
+ it {
+ is_expected.to run.with_params('decode', 'YSB2ZXJ5IGxvbmcgc3RyaW5nIHRoYXQgd2lsbCBjYXVzZSB0aGUgYmFzZTY0IGVuY29kZXIgdG8gcHJvZHVjZSBvdXRwdXQgd2l0aCBtdWx0aXBsZSBsaW5lcw==', 'strict')
+ .and_return('a very long string that will cause the base64 encoder to produce output with multiple lines')
+ }
+ it {
+ is_expected.to run.with_params('encode', 'https://www.google.com.tw/?gws_rd=ssl#q=hello+world', 'urlsafe')
+ .and_return('aHR0cHM6Ly93d3cuZ29vZ2xlLmNvbS50dy8_Z3dzX3JkPXNzbCNxPWhlbGxvK3dvcmxk')
+ }
+ it {
+ is_expected.to run.with_params('decode', 'aHR0cHM6Ly93d3cuZ29vZ2xlLmNvbS50dy8_Z3dzX3JkPXNzbCNxPWhlbGxvK3dvcmxk', 'urlsafe')
+ .and_return('https://www.google.com.tw/?gws_rd=ssl#q=hello+world')
+ }
+ it {
+ is_expected.to run.with_params('encode', 'https://github.com/puppetlabs/puppetlabs-stdlib/pulls?utf8=%E2%9C%93&q=is%3Apr+is%3Aopen+Add', 'urlsafe')
+ .and_return('aHR0cHM6Ly9naXRodWIuY29tL3B1cHBldGxhYnMvcHVwcGV0bGFicy1zdGRsaWIvcHVsbHM_dXRmOD0lRTIlOUMlOTMmcT1pcyUzQXByK2lzJTNBb3BlbitBZGQ=')
+ }
+ it {
+ is_expected.to run.with_params('decode', 'aHR0cHM6Ly9naXRodWIuY29tL3B1cHBldGxhYnMvcHVwcGV0bGFicy1zdGRsaWIvcHVsbHM_dXRmOD0lRTIlOUMlOTMmcT1pcyUzQXByK2lzJTNBb3BlbitBZGQ=', 'urlsafe')
+ .and_return('https://github.com/puppetlabs/puppetlabs-stdlib/pulls?utf8=%E2%9C%93&q=is%3Apr+is%3Aopen+Add')
+ }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/basename_spec.rb b/code/environments/production/modules/stdlib/spec/functions/basename_spec.rb
new file mode 100644
index 0000000..6957133
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/basename_spec.rb
@@ -0,0 +1,19 @@
+require 'spec_helper'
+
+describe 'basename' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('one', 'two', 'three').and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('/path/to/a/file.ext', []).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('/path/to/a/file.ext').and_return('file.ext') }
+ it { is_expected.to run.with_params('relative_path/to/a/file.ext').and_return('file.ext') }
+ it { is_expected.to run.with_params('/path/to/a/file.ext', '.ext').and_return('file') }
+ it { is_expected.to run.with_params('relative_path/to/a/file.ext', '.ext').and_return('file') }
+ it { is_expected.to run.with_params('scheme:///path/to/a/file.ext').and_return('file.ext') }
+
+ context 'with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params('scheme:///√ạĺűē/竹.ext').and_return('竹.ext') }
+ it { is_expected.to run.with_params('ҝẽγ:/√ạĺűē/竹.ㄘ', '.ㄘ').and_return('竹') }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/bool2num_spec.rb b/code/environments/production/modules/stdlib/spec/functions/bool2num_spec.rb
new file mode 100644
index 0000000..3ba5e2c
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/bool2num_spec.rb
@@ -0,0 +1,14 @@
+require 'spec_helper'
+
+describe 'bool2num' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) }
+
+ [true, 'true', AlsoString.new('true')].each do |truthy|
+ it { is_expected.to run.with_params(truthy).and_return(1) }
+ end
+
+ [false, 'false', AlsoString.new('false')].each do |falsey|
+ it { is_expected.to run.with_params(falsey).and_return(0) }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/bool2str_spec.rb b/code/environments/production/modules/stdlib/spec/functions/bool2str_spec.rb
new file mode 100644
index 0000000..8d8f9b5
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/bool2str_spec.rb
@@ -0,0 +1,16 @@
+require 'spec_helper'
+
+describe 'bool2str' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) }
+ ['true', 'false', nil, :undef, ''].each do |invalid|
+ it { is_expected.to run.with_params(invalid).and_raise_error(Puppet::ParseError) }
+ end
+ it { is_expected.to run.with_params(true, 'yes', 'no', 'maybe').and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params(true, 'maybe').and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params(true, 0, 1).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params(true).and_return('true') }
+ it { is_expected.to run.with_params(false).and_return('false') }
+ it { is_expected.to run.with_params(true, 'yes', 'no').and_return('yes') }
+ it { is_expected.to run.with_params(false, 'yes', 'no').and_return('no') }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/camelcase_spec.rb b/code/environments/production/modules/stdlib/spec/functions/camelcase_spec.rb
new file mode 100644
index 0000000..892e1da
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/camelcase_spec.rb
@@ -0,0 +1,17 @@
+require 'spec_helper'
+
+describe 'camelcase' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params(100).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('abc').and_return('Abc') }
+ it { is_expected.to run.with_params('aa_bb_cc').and_return('AaBbCc') }
+ it { is_expected.to run.with_params('_aa__bb__cc_').and_return('AaBbCc') }
+ it { is_expected.to run.with_params('100').and_return('100') }
+ it { is_expected.to run.with_params('1_00').and_return('100') }
+ it { is_expected.to run.with_params('_').and_return('') }
+ it { is_expected.to run.with_params('').and_return('') }
+ it { is_expected.to run.with_params([]).and_return([]) }
+ it { is_expected.to run.with_params(%w[abc aa_bb_cc]).and_return(%w[Abc AaBbCc]) }
+ it { is_expected.to run.with_params(['abc', 1, 'aa_bb_cc']).and_return(['Abc', 1, 'AaBbCc']) }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/capitalize_spec.rb b/code/environments/production/modules/stdlib/spec/functions/capitalize_spec.rb
new file mode 100644
index 0000000..15c2acf
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/capitalize_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+describe 'capitalize' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params(100).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('one').and_return('One') }
+ it { is_expected.to run.with_params('one two').and_return('One two') }
+ it { is_expected.to run.with_params('ONE TWO').and_return('One two') }
+
+ it { is_expected.to run.with_params(AlsoString.new('one')).and_return('One') }
+ it { is_expected.to run.with_params([]).and_return([]) }
+ it { is_expected.to run.with_params(%w[one two]).and_return(%w[One Two]) }
+ it { is_expected.to run.with_params(['one', 1, 'two']).and_return(['One', 1, 'Two']) }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/ceiling_spec.rb b/code/environments/production/modules/stdlib/spec/functions/ceiling_spec.rb
new file mode 100644
index 0000000..0682720
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/ceiling_spec.rb
@@ -0,0 +1,12 @@
+require 'spec_helper'
+
+describe 'ceiling' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('foo').and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params(34).and_return(34) }
+ it { is_expected.to run.with_params(-34).and_return(-34) }
+ it { is_expected.to run.with_params(33.1).and_return(34) }
+ it { is_expected.to run.with_params(-33.1).and_return(-33) }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/chomp_spec.rb b/code/environments/production/modules/stdlib/spec/functions/chomp_spec.rb
new file mode 100644
index 0000000..aabf596
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/chomp_spec.rb
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+describe 'chomp' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError) }
+ it {
+ pending('Current implementation ignores parameters after the first.')
+ is_expected.to run.with_params('a', 'b').and_raise_error(Puppet::ParseError)
+ }
+ it { is_expected.to run.with_params('one').and_return('one') }
+ it { is_expected.to run.with_params("one\n").and_return('one') }
+ it { is_expected.to run.with_params("one\n\n").and_return("one\n") }
+ it { is_expected.to run.with_params(%W[one\n two three\n]).and_return(%w[one two three]) }
+
+ it { is_expected.to run.with_params(AlsoString.new('one')).and_return('one') }
+ it { is_expected.to run.with_params(AlsoString.new("one\n")).and_return('one') }
+ it { is_expected.to run.with_params(AlsoString.new("one\n\n")).and_return("one\n") }
+ it { is_expected.to run.with_params([AlsoString.new("one\n"), AlsoString.new('two'), "three\n"]).and_return(%w[one two three]) }
+
+ context 'with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params("ůťƒ8\n\n").and_return("ůťƒ8\n") }
+ it { is_expected.to run.with_params("ネット\n\n").and_return("ネット\n") }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/chop_spec.rb b/code/environments/production/modules/stdlib/spec/functions/chop_spec.rb
new file mode 100644
index 0000000..7b7c597
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/chop_spec.rb
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+describe 'chop' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError) }
+ it {
+ pending('Current implementation ignores parameters after the first.')
+ is_expected.to run.with_params('a', 'b').and_raise_error(Puppet::ParseError)
+ }
+ it { is_expected.to run.with_params('one').and_return('on') }
+ it { is_expected.to run.with_params("one\n").and_return('one') }
+ it { is_expected.to run.with_params("one\n\n").and_return("one\n") }
+ it { is_expected.to run.with_params(%W[one\n two three\n]).and_return(%w[one tw three]) }
+
+ it { is_expected.to run.with_params(AlsoString.new('one')).and_return('on') }
+ it { is_expected.to run.with_params(AlsoString.new("one\n")).and_return('one') }
+ it { is_expected.to run.with_params(AlsoString.new("one\n\n")).and_return("one\n") }
+ it { is_expected.to run.with_params([AlsoString.new("one\n"), AlsoString.new('two'), "three\n"]).and_return(%w[one tw three]) }
+
+ context 'with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params("ůťƒ8\n\n").and_return("ůťƒ8\n") }
+ it { is_expected.to run.with_params("ネット\n\n").and_return("ネット\n") }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/clamp_spec.rb b/code/environments/production/modules/stdlib/spec/functions/clamp_spec.rb
new file mode 100644
index 0000000..7f0de34
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/clamp_spec.rb
@@ -0,0 +1,16 @@
+require 'spec_helper'
+
+describe 'clamp' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(ArgumentError) }
+ it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params(12, 88, 71, 190).and_raise_error(Puppet::ParseError, %r{Wrong number of arguments, need three to clamp}) }
+ it { is_expected.to run.with_params('12string', 88, 15).and_raise_error(Puppet::ParseError, %r{Required explicit numeric}) }
+ it { is_expected.to run.with_params(1, 2, 'a' => 55).and_raise_error(Puppet::ParseError, %r{The Hash type is not allowed}) }
+ it { is_expected.to run.with_params('24', [575, 187]).and_return(187) }
+ it { is_expected.to run.with_params([4, 3, '99']).and_return(4) }
+ it { is_expected.to run.with_params(16, 750, 88).and_return(88) }
+ it { is_expected.to run.with_params([3, 873], 73).and_return(73) }
+ it { is_expected.to run.with_params([4], 8, 75).and_return(8) }
+ it { is_expected.to run.with_params([6], [31], 9911).and_return(31) }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/concat_spec.rb b/code/environments/production/modules/stdlib/spec/functions/concat_spec.rb
new file mode 100644
index 0000000..c9f2ae5
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/concat_spec.rb
@@ -0,0 +1,28 @@
+require 'spec_helper'
+
+describe 'concat' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params([1]).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params(1, [2]).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params([1], [2], [3]).and_return([1, 2, 3]) }
+ it { is_expected.to run.with_params(%w[1 2 3], %w[4 5 6]).and_return(%w[1 2 3 4 5 6]) }
+ it { is_expected.to run.with_params(%w[1 2 3], '4').and_return(%w[1 2 3 4]) }
+ it { is_expected.to run.with_params(%w[1 2 3], [%w[4 5], '6']).and_return(['1', '2', '3', %w[4 5], '6']) }
+ it { is_expected.to run.with_params(%w[1 2], %w[3 4], %w[5 6]).and_return(%w[1 2 3 4 5 6]) }
+ it { is_expected.to run.with_params(%w[1 2], '3', '4', %w[5 6]).and_return(%w[1 2 3 4 5 6]) }
+
+ context 'with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params([{ 'a' => 'b' }], 'c' => 'd', 'e' => 'f').and_return([{ 'a' => 'b' }, { 'c' => 'd', 'e' => 'f' }]) }
+ it { is_expected.to run.with_params(['ấ', 'β', '©'], %w[đ ể 文字列]).and_return(['ấ', 'β', '©', 'đ', 'ể', '文字列']) }
+ end
+
+ arguments = [%w[1 2 3], %w[4 5 6]]
+ originals = [arguments[0].dup, arguments[1].dup]
+ it 'leaves the original array intact' do
+ _result = subject.call([arguments[0], arguments[1]])
+ arguments.each_with_index do |argument, index|
+ expect(argument).to eq(originals[index])
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/convert_base_spec.rb b/code/environments/production/modules/stdlib/spec/functions/convert_base_spec.rb
new file mode 100644
index 0000000..d1a6cef
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/convert_base_spec.rb
@@ -0,0 +1,24 @@
+require 'spec_helper'
+
+describe 'convert_base' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(ArgumentError) }
+ it { is_expected.to run.with_params('asdf').and_raise_error(ArgumentError) }
+ it { is_expected.to run.with_params('asdf', 'moo', 'cow').and_raise_error(ArgumentError) }
+ it { is_expected.to run.with_params(['1'], '2').and_raise_error(Puppet::ParseError, %r{argument must be either a string or an integer}) }
+ it { is_expected.to run.with_params('1', ['2']).and_raise_error(Puppet::ParseError, %r{argument must be either a string or an integer}) }
+ it { is_expected.to run.with_params('1', 1).and_raise_error(Puppet::ParseError, %r{base must be at least 2 and must not be greater than 36}) }
+ it { is_expected.to run.with_params('1', 37).and_raise_error(Puppet::ParseError, %r{base must be at least 2 and must not be greater than 36}) }
+
+ it 'raises a ParseError if argument 1 is a string that does not correspond to an integer in base 10' do
+ is_expected.to run.with_params('ten', 6).and_raise_error(Puppet::ParseError, %r{argument must be an integer or a string corresponding to an integer in base 10})
+ end
+
+ it 'raises a ParseError if argument 2 is a string and does not correspond to an integer in base 10' do
+ is_expected.to run.with_params(100, 'hex').and_raise_error(Puppet::ParseError, %r{argument must be an integer or a string corresponding to an integer in base 10})
+ end
+
+ it { is_expected.to run.with_params('11', '16').and_return('b') }
+ it { is_expected.to run.with_params('35', '36').and_return('z') }
+ it { is_expected.to run.with_params(5, 2).and_return('101') }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/count_spec.rb b/code/environments/production/modules/stdlib/spec/functions/count_spec.rb
new file mode 100644
index 0000000..9f5d544
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/count_spec.rb
@@ -0,0 +1,23 @@
+require 'spec_helper'
+
+describe 'count' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(ArgumentError) }
+ it { is_expected.to run.with_params('one').and_raise_error(ArgumentError) }
+ it { is_expected.to run.with_params('one', 'two').and_return(1) }
+ it {
+ pending('should actually be like this, and not like above')
+ is_expected.to run.with_params('one', 'two').and_raise_error(ArgumentError)
+ }
+ it { is_expected.to run.with_params('one', 'two', 'three').and_raise_error(ArgumentError) }
+ it { is_expected.to run.with_params(%w[one two three]).and_return(3) }
+ it { is_expected.to run.with_params(%w[one two two], 'two').and_return(2) }
+ it { is_expected.to run.with_params(['one', nil, 'two']).and_return(2) }
+ it { is_expected.to run.with_params(['one', '', 'two']).and_return(2) }
+ it { is_expected.to run.with_params(['one', :undef, 'two']).and_return(2) }
+
+ it { is_expected.to run.with_params(['ổņ℮', 'ŧщộ', 'three']).and_return(3) }
+ it { is_expected.to run.with_params(['ổņ℮', 'ŧщộ', 'ŧщộ'], 'ŧщộ').and_return(2) }
+ it { is_expected.to run.with_params(['ổņ℮', nil, 'ŧщộ']).and_return(2) }
+ it { is_expected.to run.with_params(['ổņ℮', :undef, 'ŧщộ']).and_return(2) }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/deep_merge_spec.rb b/code/environments/production/modules/stdlib/spec/functions/deep_merge_spec.rb
new file mode 100644
index 0000000..d09bde0
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/deep_merge_spec.rb
@@ -0,0 +1,58 @@
+require 'spec_helper'
+
+describe 'deep_merge' do
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('key' => 'value').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params({}, '2').and_raise_error(Puppet::ParseError, %r{unexpected argument type String}) }
+ it { is_expected.to run.with_params({}, 2).and_raise_error(Puppet::ParseError, %r{unexpected argument}) }
+ it { is_expected.to run.with_params({}, '').and_return({}) }
+ it { is_expected.to run.with_params({}, {}).and_return({}) }
+ it { is_expected.to run.with_params({}, {}, {}).and_return({}) }
+ it { is_expected.to run.with_params({}, {}, {}, {}).and_return({}) }
+ it { is_expected.to run.with_params({ 'key' => 'value' }, '').and_return('key' => 'value') }
+ it { is_expected.to run.with_params({ 'key1' => 'value1' }, 'key2' => 'value2').and_return('key1' => 'value1', 'key2' => 'value2') }
+
+ describe 'when arguments have key collisions' do
+ it 'prefers values from the last hash' do
+ is_expected.to run \
+ .with_params({ 'key1' => 'value1', 'key2' => 'value2' }, 'key2' => 'replacement_value', 'key3' => 'value3') \
+ .and_return('key1' => 'value1', 'key2' => 'replacement_value', 'key3' => 'value3')
+ end
+ it {
+ is_expected.to run \
+ .with_params({ 'key1' => 'value1' }, { 'key1' => 'value2' }, 'key1' => 'value3') \
+ .and_return('key1' => 'value3')
+ }
+ end
+
+ describe 'when arguments have subhashes' do
+ it {
+ is_expected.to run \
+ .with_params({ 'key1' => 'value1' }, 'key2' => 'value2', 'key3' => { 'subkey1' => 'value4' }) \
+ .and_return('key1' => 'value1', 'key2' => 'value2', 'key3' => { 'subkey1' => 'value4' })
+ }
+ it {
+ is_expected.to run \
+ .with_params({ 'key1' => { 'subkey1' => 'value1' } }, 'key1' => { 'subkey2' => 'value2' }) \
+ .and_return('key1' => { 'subkey1' => 'value1', 'subkey2' => 'value2' })
+ }
+ it {
+ is_expected.to run \
+ .with_params({ 'key1' => { 'subkey1' => { 'subsubkey1' => 'value1' } } }, 'key1' => { 'subkey1' => { 'subsubkey1' => 'value2' } }) \
+ .and_return('key1' => { 'subkey1' => { 'subsubkey1' => 'value2' } })
+ }
+ end
+
+ arguments = { 'key1' => 'value1' }, { 'key2' => 'value2' }
+ originals = [arguments[0].dup, arguments[1].dup]
+ it 'does not change the original hashes' do
+ subject.call([arguments[0], arguments[1]])
+ arguments.each_with_index do |argument, index|
+ expect(argument).to eq(originals[index])
+ end
+ end
+
+ context 'with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params({ 'ĸέỹ1' => 'ϋǻļủë1' }, 'この文字列' => '万').and_return('ĸέỹ1' => 'ϋǻļủë1', 'この文字列' => '万') }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/defined_with_params_spec.rb b/code/environments/production/modules/stdlib/spec/functions/defined_with_params_spec.rb
new file mode 100644
index 0000000..d404ba9
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/defined_with_params_spec.rb
@@ -0,0 +1,72 @@
+require 'spec_helper'
+
+describe 'defined_with_params' do
+ describe 'when no resource is specified' do
+ it { is_expected.to run.with_params.and_raise_error(ArgumentError) }
+ end
+ describe 'when compared against a resource with no attributes' do
+ let :pre_condition do
+ 'user { "dan": }'
+ end
+
+ it { is_expected.to run.with_params('User[dan]', {}).and_return(true) }
+ it { is_expected.to run.with_params('User[bob]', {}).and_return(false) }
+ it { is_expected.to run.with_params('User[dan]', 'foo' => 'bar').and_return(false) }
+
+ context 'with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params('User[ĵĭмოү]', {}).and_return(false) }
+ it { is_expected.to run.with_params('User[ポーラ]', {}).and_return(false) }
+ end
+ end
+
+ describe 'when compared against a resource with attributes' do
+ let :pre_condition do
+ 'user { "dan": ensure => present, shell => "/bin/csh", managehome => false}'
+ end
+
+ it { is_expected.to run.with_params('User[dan]', {}).and_return(true) }
+ it { is_expected.to run.with_params('User[dan]', '').and_return(true) }
+ it { is_expected.to run.with_params('User[dan]', 'ensure' => 'present').and_return(true) }
+ it { is_expected.to run.with_params('User[dan]', 'ensure' => 'present', 'managehome' => false).and_return(true) }
+ it { is_expected.to run.with_params('User[dan]', 'ensure' => 'absent', 'managehome' => false).and_return(false) }
+ end
+
+ describe 'when passing undef values' do
+ let :pre_condition do
+ 'file { "/tmp/a": ensure => present }'
+ end
+
+ it { is_expected.to run.with_params('File[/tmp/a]', {}).and_return(true) }
+ it { is_expected.to run.with_params('File[/tmp/a]', 'ensure' => 'present', 'owner' => :undef).and_return(true) }
+ end
+
+ describe 'when the reference is a' do
+ let :pre_condition do
+ 'user { "dan": }'
+ end
+
+ context 'with reference' do
+ it { is_expected.to run.with_params(Puppet::Resource.new('User[dan]'), {}).and_return(true) }
+ end
+ if Puppet::Util::Package.versioncmp(Puppet.version, '4.6.0') >= 0
+ context 'with array' do
+ it 'fails' do
+ expect {
+ subject.call([['User[dan]'], {}])
+ }.to raise_error ArgumentError, %r{not understood: 'Array'}
+ end
+ end
+ end
+ end
+
+ describe 'when passed a defined type' do
+ let :pre_condition do
+ 'test::deftype { "foo": }'
+ end
+
+ it { is_expected.to run.with_params('Test::Deftype[foo]', {}).and_return(true) }
+ it { is_expected.to run.with_params('Test::Deftype[bar]', {}).and_return(false) }
+ it { is_expected.to run.with_params(Puppet::Resource.new('Test::Deftype[foo]'), {}).and_return(true) }
+ it { is_expected.to run.with_params(Puppet::Resource.new('Test::Deftype[bar]'), {}).and_return(false) }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/delete_at_spec.rb b/code/environments/production/modules/stdlib/spec/functions/delete_at_spec.rb
new file mode 100644
index 0000000..8889fbc
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/delete_at_spec.rb
@@ -0,0 +1,29 @@
+require 'spec_helper'
+
+describe 'delete_at' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('one', 1).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params(1, 1).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params(['one'], 'two').and_raise_error(Puppet::ParseError) }
+ it {
+ pending('Current implementation ignores parameters after the first two.')
+ is_expected.to run.with_params(['one'], 0, 1).and_raise_error(Puppet::ParseError)
+ }
+
+ describe 'argument validation' do
+ it { is_expected.to run.with_params([0, 1, 2], 3).and_raise_error(Puppet::ParseError) }
+ end
+
+ it { is_expected.to run.with_params([0, 1, 2], 1).and_return([0, 2]) }
+ it { is_expected.to run.with_params([0, 1, 2], -1).and_return([0, 1]) }
+ it { is_expected.to run.with_params([0, 1, 2], -4).and_return([0, 1, 2]) }
+ it { is_expected.to run.with_params(%w[ƒờở βāř ьầż], 1).and_return(%w[ƒờở ьầż]) }
+
+ it 'leaves the original array intact' do
+ argument = [1, 2, 3]
+ original = argument.dup
+ _result = subject.call([argument, 2])
+ expect(argument).to eq(original)
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/delete_regex_spec.rb b/code/environments/production/modules/stdlib/spec/functions/delete_regex_spec.rb
new file mode 100644
index 0000000..1e1cc2c
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/delete_regex_spec.rb
@@ -0,0 +1,56 @@
+require 'spec_helper'
+
+describe 'delete_regex' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params([], 'two') }
+ it { is_expected.to run.with_params({}, 'two') }
+ it { is_expected.to run.with_params([], 'two', 'three').and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params([], 'two', 'three', 'four').and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params(1, 'two').and_raise_error(TypeError) }
+
+ describe 'deleting from an array' do
+ it { is_expected.to run.with_params([], '').and_return([]) }
+ it { is_expected.to run.with_params([], 'two').and_return([]) }
+ it { is_expected.to run.with_params(['two'], 'two').and_return([]) }
+ it { is_expected.to run.with_params(%w[two two], 'two').and_return([]) }
+ it { is_expected.to run.with_params(%w[one two three], '^t.*').and_return(['one']) }
+ it { is_expected.to run.with_params(%w[ab b c b], 'b').and_return(%w[ab c]) }
+ it { is_expected.to run.with_params(%w[one two three], 'four').and_return(%w[one two three]) }
+ it { is_expected.to run.with_params(%w[one two three], 'e').and_return(%w[one two three]) }
+ it { is_expected.to run.with_params(%w[one two three], 'two').and_return(%w[one three]) }
+ it { is_expected.to run.with_params(%w[two one two three two], 'two').and_return(%w[one three]) }
+ it { is_expected.to run.with_params(['abracadabra'], 'abr').and_return(['abracadabra']) }
+ it { is_expected.to run.with_params(['abracadabra'], '^.*jimbob.*$').and_return(['abracadabra']) }
+ end
+
+ describe 'deleting from an array' do
+ it { is_expected.to run.with_params({}, '').and_return({}) }
+ it { is_expected.to run.with_params({}, 'key').and_return({}) }
+ it { is_expected.to run.with_params({ 'key' => 'value' }, 'key').and_return({}) }
+ it {
+ is_expected.to run \
+ .with_params({ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }, 'key2') \
+ .and_return('key1' => 'value1', 'key3' => 'value3')
+ }
+ it {
+ is_expected.to run \
+ .with_params({ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }, %w[key1 key2]) \
+ .and_return('key3' => 'value3')
+ }
+ end
+
+ it 'leaves the original array intact' do
+ argument1 = %w[one two three]
+ original1 = argument1.dup
+ subject.call([argument1, 'two'])
+ expect(argument1).to eq(original1)
+ end
+ it 'leaves the original hash intact' do
+ argument1 = { 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }
+ original1 = argument1.dup
+ subject.call([argument1, 'key2'])
+ expect(argument1).to eq(original1)
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/delete_spec.rb b/code/environments/production/modules/stdlib/spec/functions/delete_spec.rb
new file mode 100644
index 0000000..fa2f1b8
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/delete_spec.rb
@@ -0,0 +1,79 @@
+require 'spec_helper'
+
+describe 'delete' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params([], 'two') }
+ it { is_expected.to run.with_params([], 'two', 'three').and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params(1, 'two').and_raise_error(TypeError) }
+
+ describe 'deleting from an array' do
+ it { is_expected.to run.with_params([], '').and_return([]) }
+ it { is_expected.to run.with_params([], 'two').and_return([]) }
+ it { is_expected.to run.with_params(['two'], 'two').and_return([]) }
+ it { is_expected.to run.with_params(%w[two two], 'two').and_return([]) }
+ it { is_expected.to run.with_params(%w[ab b c b], 'b').and_return(%w[ab c]) }
+ it { is_expected.to run.with_params(%w[one two three], 'four').and_return(%w[one two three]) }
+ it { is_expected.to run.with_params(%w[one two three], 'e').and_return(%w[one two three]) }
+ it { is_expected.to run.with_params(%w[one two three], 'two').and_return(%w[one three]) }
+ it { is_expected.to run.with_params(%w[two one two three two], 'two').and_return(%w[one three]) }
+ it { is_expected.to run.with_params(%w[one two three two], %w[one two]).and_return(['three']) }
+ it { is_expected.to run.with_params(['ồאּẻ', 'ŧẅơ', 'ŧңŗё℮', 'ŧẅơ'], %w[ồאּẻ ŧẅơ]).and_return(['ŧңŗё℮']) }
+ end
+
+ describe 'deleting from a string' do
+ it { is_expected.to run.with_params('', '').and_return('') }
+ it { is_expected.to run.with_params('bar', '').and_return('bar') }
+ it { is_expected.to run.with_params('', 'bar').and_return('') }
+ it { is_expected.to run.with_params('bar', 'bar').and_return('') }
+ it { is_expected.to run.with_params('barbar', 'bar').and_return('') }
+ it { is_expected.to run.with_params('barfoobar', 'bar').and_return('foo') }
+ it { is_expected.to run.with_params('foobarbabarz', 'bar').and_return('foobaz') }
+ it { is_expected.to run.with_params('foobarbabarz', %w[foo bar]).and_return('baz') }
+ it { is_expected.to run.with_params('ƒōōβậяβậβậяź', %w[ƒōō βậя]).and_return('βậź') }
+
+ it { is_expected.to run.with_params('barfoobar', %w[barbar foo]).and_return('barbar') }
+ it { is_expected.to run.with_params('barfoobar', %w[foo barbar]).and_return('') }
+ end
+
+ describe 'deleting from an array' do
+ it { is_expected.to run.with_params({}, '').and_return({}) }
+ it { is_expected.to run.with_params({}, 'key').and_return({}) }
+ it { is_expected.to run.with_params({ 'key' => 'value' }, 'key').and_return({}) }
+ it {
+ is_expected.to run \
+ .with_params({ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }, 'key2') \
+ .and_return('key1' => 'value1', 'key3' => 'value3')
+ }
+ it {
+ is_expected.to run \
+ .with_params({ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }, %w[key1 key2]) \
+ .and_return('key3' => 'value3')
+ }
+ it {
+ is_expected.to run \
+ .with_params({ 'ĸəұ1' => 'νãŀủĕ1', 'ĸəұ2' => 'νãŀủĕ2', 'ĸəұ3' => 'νãŀủĕ3' }, %w[ĸəұ1 ĸəұ2]) \
+ .and_return('ĸəұ3' => 'νãŀủĕ3')
+ }
+ end
+
+ it 'leaves the original array intact' do
+ argument1 = %w[one two three]
+ original1 = argument1.dup
+ _result = subject.call([argument1, 'two'])
+ expect(argument1).to eq(original1)
+ end
+ it 'leaves the original string intact' do
+ argument1 = 'onetwothree'
+ original1 = argument1.dup
+ _result = subject.call([argument1, 'two'])
+ expect(argument1).to eq(original1)
+ end
+ it 'leaves the original hash intact' do
+ argument1 = { 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }
+ original1 = argument1.dup
+ _result = subject.call([argument1, 'key2'])
+ expect(argument1).to eq(original1)
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/delete_undef_values_spec.rb b/code/environments/production/modules/stdlib/spec/functions/delete_undef_values_spec.rb
new file mode 100644
index 0000000..2a282f5
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/delete_undef_values_spec.rb
@@ -0,0 +1,58 @@
+require 'spec_helper'
+
+describe 'delete_undef_values' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError) }
+
+ describe 'when deleting from an array' do
+ [:undef, '', nil].each do |undef_value|
+ describe "when undef is represented by #{undef_value.inspect}" do
+ before(:each) do
+ pending("review behaviour when being passed undef as #{undef_value.inspect}") if undef_value == ''
+ pending("review behaviour when being passed undef as #{undef_value.inspect}") if undef_value.nil?
+ end
+ it { is_expected.to run.with_params([undef_value]).and_return([]) }
+ it { is_expected.to run.with_params(['one', undef_value, 'two', 'three']).and_return(%w[one two three]) }
+ it { is_expected.to run.with_params(['ớņέ', undef_value, 'ŧשּׁō', 'ŧħґëə']).and_return(%w[ớņέ ŧשּׁō ŧħґëə]) }
+ end
+
+ it 'leaves the original argument intact' do
+ argument = ['one', undef_value, 'two']
+ original = argument.dup
+ _result = subject.call([argument, 2])
+ expect(argument).to eq(original)
+ end
+ end
+
+ it { is_expected.to run.with_params(['undef']).and_return(['undef']) }
+ end
+
+ describe 'when deleting from a hash' do
+ [:undef, '', nil].each do |undef_value|
+ describe "when undef is represented by #{undef_value.inspect}" do
+ before(:each) do
+ pending("review behaviour when being passed undef as #{undef_value.inspect}") if undef_value == ''
+ pending("review behaviour when being passed undef as #{undef_value.inspect}") if undef_value.nil?
+ end
+ it { is_expected.to run.with_params('key' => undef_value).and_return({}) }
+ it {
+ is_expected.to run \
+ .with_params('key1' => 'value1', 'undef_key' => undef_value, 'key2' => 'value2') \
+ .and_return('key1' => 'value1', 'key2' => 'value2')
+ }
+ end
+
+ it 'leaves the original argument intact' do
+ argument = { 'key1' => 'value1', 'key2' => undef_value }
+ original = argument.dup
+ _result = subject.call([argument, 2])
+ expect(argument).to eq(original)
+ end
+ end
+
+ it { is_expected.to run.with_params('key' => 'undef').and_return('key' => 'undef') }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/delete_values_spec.rb b/code/environments/production/modules/stdlib/spec/functions/delete_values_spec.rb
new file mode 100644
index 0000000..20f2648
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/delete_values_spec.rb
@@ -0,0 +1,45 @@
+require 'spec_helper'
+
+describe 'delete_values' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('one', 'two', 'three').and_raise_error(Puppet::ParseError) }
+ describe 'when the first argument is not a hash' do
+ it { is_expected.to run.with_params(1, 'two').and_raise_error(TypeError) }
+ it { is_expected.to run.with_params('one', 'two').and_raise_error(TypeError) }
+ it { is_expected.to run.with_params([], 'two').and_raise_error(TypeError) }
+ end
+
+ describe 'when deleting from a hash' do
+ it { is_expected.to run.with_params({}, 'value').and_return({}) }
+ it {
+ is_expected.to run \
+ .with_params({ 'key1' => 'value1' }, 'non-existing value') \
+ .and_return('key1' => 'value1')
+ }
+ it {
+ is_expected.to run \
+ .with_params({ 'ҝếỵ1 ' => 'νâĺūẹ1', 'ҝếỵ2' => 'value to delete' }, 'value to delete') \
+ .and_return('ҝếỵ1 ' => 'νâĺūẹ1')
+ }
+ it {
+ is_expected.to run \
+ .with_params({ 'key1' => 'value1', 'key2' => 'νǎŀữ℮ ťớ đêłểťė' }, 'νǎŀữ℮ ťớ đêłểťė') \
+ .and_return('key1' => 'value1')
+ }
+ it {
+ is_expected.to run \
+ .with_params({ 'key1' => 'value1', 'key2' => 'value to delete', 'key3' => 'value to delete' }, 'value to delete') \
+ .and_return('key1' => 'value1')
+ }
+ end
+
+ it 'leaves the original argument intact' do
+ argument = { 'key1' => 'value1', 'key2' => 'value2' }
+ original = argument.dup
+ _result = subject.call([argument, 'value2'])
+ expect(argument).to eq(original)
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/deprecation_spec.rb b/code/environments/production/modules/stdlib/spec/functions/deprecation_spec.rb
new file mode 100644
index 0000000..8410867
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/deprecation_spec.rb
@@ -0,0 +1,63 @@
+require 'spec_helper'
+
+if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
+ describe 'deprecation' do
+ before(:each) do
+ # this is to reset the strict variable to default
+ Puppet.settings[:strict] = :warning
+ end
+
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(ArgumentError) }
+
+ it 'displays a single warning' do
+ Puppet.expects(:warning).with(includes('heelo'))
+ is_expected.to run.with_params('key', 'heelo')
+ end
+
+ it 'displays a single warning, despite multiple calls' do
+ Puppet.expects(:warning).with(includes('heelo')).once
+ (0..1).each do |_i|
+ is_expected.to run.with_params('key', 'heelo')
+ end
+ end
+
+ it 'fails twice with message, with multiple calls. when strict= :error' do
+ Puppet.settings[:strict] = :error
+ Puppet.expects(:warning).with(includes('heelo')).never
+ (0..1).each do |_i|
+ is_expected.to run.with_params('key', 'heelo').and_raise_error(RuntimeError, %r{deprecation. key. heelo})
+ end
+ end
+
+ it 'displays nothing, despite multiple calls. strict= :off' do
+ Puppet.settings[:strict] = :off
+ Puppet.expects(:warning).with(includes('heelo')).never
+ (0..1).each do |_i|
+ is_expected.to run.with_params('key', 'heelo')
+ end
+ end
+
+ after(:each) do
+ # this is to reset the strict variable to default
+ Puppet.settings[:strict] = :warning
+ end
+ end
+elsif Puppet.version.to_f < 4.0
+ # Puppet version < 4 will use these tests.
+ describe 'deprecation' do
+ after(:each) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ before(:each) do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
+ end
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+
+ it 'displays a single warning' do
+ scope.expects(:warning).with(includes('heelo'))
+ is_expected.to run.with_params('key', 'heelo')
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/difference_spec.rb b/code/environments/production/modules/stdlib/spec/functions/difference_spec.rb
new file mode 100644
index 0000000..d8c6765
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/difference_spec.rb
@@ -0,0 +1,23 @@
+require 'spec_helper'
+
+describe 'difference' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('one', 'two', 'three').and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('one', []).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params([], 'two').and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params({}, {}).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params([], []).and_return([]) }
+ it { is_expected.to run.with_params([], ['one']).and_return([]) }
+ it { is_expected.to run.with_params(['one'], ['one']).and_return([]) }
+ it { is_expected.to run.with_params(['ớņέ'], ['']).and_return(['ớņέ']) }
+ it { is_expected.to run.with_params(['one'], []).and_return(['one']) }
+ it { is_expected.to run.with_params(%w[one two three], %w[two three]).and_return(['one']) }
+ it { is_expected.to run.with_params(['ớņέ', 'ŧשּׁō', 'ŧħґëə', 2], %w[ŧשּׁō ŧħґëə]).and_return(['ớņέ', 2]) }
+ it { is_expected.to run.with_params(%w[one two two three], %w[two three]).and_return(['one']) }
+ it { is_expected.to run.with_params(%w[one two three], %w[two two three]).and_return(['one']) }
+ it { is_expected.to run.with_params(%w[one two three], %w[two three four]).and_return(['one']) }
+ it 'does not confuse types' do is_expected.to run.with_params(%w[1 2 3], [1, 2]).and_return(%w[1 2 3]) end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/dig44_spec.rb b/code/environments/production/modules/stdlib/spec/functions/dig44_spec.rb
new file mode 100644
index 0000000..c721b0c
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/dig44_spec.rb
@@ -0,0 +1,128 @@
+require 'spec_helper'
+
+describe 'dig44' do
+ let(:data) do
+ {
+ 'a' => {
+ 'g' => '2',
+ 'e' => [
+ 'f0',
+ 'f1',
+ {
+ 'x' => {
+ 'y' => 'z',
+ },
+ },
+ 'f3',
+ ],
+ },
+ 'b' => true,
+ 'c' => false,
+ 'd' => '1',
+ 'e' => :undef,
+ 'f' => nil,
+ }
+ end
+
+ let(:utf8_data) do
+ {
+ 'ẵ' => {
+ 'в' => [
+ '©',
+ 'ĝ',
+ 'に',
+ ],
+ },
+ }
+ end
+
+ context 'with single values' do
+ it 'exists' do
+ is_expected.not_to be_nil
+ end
+
+ it 'requires two arguments' do
+ is_expected.to run.with_params.and_raise_error(ArgumentError)
+ end
+
+ it 'fails if the data is not a structure' do
+ is_expected.to run.with_params('test', []).and_raise_error(Puppet::Error)
+ end
+
+ it 'fails if the path is not an array' do
+ is_expected.to run.with_params({}, '').and_raise_error(Puppet::Error)
+ end
+
+ it 'returns the value if the value is string' do
+ is_expected.to run.with_params(data, ['d'], 'default').and_return('1')
+ end
+
+ it 'returns true if the value is true' do
+ is_expected.to run.with_params(data, ['b'], 'default').and_return(true)
+ end
+
+ it 'returns false if the value is false' do
+ is_expected.to run.with_params(data, ['c'], 'default').and_return(false)
+ end
+
+ it 'returns the default if the value is nil' do
+ is_expected.to run.with_params(data, ['f'], 'default').and_return('default')
+ end
+
+ it 'returns the default if the value is :undef (same as nil)' do
+ is_expected.to run.with_params(data, ['e'], 'default').and_return('default')
+ end
+
+ it 'returns the default if the path is not found' do
+ is_expected.to run.with_params(data, ['missing'], 'default').and_return('default')
+ end
+ end
+
+ context 'with structured values' do
+ it 'is able to extract a deeply nested hash value' do
+ is_expected.to run.with_params(data, %w[a g], 'default').and_return('2')
+ end
+
+ it 'returns the default value if the path is too long' do
+ is_expected.to run.with_params(data, %w[a g c d], 'default').and_return('default')
+ end
+
+ it 'supports an array index (number) in the path' do
+ is_expected.to run.with_params(data, ['a', 'e', 1], 'default').and_return('f1')
+ end
+
+ it 'supports an array index (string) in the path' do
+ is_expected.to run.with_params(data, %w[a e 1], 'default').and_return('f1')
+ end
+
+ it 'returns the default value if an array index is not a number' do
+ is_expected.to run.with_params(data, %w[a b c], 'default').and_return('default')
+ end
+
+ it 'returns the default value if and index is out of array length' do
+ is_expected.to run.with_params(data, %w[a e 5], 'default').and_return('default')
+ end
+
+ it 'is able to path though both arrays and hashes' do
+ is_expected.to run.with_params(data, %w[a e 2 x y], 'default').and_return('z')
+ end
+
+ it 'returns "nil" if value is not found and no default value is provided' do
+ is_expected.to run.with_params(data, %w[a 1]).and_return(nil)
+ end
+ end
+
+ context 'with internationalization (i18N) values' do
+ it 'is able to return a unicode character' do
+ is_expected.to run.with_params(utf8_data, ['ẵ', 'в', 0]).and_return('©')
+ end
+
+ it 'is able to return a utf8 character' do
+ is_expected.to run.with_params(utf8_data, ['ẵ', 'в', 1]).and_return('ĝ')
+ end
+
+ it 'is able to return a double byte character' do
+ is_expected.to run.with_params(utf8_data, ['ẵ', 'в', 2]).and_return('に')
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/dig_spec.rb b/code/environments/production/modules/stdlib/spec/functions/dig_spec.rb
new file mode 100644
index 0000000..af5ec51
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/dig_spec.rb
@@ -0,0 +1,12 @@
+require 'spec_helper'
+
+describe 'dig' do
+ it 'exists' do
+ expect(Puppet::Parser::Functions.function('dig')).to eq('function_dig')
+ end
+
+ it 'gives a deprecation warning when called' do
+ scope.expects(:warning).with('dig() DEPRECATED: This function has been replaced in Puppet 4.5.0, please use dig44() for backwards compatibility or use the new version.')
+ scope.function_dig([{}, []])
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/dirname_spec.rb b/code/environments/production/modules/stdlib/spec/functions/dirname_spec.rb
new file mode 100644
index 0000000..da62eea
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/dirname_spec.rb
@@ -0,0 +1,18 @@
+require 'spec_helper'
+
+describe 'dirname' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('/path/to/a/file.ext', []).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('/path/to/a/file.ext').and_return('/path/to/a') }
+ it { is_expected.to run.with_params('relative_path/to/a/file.ext').and_return('relative_path/to/a') }
+
+ context 'with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params('scheme:///√ạĺűē/竹.ext').and_return('scheme:///√ạĺűē') }
+ it { is_expected.to run.with_params('ҝẽγ:/√ạĺűē/竹.ㄘ').and_return('ҝẽγ:/√ạĺűē') }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/dos2unix_spec.rb b/code/environments/production/modules/stdlib/spec/functions/dos2unix_spec.rb
new file mode 100644
index 0000000..8677d8c
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/dos2unix_spec.rb
@@ -0,0 +1,47 @@
+require 'spec_helper'
+
+describe 'dos2unix' do
+ context 'when checking parameter validity' do
+ it { is_expected.not_to eq(nil) }
+ it do
+ is_expected.to run.with_params.and_raise_error(ArgumentError, %r{Wrong number of arguments})
+ end
+ it do
+ is_expected.to run.with_params('one', 'two').and_raise_error(ArgumentError, %r{Wrong number of arguments})
+ end
+ it do
+ is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError)
+ end
+ it do
+ is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError)
+ end
+ it do
+ is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError)
+ end
+ end
+
+ context 'when converting from dos to unix format' do
+ sample_text = "Hello\r\nWorld\r\n"
+ desired_output = "Hello\nWorld\n"
+
+ it 'outputs unix format' do
+ is_expected.to run.with_params(sample_text).and_return(desired_output)
+ end
+ end
+
+ context 'with internationalization (i18N) values' do
+ sample_text_utf8 = "Ħ℮ļłǿ\r\nשׁөŕłđ\r\n"
+ desired_output_utf8 = "Ħ℮ļłǿ\nשׁөŕłđ\n"
+
+ sample_text_doublebyte = "こんにちは\r\n世界\r\n"
+ desired_output_doublebyte = "こんにちは\n世界\n"
+
+ it 'outputs uft8 string' do
+ is_expected.to run.with_params(sample_text_utf8).and_return(desired_output_utf8)
+ end
+
+ it 'outputs double byte string' do
+ is_expected.to run.with_params(sample_text_doublebyte).and_return(desired_output_doublebyte)
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/downcase_spec.rb b/code/environments/production/modules/stdlib/spec/functions/downcase_spec.rb
new file mode 100644
index 0000000..d49e169
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/downcase_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+describe 'downcase' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params(100).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('abc').and_return('abc') }
+ it { is_expected.to run.with_params('Abc').and_return('abc') }
+ it { is_expected.to run.with_params('ABC').and_return('abc') }
+
+ it { is_expected.to run.with_params(AlsoString.new('ABC')).and_return('abc') }
+ it { is_expected.to run.with_params([]).and_return([]) }
+ it { is_expected.to run.with_params(%w[ONE TWO]).and_return(%w[one two]) }
+ it { is_expected.to run.with_params(['One', 1, 'Two']).and_return(['one', 1, 'two']) }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/empty_spec.rb b/code/environments/production/modules/stdlib/spec/functions/empty_spec.rb
new file mode 100644
index 0000000..c6bf1e4
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/empty_spec.rb
@@ -0,0 +1,22 @@
+require 'spec_helper'
+
+describe 'empty', :if => Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) }
+ it {
+ pending('Current implementation ignores parameters after the first.')
+ is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError)
+ }
+ it { is_expected.to run.with_params(0).and_return(false) }
+ it { is_expected.to run.with_params('').and_return(true) }
+ it { is_expected.to run.with_params('one').and_return(false) }
+
+ it { is_expected.to run.with_params(AlsoString.new('')).and_return(true) }
+ it { is_expected.to run.with_params(AlsoString.new('one')).and_return(false) }
+
+ it { is_expected.to run.with_params([]).and_return(true) }
+ it { is_expected.to run.with_params(['one']).and_return(false) }
+
+ it { is_expected.to run.with_params({}).and_return(true) }
+ it { is_expected.to run.with_params('key' => 'value').and_return(false) }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/ensure_packages_spec.rb b/code/environments/production/modules/stdlib/spec/functions/ensure_packages_spec.rb
new file mode 100644
index 0000000..6bdb015
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/ensure_packages_spec.rb
@@ -0,0 +1,72 @@
+require 'spec_helper'
+
+describe 'ensure_packages' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) }
+ it {
+ pending('should not accept numbers as arguments')
+ is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError)
+ }
+ it {
+ pending('should not accept numbers as arguments')
+ is_expected.to run.with_params(['packagename', 1]).and_raise_error(Puppet::ParseError)
+ }
+ it { is_expected.to run.with_params('packagename') }
+ it { is_expected.to run.with_params(%w[packagename1 packagename2]) }
+
+ context 'when given a catalog with "package { puppet: ensure => absent }"' do
+ let(:pre_condition) { 'package { puppet: ensure => absent }' }
+
+ describe 'after running ensure_package("facter")' do
+ before(:each) { subject.call(['facter']) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(-> { catalogue }).to contain_package('puppet').with_ensure('absent') }
+ it { expect(-> { catalogue }).to contain_package('facter').with_ensure('present') }
+ end
+
+ describe 'after running ensure_package("facter", { "provider" => "gem" })' do
+ before(:each) { subject.call(['facter', { 'provider' => 'gem' }]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(-> { catalogue }).to contain_package('puppet').with_ensure('absent').without_provider }
+ it { expect(-> { catalogue }).to contain_package('facter').with_ensure('present').with_provider('gem') }
+ end
+ end
+
+ context 'when given an empty packages array' do
+ let(:pre_condition) { 'notify { "hi": } -> Package <| |>; $somearray = ["vim",""]; ensure_packages($somearray)' }
+
+ describe 'after running ensure_package(["vim", ""])' do
+ it { expect { catalogue }.to raise_error(Puppet::ParseError, %r{Empty String provided}) }
+ end
+ end
+
+ context 'when given hash of packages' do
+ before(:each) do
+ subject.call([{ 'foo' => { 'provider' => 'rpm' }, 'bar' => { 'provider' => 'gem' } }, { 'ensure' => 'present' }])
+ subject.call([{ 'パッケージ' => { 'ensure' => 'absent' } }])
+ subject.call([{ 'ρǻ¢κầģẻ' => { 'ensure' => 'absent' } }])
+ end
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(-> { catalogue }).to contain_package('foo').with('provider' => 'rpm', 'ensure' => 'present') }
+ it { expect(-> { catalogue }).to contain_package('bar').with('provider' => 'gem', 'ensure' => 'present') }
+
+ context 'with UTF8 and double byte characters' do
+ it { expect(-> { catalogue }).to contain_package('パッケージ').with('ensure' => 'absent') }
+ it { expect(-> { catalogue }).to contain_package('ρǻ¢κầģẻ').with('ensure' => 'absent') }
+ end
+ end
+
+ context 'when given a catalog with "package { puppet: ensure => present }"' do
+ let(:pre_condition) { 'package { puppet: ensure => present }' }
+
+ describe 'after running ensure_package("puppet", { "ensure" => "installed" })' do
+ before(:each) { subject.call(['puppet', { 'ensure' => 'installed' }]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(-> { catalogue }).to contain_package('puppet').with_ensure('present') }
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/ensure_resource_spec.rb b/code/environments/production/modules/stdlib/spec/functions/ensure_resource_spec.rb
new file mode 100644
index 0000000..3ef3b70
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/ensure_resource_spec.rb
@@ -0,0 +1,137 @@
+require 'spec_helper'
+
+describe 'ensure_resource' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{Must specify a type}) }
+ it { is_expected.to run.with_params('type').and_raise_error(ArgumentError, %r{Must specify a title}) }
+ if Puppet::Util::Package.versioncmp(Puppet.version, '4.6.0') >= 0
+ it { is_expected.to run.with_params('type', 'title', {}, 'extras').and_raise_error(ArgumentError) }
+ else
+ it { is_expected.to run.with_params('type', 'title', {}, 'extras').and_raise_error(Puppet::ParseError) }
+ end
+
+ it {
+ pending('should not accept numbers as arguments')
+ is_expected.to run.with_params(1, 2, 3).and_raise_error(Puppet::ParseError)
+ }
+
+ context 'when given an empty catalog' do
+ describe 'after running ensure_resource("user", "username1", {})' do
+ before(:each) { subject.call(['User', 'username1', {}]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(-> { catalogue }).to contain_user('username1').without_ensure }
+ end
+
+ describe 'after running ensure_resource("user", "username1", { gid => undef })' do
+ before(:each) { subject.call(['User', 'username1', { 'gid' => :undef }]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(-> { catalogue }).to contain_user('username1').without_ensure }
+ it { expect(-> { catalogue }).to contain_user('username1').without_gid }
+ end
+
+ describe 'after running ensure_resource("user", "username1", { ensure => present, gid => undef })' do
+ before(:each) { subject.call(['User', 'username1', { 'ensure' => 'present', 'gid' => :undef }]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(-> { catalogue }).to contain_user('username1').with_ensure('present') }
+ it { expect(-> { catalogue }).to contain_user('username1').without_gid }
+ end
+
+ describe 'after running ensure_resource("test::deftype", "foo", {})' do
+ before(:each) { subject.call(['test::deftype', 'foo', {}]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(-> { catalogue }).to contain_test__deftype('foo').without_ensure }
+ end
+ end
+
+ context 'when given a catalog with UTF8 chars' do
+ describe 'after running ensure_resource("user", "Şắოрŀễ Ţëם", {})' do
+ before(:each) { subject.call(['User', 'Şắოрŀễ Ţëם', {}]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(-> { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_ensure }
+ end
+
+ describe 'after running ensure_resource("user", "Şắოрŀễ Ţëם", { gid => undef })' do
+ before(:each) { subject.call(['User', 'Şắოрŀễ Ţëם', { 'gid' => :undef }]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(-> { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_ensure }
+ it { expect(-> { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_gid }
+ end
+
+ describe 'after running ensure_resource("user", "Şắოрŀễ Ţëם", { ensure => present, gid => undef })' do
+ before(:each) { subject.call(['User', 'Şắოрŀễ Ţëם', { 'ensure' => 'present', 'gid' => :undef }]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(-> { catalogue }).to contain_user('Şắოрŀễ Ţëם').with_ensure('present') }
+ it { expect(-> { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_gid }
+ end
+ end
+
+ context 'when given a catalog with "user { username1: ensure => present }"' do
+ let(:pre_condition) { 'user { username1: ensure => present }' }
+
+ describe 'after running ensure_resource("user", "username1", {})' do
+ before(:each) { subject.call(['User', 'username1', {}]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(-> { catalogue }).to contain_user('username1').with_ensure('present') }
+ end
+
+ describe 'after running ensure_resource("user", "username2", {})' do
+ before(:each) { subject.call(['User', 'username2', {}]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(-> { catalogue }).to contain_user('username1').with_ensure('present') }
+ it { expect(-> { catalogue }).to contain_user('username2').without_ensure }
+ end
+
+ describe 'after running ensure_resource("user", "username1", { gid => undef })' do
+ before(:each) { subject.call(['User', 'username1', { 'gid' => :undef }]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(-> { catalogue }).to contain_user('username1').with_ensure('present') }
+ end
+
+ describe 'after running ensure_resource("user", ["username1", "username2"], {})' do
+ before(:each) { subject.call(['User', %w[username1 username2], {}]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(-> { catalogue }).to contain_user('username1').with_ensure('present') }
+ it { expect(-> { catalogue }).to contain_user('username2').without_ensure }
+ end
+
+ describe 'when providing already set params' do
+ let(:params) { { 'ensure' => 'present' } }
+
+ before(:each) { subject.call(['User', %w[username2 username3], params]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(-> { catalogue }).to contain_user('username1').with(params) }
+ it { expect(-> { catalogue }).to contain_user('username2').with(params) }
+ end
+
+ context 'when trying to add params' do
+ it {
+ is_expected.to run \
+ .with_params('User', 'username1', 'ensure' => 'present', 'shell' => true) \
+ .and_raise_error(Puppet::Resource::Catalog::DuplicateResourceError, %r{User\[username1\] is already declared})
+ }
+ end
+ end
+
+ context 'when given a catalog with "test::deftype { foo: }"' do
+ let(:pre_condition) { 'test::deftype { "foo": }' }
+
+ describe 'after running ensure_resource("test::deftype", "foo", {})' do
+ before(:each) { subject.call(['test::deftype', 'foo', {}]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(-> { catalogue }).to contain_test__deftype('foo').without_ensure }
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/ensure_resources_spec.rb b/code/environments/production/modules/stdlib/spec/functions/ensure_resources_spec.rb
new file mode 100644
index 0000000..5ec0b20
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/ensure_resources_spec.rb
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+describe 'ensure_resources' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{Must specify a type}) }
+ it { is_expected.to run.with_params('type').and_raise_error(ArgumentError, %r{Must specify a title}) }
+
+ describe 'given a title hash of multiple resources' do
+ before(:each) { subject.call(['user', { 'dan' => { 'gid' => 'mygroup', 'uid' => '600' }, 'alex' => { 'gid' => 'mygroup', 'uid' => '700' } }, { 'ensure' => 'present' }]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(-> { catalogue }).to contain_user('dan').with_ensure('present') }
+ it { expect(-> { catalogue }).to contain_user('alex').with_ensure('present') }
+ it { expect(-> { catalogue }).to contain_user('dan').with('gid' => 'mygroup', 'uid' => '600') }
+ it { expect(-> { catalogue }).to contain_user('alex').with('gid' => 'mygroup', 'uid' => '700') }
+ end
+
+ describe 'given a title hash of a single resource' do
+ before(:each) { subject.call(['user', { 'dan' => { 'gid' => 'mygroup', 'uid' => '600' } }, { 'ensure' => 'present' }]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(-> { catalogue }).to contain_user('dan').with_ensure('present') }
+ it { expect(-> { catalogue }).to contain_user('dan').with('gid' => 'mygroup', 'uid' => '600') }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/flatten_spec.rb b/code/environments/production/modules/stdlib/spec/functions/flatten_spec.rb
new file mode 100644
index 0000000..df9ce34
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/flatten_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+describe 'flatten', :if => Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params([], []).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params([]).and_return([]) }
+ it { is_expected.to run.with_params(['one']).and_return(['one']) }
+ it { is_expected.to run.with_params([['one']]).and_return(['one']) }
+ it { is_expected.to run.with_params(%w[a b c d e f g]).and_return(%w[a b c d e f g]) }
+ it { is_expected.to run.with_params([['a', 'b', ['c', %w[d e], 'f', 'g']]]).and_return(%w[a b c d e f g]) }
+ it { is_expected.to run.with_params(['ã', 'β', ['ĉ', %w[đ ẽ ƒ ġ]]]).and_return(%w[ã β ĉ đ ẽ ƒ ġ]) }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/floor_spec.rb b/code/environments/production/modules/stdlib/spec/functions/floor_spec.rb
new file mode 100644
index 0000000..c669966
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/floor_spec.rb
@@ -0,0 +1,12 @@
+require 'spec_helper'
+
+describe 'floor' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('foo').and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params(34).and_return(34) }
+ it { is_expected.to run.with_params(-34).and_return(-34) }
+ it { is_expected.to run.with_params(33.1).and_return(33) }
+ it { is_expected.to run.with_params(-33.1).and_return(-34) }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/fqdn_rand_string_spec.rb b/code/environments/production/modules/stdlib/spec/functions/fqdn_rand_string_spec.rb
new file mode 100644
index 0000000..ed6e376
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/fqdn_rand_string_spec.rb
@@ -0,0 +1,67 @@
+require 'spec_helper'
+
+describe 'fqdn_rand_string' do
+ let(:default_charset) { %r{\A[a-zA-Z0-9]{100}\z} }
+
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params(0).and_raise_error(ArgumentError, %r{first argument must be a positive integer}) }
+ it { is_expected.to run.with_params(1.5).and_raise_error(ArgumentError, %r{first argument must be a positive integer}) }
+ it { is_expected.to run.with_params(-10).and_raise_error(ArgumentError, %r{first argument must be a positive integer}) }
+ it { is_expected.to run.with_params('-10').and_raise_error(ArgumentError, %r{first argument must be a positive integer}) }
+ it { is_expected.to run.with_params('string').and_raise_error(ArgumentError, %r{first argument must be a positive integer}) }
+ it { is_expected.to run.with_params([]).and_raise_error(ArgumentError, %r{first argument must be a positive integer}) }
+ it { is_expected.to run.with_params({}).and_raise_error(ArgumentError, %r{first argument must be a positive integer}) }
+ it { is_expected.to run.with_params(1, 1).and_raise_error(ArgumentError, %r{second argument must be undef or a string}) }
+ it { is_expected.to run.with_params(1, []).and_raise_error(ArgumentError, %r{second argument must be undef or a string}) }
+ it { is_expected.to run.with_params(1, {}).and_raise_error(ArgumentError, %r{second argument must be undef or a string}) }
+ it { is_expected.to run.with_params(100).and_return(default_charset) }
+ it { is_expected.to run.with_params('100').and_return(default_charset) }
+ it { is_expected.to run.with_params(100, nil).and_return(default_charset) }
+ it { is_expected.to run.with_params(100, '').and_return(default_charset) }
+ it { is_expected.to run.with_params(100, 'a').and_return(%r{\Aa{100}\z}) }
+ it { is_expected.to run.with_params(100, 'ab').and_return(%r{\A[ab]{100}\z}) }
+ it { is_expected.to run.with_params(100, 'ãβ').and_return(%r{\A[ãβ]{100}\z}) }
+
+ it "provides the same 'random' value on subsequent calls for the same host" do
+ expect(fqdn_rand_string(10)).to eql(fqdn_rand_string(10))
+ end
+
+ it 'considers the same host and same extra arguments to have the same random sequence' do
+ first_random = fqdn_rand_string(10, :extra_identifier => [1, 'same', 'host'])
+ second_random = fqdn_rand_string(10, :extra_identifier => [1, 'same', 'host'])
+
+ expect(first_random).to eql(second_random)
+ end
+
+ it 'allows extra arguments to control the random value on a single host' do
+ first_random = fqdn_rand_string(10, :extra_identifier => [1, 'different', 'host'])
+ second_different_random = fqdn_rand_string(10, :extra_identifier => [2, 'different', 'host'])
+
+ expect(first_random).not_to eql(second_different_random)
+ end
+
+ it 'returns different strings for different hosts' do
+ val1 = fqdn_rand_string(10, :host => 'first.host.com')
+ val2 = fqdn_rand_string(10, :host => 'second.host.com')
+
+ expect(val1).not_to eql(val2)
+ end
+
+ def fqdn_rand_string(max, args = {})
+ host = args[:host] || '127.0.0.1'
+ charset = args[:charset]
+ extra = args[:extra_identifier] || []
+
+ # workaround not being able to use let(:facts) because some tests need
+ # multiple different hostnames in one context
+ scope.stubs(:lookupvar).with('::fqdn', {}).returns(host)
+
+ function_args = [max]
+ if args.key?(:charset) || !extra.empty?
+ function_args << charset
+ end
+ function_args += extra
+ scope.function_fqdn_rand_string(function_args)
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/fqdn_rotate_spec.rb b/code/environments/production/modules/stdlib/spec/functions/fqdn_rotate_spec.rb
new file mode 100644
index 0000000..93e0bba
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/fqdn_rotate_spec.rb
@@ -0,0 +1,74 @@
+require 'spec_helper'
+
+describe 'fqdn_rotate' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params(0).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work with}) }
+ it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work with}) }
+ it { is_expected.to run.with_params('').and_return('') }
+ it { is_expected.to run.with_params('a').and_return('a') }
+ it { is_expected.to run.with_params('ã').and_return('ã') }
+
+ it { is_expected.to run.with_params([]).and_return([]) }
+ it { is_expected.to run.with_params(['a']).and_return(['a']) }
+
+ it 'rotates a string and the result should be the same size' do
+ expect(fqdn_rotate('asdf').size).to eq(4)
+ end
+
+ it 'rotates a string to give the same results for one host' do
+ val1 = fqdn_rotate('abcdefg', :host => 'one')
+ val2 = fqdn_rotate('abcdefg', :host => 'one')
+ expect(val1).to eq(val2)
+ end
+
+ it 'allows extra arguments to control the random rotation on a single host' do
+ val1 = fqdn_rotate('abcdefg', :extra_identifier => [1, 'different', 'host'])
+ val2 = fqdn_rotate('abcdefg', :extra_identifier => [2, 'different', 'host'])
+ expect(val1).not_to eq(val2)
+ end
+
+ it 'considers the same host and same extra arguments to have the same random rotation' do
+ val1 = fqdn_rotate('abcdefg', :extra_identifier => [1, 'same', 'host'])
+ val2 = fqdn_rotate('abcdefg', :extra_identifier => [1, 'same', 'host'])
+ expect(val1).to eq(val2)
+ end
+
+ it 'rotates a string to give different values on different hosts' do
+ val1 = fqdn_rotate('abcdefg', :host => 'one')
+ val2 = fqdn_rotate('abcdefg', :host => 'two')
+ expect(val1).not_to eq(val2)
+ end
+
+ it 'accepts objects which extend String' do
+ result = fqdn_rotate(AlsoString.new('asdf'))
+ expect(result).to eq('dfas')
+ end
+
+ it 'uses the Puppet::Util.deterministic_rand function' do
+ skip 'Puppet::Util#deterministic_rand not available' unless Puppet::Util.respond_to?(:deterministic_rand)
+
+ Puppet::Util.expects(:deterministic_rand).with(44_489_829_212_339_698_569_024_999_901_561_968_770, 4)
+ fqdn_rotate('asdf')
+ end
+
+ it 'does not leave the global seed in a deterministic state' do
+ fqdn_rotate('asdf')
+ rand1 = rand
+ fqdn_rotate('asdf')
+ rand2 = rand
+ expect(rand1).not_to eql(rand2)
+ end
+
+ def fqdn_rotate(value, args = {})
+ host = args[:host] || '127.0.0.1'
+ extra = args[:extra_identifier] || []
+
+ # workaround not being able to use let(:facts) because some tests need
+ # multiple different hostnames in one context
+ scope.stubs(:lookupvar).with('::fqdn').returns(host)
+
+ function_args = [value] + extra
+ scope.function_fqdn_rotate(function_args)
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/fqdn_uuid_spec.rb b/code/environments/production/modules/stdlib/spec/functions/fqdn_uuid_spec.rb
new file mode 100644
index 0000000..a6da6f2
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/fqdn_uuid_spec.rb
@@ -0,0 +1,12 @@
+require 'spec_helper'
+
+describe 'fqdn_uuid' do
+ context 'with invalid parameters' do
+ it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{No arguments given$}) }
+ end
+
+ context 'with given string' do
+ it { is_expected.to run.with_params('puppetlabs.com').and_return('9c70320f-6815-5fc5-ab0f-debe68bf764c') }
+ it { is_expected.to run.with_params('google.com').and_return('64ee70a4-8cc1-5d25-abf2-dea6c79a09c8') }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/get_module_path_spec.rb b/code/environments/production/modules/stdlib/spec/functions/get_module_path_spec.rb
new file mode 100644
index 0000000..81290cb
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/get_module_path_spec.rb
@@ -0,0 +1,49 @@
+require 'spec_helper'
+
+describe 'get_module_path' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{Wrong number of arguments, expects one}) }
+ it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, %r{Wrong number of arguments, expects one}) }
+ it { is_expected.to run.with_params('one', 'two', 'three').and_raise_error(Puppet::ParseError, %r{Wrong number of arguments, expects one}) }
+ it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, %r{Could not find module}) }
+
+ class StubModule
+ attr_reader :path
+ def initialize(path)
+ @path = path
+ end
+ end
+
+ describe 'when locating a module' do
+ let(:modulepath) { '/tmp/does_not_exist' }
+ let(:path_of_module_foo) { StubModule.new('/tmp/does_not_exist/foo') }
+
+ before(:each) { Puppet[:modulepath] = modulepath }
+
+ context 'when in the default environment' do
+ before(:each) { Puppet::Module.expects(:find).with('foo', 'rp_env').returns(path_of_module_foo) }
+
+ it { is_expected.to run.with_params('foo').and_return(path_of_module_foo.path) }
+
+ context 'when the modulepath is a list' do
+ before(:each) { Puppet[:modulepath] = modulepath + 'tmp/something_else' }
+
+ it { is_expected.to run.with_params('foo').and_return(path_of_module_foo.path) }
+ end
+ end
+
+ context 'when in a non-default default environment' do
+ let(:environment) { 'test' }
+
+ before(:each) { Puppet::Module.expects(:find).with('foo', 'test').returns(path_of_module_foo) }
+
+ it { is_expected.to run.with_params('foo').and_return(path_of_module_foo.path) }
+
+ context 'when the modulepath is a list' do
+ before(:each) { Puppet[:modulepath] = modulepath + 'tmp/something_else' }
+
+ it { is_expected.to run.with_params('foo').and_return(path_of_module_foo.path) }
+ end
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/getparam_spec.rb b/code/environments/production/modules/stdlib/spec/functions/getparam_spec.rb
new file mode 100644
index 0000000..3a3cc27
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/getparam_spec.rb
@@ -0,0 +1,34 @@
+require 'spec_helper'
+
+describe 'getparam' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{Must specify a reference}) }
+ it { is_expected.to run.with_params('User[one]').and_raise_error(ArgumentError, %r{Must specify name of a parameter}) }
+ it { is_expected.to run.with_params('User[one]', 2).and_raise_error(ArgumentError, %r{Must specify name of a parameter}) }
+ it { is_expected.to run.with_params('User[one]', []).and_raise_error(ArgumentError, %r{Must specify name of a parameter}) }
+ it { is_expected.to run.with_params('User[one]', {}).and_raise_error(ArgumentError, %r{Must specify name of a parameter}) }
+
+ describe 'when compared against a user resource with no params' do
+ let(:pre_condition) { 'user { "one": }' }
+
+ it { is_expected.to run.with_params('User[one]', 'ensure').and_return('') }
+ it { is_expected.to run.with_params('User[two]', 'ensure').and_return('') }
+ it { is_expected.to run.with_params('User[one]', 'shell').and_return('') }
+ end
+
+ describe 'when compared against a user resource with params' do
+ let(:pre_condition) { 'user { "one": ensure => present, shell => "/bin/sh", managehome => false, }' }
+
+ it { is_expected.to run.with_params('User[one]', 'ensure').and_return('present') }
+ it { is_expected.to run.with_params('User[two]', 'ensure').and_return('') }
+ it { is_expected.to run.with_params('User[one]', 'shell').and_return('/bin/sh') }
+ it { is_expected.to run.with_params('User[one]', 'managehome').and_return(false) }
+ end
+
+ describe 'when compared against a user resource with UTF8 and double byte params' do
+ let(:pre_condition) { 'user { ["三", "ƒốưř"]: ensure => present }' }
+
+ it { is_expected.to run.with_params('User[三]', 'ensure').and_return('present') }
+ it { is_expected.to run.with_params('User[ƒốưř]', 'ensure').and_return('present') }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/getvar_spec.rb b/code/environments/production/modules/stdlib/spec/functions/getvar_spec.rb
new file mode 100644
index 0000000..cb865c7
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/getvar_spec.rb
@@ -0,0 +1,36 @@
+require 'spec_helper'
+
+describe 'getvar' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+
+ it { is_expected.to run.with_params('$::foo').and_return(nil) }
+
+ context 'with given variables in namespaces' do
+ let(:pre_condition) do
+ <<-PUPPETCODE
+ class site::data { $foo = 'baz' }
+ include site::data
+ PUPPETCODE
+ end
+
+ it { is_expected.to run.with_params('site::data::foo').and_return('baz') }
+ it { is_expected.to run.with_params('::site::data::foo').and_return('baz') }
+ it { is_expected.to run.with_params('::site::data::bar').and_return(nil) }
+ end
+
+ context 'with given variables in namespaces' do
+ let(:pre_condition) do
+ <<-PUPPETCODE
+ class site::info { $lock = 'ŧҺîš íš ắ śţřĭŋĝ' }
+ class site::new { $item = '万Ü€‰' }
+ include site::info
+ include site::new
+ PUPPETCODE
+ end
+
+ it { is_expected.to run.with_params('site::info::lock').and_return('ŧҺîš íš ắ śţřĭŋĝ') }
+ it { is_expected.to run.with_params('::site::new::item').and_return('万Ü€‰') }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/glob_spec.rb b/code/environments/production/modules/stdlib/spec/functions/glob_spec.rb
new file mode 100644
index 0000000..209aca6
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/glob_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe 'glob' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('').and_return([]) }
+ it { is_expected.to run.with_params(['']).and_return([]) }
+ it { is_expected.to run.with_params(['', '']).and_return([]) }
+ it { is_expected.to run.with_params(['/etc/xyzxyzxyz', '/etcxyzxyzxyz']).and_return([]) }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/grep_spec.rb b/code/environments/production/modules/stdlib/spec/functions/grep_spec.rb
new file mode 100644
index 0000000..1122ffb
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/grep_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe 'grep' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it {
+ pending('grep does not actually check this, and raises NoMethodError instead')
+ is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, %r{first argument not an array})
+ }
+ it {
+ pending('grep does not actually check this, and raises NoMethodError instead')
+ is_expected.to run.with_params(1, 'two').and_raise_error(Puppet::ParseError, %r{first argument not an array})
+ }
+ it { is_expected.to run.with_params('one', 'two', 'three').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params([], 'two').and_return([]) }
+ it { is_expected.to run.with_params(%w[one two three], 'two').and_return(['two']) }
+ it { is_expected.to run.with_params(%w[one two three], 't(wo|hree)').and_return(%w[two three]) }
+ it { is_expected.to run.with_params(%w[ờאּê ţשּׂỡ ţһŗəè], 'ţ(שּׂỡ|һŗəè)').and_return(%w[ţשּׂỡ ţһŗəè]) }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/has_interface_with_spec.rb b/code/environments/production/modules/stdlib/spec/functions/has_interface_with_spec.rb
new file mode 100644
index 0000000..273ecb2
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/has_interface_with_spec.rb
@@ -0,0 +1,39 @@
+require 'spec_helper'
+
+describe 'has_interface_with' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('one', 'two', 'three').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+
+ # We need to mock out the Facts so we can specify how we expect this function
+ # to behave on different platforms.
+ context 'when on Mac OS X Systems' do
+ let(:facts) { { :interfaces => 'lo0,gif0,stf0,en1,p2p0,fw0,en0,vmnet1,vmnet8,utun0' } }
+
+ it { is_expected.to run.with_params('lo0').and_return(true) }
+ it { is_expected.to run.with_params('lo').and_return(false) }
+ end
+
+ context 'when on Linux Systems' do
+ let(:facts) do
+ {
+ :interfaces => 'eth0,lo',
+ :ipaddress => '10.0.0.1',
+ :ipaddress_lo => '127.0.0.1',
+ :ipaddress_eth0 => '10.0.0.1',
+ :muppet => 'kermit',
+ :muppet_lo => 'mspiggy',
+ :muppet_eth0 => 'kermit',
+ }
+ end
+
+ it { is_expected.to run.with_params('lo').and_return(true) }
+ it { is_expected.to run.with_params('lo0').and_return(false) }
+ it { is_expected.to run.with_params('ipaddress', '127.0.0.1').and_return(true) }
+ it { is_expected.to run.with_params('ipaddress', '10.0.0.1').and_return(true) }
+ it { is_expected.to run.with_params('ipaddress', '8.8.8.8').and_return(false) }
+ it { is_expected.to run.with_params('muppet', 'kermit').and_return(true) }
+ it { is_expected.to run.with_params('muppet', 'mspiggy').and_return(true) }
+ it { is_expected.to run.with_params('muppet', 'bigbird').and_return(false) }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/has_ip_address_spec.rb b/code/environments/production/modules/stdlib/spec/functions/has_ip_address_spec.rb
new file mode 100644
index 0000000..33934f3
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/has_ip_address_spec.rb
@@ -0,0 +1,22 @@
+require 'spec_helper'
+
+describe 'has_ip_address' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+
+ context 'when on Linux Systems' do
+ let(:facts) do
+ {
+ :interfaces => 'eth0,lo',
+ :ipaddress => '10.0.0.1',
+ :ipaddress_lo => '127.0.0.1',
+ :ipaddress_eth0 => '10.0.0.1',
+ }
+ end
+
+ it { is_expected.to run.with_params('127.0.0.1').and_return(true) }
+ it { is_expected.to run.with_params('10.0.0.1').and_return(true) }
+ it { is_expected.to run.with_params('8.8.8.8').and_return(false) }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/has_ip_network_spec.rb b/code/environments/production/modules/stdlib/spec/functions/has_ip_network_spec.rb
new file mode 100644
index 0000000..cc6ff0b
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/has_ip_network_spec.rb
@@ -0,0 +1,21 @@
+require 'spec_helper'
+
+describe 'has_ip_network' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+
+ context 'when on Linux Systems' do
+ let(:facts) do
+ {
+ :interfaces => 'eth0,lo',
+ :network_lo => '127.0.0.0',
+ :network_eth0 => '10.0.0.0',
+ }
+ end
+
+ it { is_expected.to run.with_params('127.0.0.0').and_return(true) }
+ it { is_expected.to run.with_params('10.0.0.0').and_return(true) }
+ it { is_expected.to run.with_params('8.8.8.0').and_return(false) }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/has_key_spec.rb b/code/environments/production/modules/stdlib/spec/functions/has_key_spec.rb
new file mode 100644
index 0000000..6abebba
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/has_key_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe 'has_key' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('one', 'two', 'three').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, %r{expects the first argument to be a hash}) }
+ it { is_expected.to run.with_params(1, 'two').and_raise_error(Puppet::ParseError, %r{expects the first argument to be a hash}) }
+ it { is_expected.to run.with_params([], 'two').and_raise_error(Puppet::ParseError, %r{expects the first argument to be a hash}) }
+
+ it { is_expected.to run.with_params({ 'key' => 'value' }, 'key').and_return(true) }
+ it { is_expected.to run.with_params({}, 'key').and_return(false) }
+ it { is_expected.to run.with_params({ 'key' => 'value' }, 'not a key').and_return(false) }
+
+ context 'with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params({ 'κéỳ ' => '٧ậļųể' }, 'κéỳ ').and_return(true) }
+ it { is_expected.to run.with_params({ 'キー' => '٧ậļųể' }, 'キー').and_return(true) }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/hash_spec.rb b/code/environments/production/modules/stdlib/spec/functions/hash_spec.rb
new file mode 100644
index 0000000..f32d54f
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/hash_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+describe 'hash' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it {
+ pending('Current implementation ignores parameters after the first.')
+ is_expected.to run.with_params([], 'two').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
+ }
+ it { is_expected.to run.with_params(['one']).and_raise_error(Puppet::ParseError, %r{Unable to compute}) }
+ it { is_expected.to run.with_params([]).and_return({}) }
+ it { is_expected.to run.with_params(%w[key1 value1]).and_return('key1' => 'value1') }
+ it { is_expected.to run.with_params(['κ℮ұ1', '√āĺűẻ1']).and_return('κ℮ұ1' => '√āĺűẻ1') }
+ it { is_expected.to run.with_params(%w[key1 value1 key2 value2]).and_return('key1' => 'value1', 'key2' => 'value2') }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/intersection_spec.rb b/code/environments/production/modules/stdlib/spec/functions/intersection_spec.rb
new file mode 100644
index 0000000..4589928
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/intersection_spec.rb
@@ -0,0 +1,22 @@
+require 'spec_helper'
+
+describe 'intersection' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('one', 'two', 'three').and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('one', []).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params([], 'two').and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params({}, {}).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params([], []).and_return([]) }
+ it { is_expected.to run.with_params([], ['one']).and_return([]) }
+ it { is_expected.to run.with_params(['one'], []).and_return([]) }
+ it { is_expected.to run.with_params(['one'], ['one']).and_return(['one']) }
+ it { is_expected.to run.with_params(%w[one two three], %w[two three]).and_return(%w[two three]) }
+ it { is_expected.to run.with_params(%w[ōŋể ŧשợ ţђŕẽё], %w[ŧשợ ţђŕẽё]).and_return(%w[ŧשợ ţђŕẽё]) }
+ it { is_expected.to run.with_params(%w[one two two three], %w[two three]).and_return(%w[two three]) }
+ it { is_expected.to run.with_params(%w[one two three], %w[two two three]).and_return(%w[two three]) }
+ it { is_expected.to run.with_params(%w[one two three], %w[two three four]).and_return(%w[two three]) }
+ it 'does not confuse types' do is_expected.to run.with_params(%w[1 2 3], [1, 2]).and_return([]) end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/is_a_spec.rb b/code/environments/production/modules/stdlib/spec/functions/is_a_spec.rb
new file mode 100644
index 0000000..a5fe590
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/is_a_spec.rb
@@ -0,0 +1,32 @@
+require 'spec_helper'
+
+if ENV['FUTURE_PARSER'] == 'yes'
+ describe 'type_of' do
+ pending 'teach rspec-puppet to load future-only functions under 3.7.5' do
+ it { is_expected.not_to eq(nil) }
+ end
+ end
+end
+
+if Puppet.version.to_f >= 4.0
+ describe 'is_a' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(ArgumentError) }
+ it { is_expected.to run.with_params('', '').and_raise_error(ArgumentError) }
+
+ it 'succeeds when comparing a string and a string' do
+ is_expected.to run.with_params('hello world', String).and_return(true)
+ end
+
+ it 'fails when comparing an integer and a string' do
+ is_expected.to run.with_params(5, String).and_return(false)
+ end
+
+ it 'suceeds when comparing an UTF8 and double byte characters' do
+ comparison_array = ['このテキスト', 'ŧћịś ŧêχŧ']
+ comparison_array.each do |comparison_value|
+ is_expected.to run.with_params(comparison_value, String).and_return(true)
+ end
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/is_array_spec.rb b/code/environments/production/modules/stdlib/spec/functions/is_array_spec.rb
new file mode 100644
index 0000000..c6c016a
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/is_array_spec.rb
@@ -0,0 +1,35 @@
+require 'spec_helper'
+
+describe 'is_array' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it {
+ pending('Current implementation ignores parameters after the first.')
+ is_expected.to run.with_params([], []).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
+ }
+ it { is_expected.to run.with_params([]).and_return(true) }
+ it { is_expected.to run.with_params(['one']).and_return(true) }
+ it { is_expected.to run.with_params([1]).and_return(true) }
+ it { is_expected.to run.with_params([{}]).and_return(true) }
+ it { is_expected.to run.with_params([[]]).and_return(true) }
+ it { is_expected.to run.with_params('').and_return(false) }
+ it { is_expected.to run.with_params('one').and_return(false) }
+ it { is_expected.to run.with_params(1).and_return(false) }
+ it { is_expected.to run.with_params({}).and_return(false) }
+ context 'with deprecation warning' do
+ after(:each) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
+ it 'displays a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params(['1.2.3.4']).and_return(true)
+ end
+ it 'displays no warning for deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'false'
+ scope.expects(:warning).with(includes('This method is deprecated')).never
+ is_expected.to run.with_params(['1.2.3.4']).and_return(true)
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/is_bool_spec.rb b/code/environments/production/modules/stdlib/spec/functions/is_bool_spec.rb
new file mode 100644
index 0000000..182ef70
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/is_bool_spec.rb
@@ -0,0 +1,31 @@
+require 'spec_helper'
+
+describe 'is_bool' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params(true, false).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params(true).and_return(true) }
+ it { is_expected.to run.with_params(false).and_return(true) }
+ it { is_expected.to run.with_params([1]).and_return(false) }
+ it { is_expected.to run.with_params([{}]).and_return(false) }
+ it { is_expected.to run.with_params([[]]).and_return(false) }
+ it { is_expected.to run.with_params([true]).and_return(false) }
+ it { is_expected.to run.with_params('true').and_return(false) }
+ it { is_expected.to run.with_params('false').and_return(false) }
+ context 'with deprecation warning' do
+ after(:each) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
+ it 'displays a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params(true).and_return(true)
+ end
+ it 'displays no warning for deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'false'
+ scope.expects(:warning).with(includes('This method is deprecated')).never
+ is_expected.to run.with_params(false).and_return(true)
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/is_domain_name_spec.rb b/code/environments/production/modules/stdlib/spec/functions/is_domain_name_spec.rb
new file mode 100644
index 0000000..c2d5988
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/is_domain_name_spec.rb
@@ -0,0 +1,43 @@
+require 'spec_helper'
+
+describe 'is_domain_name' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params(1).and_return(false) }
+ it { is_expected.to run.with_params([]).and_return(false) }
+ it { is_expected.to run.with_params({}).and_return(false) }
+ it { is_expected.to run.with_params('').and_return(false) }
+ it { is_expected.to run.with_params('.').and_return(true) }
+ it { is_expected.to run.with_params('com').and_return(true) }
+ it { is_expected.to run.with_params('com.').and_return(true) }
+ it { is_expected.to run.with_params('x.com').and_return(true) }
+ it { is_expected.to run.with_params('x.com.').and_return(true) }
+ it { is_expected.to run.with_params('foo.example.com').and_return(true) }
+ it { is_expected.to run.with_params('foo.example.com.').and_return(true) }
+ it { is_expected.to run.with_params('2foo.example.com').and_return(true) }
+ it { is_expected.to run.with_params('2foo.example.com.').and_return(true) }
+ it { is_expected.to run.with_params('www.2foo.example.com').and_return(true) }
+ it { is_expected.to run.with_params('www.2foo.example.com.').and_return(true) }
+ describe 'inputs with spaces' do
+ it { is_expected.to run.with_params('invalid domain').and_return(false) }
+ end
+ describe 'inputs with hyphens' do
+ it { is_expected.to run.with_params('foo-bar.example.com').and_return(true) }
+ it { is_expected.to run.with_params('foo-bar.example.com.').and_return(true) }
+ it { is_expected.to run.with_params('www.foo-bar.example.com').and_return(true) }
+ it { is_expected.to run.with_params('www.foo-bar.example.com.').and_return(true) }
+ it { is_expected.to run.with_params('-foo.example.com').and_return(false) }
+ it { is_expected.to run.with_params('-foo.example.com.').and_return(false) }
+ end
+ # Values obtained from Facter values will be frozen strings
+ # in newer versions of Facter:
+ it { is_expected.to run.with_params('www.example.com'.freeze).and_return(true) }
+ describe 'top level domain must be alphabetic if there are multiple labels' do
+ it { is_expected.to run.with_params('2com').and_return(true) }
+ it { is_expected.to run.with_params('www.example.2com').and_return(false) }
+ end
+ describe 'IP addresses are not domain names' do
+ it { is_expected.to run.with_params('192.168.1.1').and_return(false) }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/is_email_address_spec.rb b/code/environments/production/modules/stdlib/spec/functions/is_email_address_spec.rb
new file mode 100644
index 0000000..6c291e6
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/is_email_address_spec.rb
@@ -0,0 +1,14 @@
+require 'spec_helper'
+
+describe 'is_email_address' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params([], []).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('bob@gmail.com').and_return(true) }
+ it { is_expected.to run.with_params('alice+puppetlabs.com@gmail.com').and_return(true) }
+ it { is_expected.to run.with_params('peter.parker@gmail.com').and_return(true) }
+ it { is_expected.to run.with_params('1.2.3@domain').and_return(false) }
+ it { is_expected.to run.with_params('1.2.3.4.5@').and_return(false) }
+ it { is_expected.to run.with_params({}).and_return(false) }
+ it { is_expected.to run.with_params([]).and_return(false) }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/is_float_spec.rb b/code/environments/production/modules/stdlib/spec/functions/is_float_spec.rb
new file mode 100644
index 0000000..6f59c3e
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/is_float_spec.rb
@@ -0,0 +1,40 @@
+require 'spec_helper'
+
+describe 'is_float' do
+ it { is_expected.not_to eq(nil) }
+
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params(0.1, 0.2).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+
+ describe 'passing a string' do
+ it { is_expected.to run.with_params('0.1').and_return(true) }
+ it { is_expected.to run.with_params('1.0').and_return(true) }
+ it { is_expected.to run.with_params('1').and_return(false) }
+ it { is_expected.to run.with_params('one').and_return(false) }
+ it { is_expected.to run.with_params('one 1.0').and_return(false) }
+ it { is_expected.to run.with_params('1.0 one').and_return(false) }
+ end
+
+ describe 'passing numbers' do
+ it { is_expected.to run.with_params(0.1).and_return(true) }
+ it { is_expected.to run.with_params(1.0).and_return(true) }
+ it { is_expected.to run.with_params(1).and_return(false) }
+ end
+
+ context 'with deprecation warning' do
+ after(:each) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
+ it 'displays a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params(2.2).and_return(true)
+ end
+ it 'displays no warning for deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'false'
+ scope.expects(:warning).with(includes('This method is deprecated')).never
+ is_expected.to run.with_params(1.0).and_return(true)
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/is_function_available_spec.rb b/code/environments/production/modules/stdlib/spec/functions/is_function_available_spec.rb
new file mode 100644
index 0000000..887f069
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/is_function_available_spec.rb
@@ -0,0 +1,9 @@
+require 'spec_helper'
+
+describe 'is_function_available' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('include').and_return(true) }
+ it { is_expected.to run.with_params('no_such_function').and_return(false) }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/is_hash_spec.rb b/code/environments/production/modules/stdlib/spec/functions/is_hash_spec.rb
new file mode 100644
index 0000000..3ef061d
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/is_hash_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe 'is_hash' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params({}, {}).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('').and_return(false) }
+ it { is_expected.to run.with_params({}).and_return(true) }
+ it { is_expected.to run.with_params([]).and_return(false) }
+ it { is_expected.to run.with_params(1).and_return(false) }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/is_integer_spec.rb b/code/environments/production/modules/stdlib/spec/functions/is_integer_spec.rb
new file mode 100644
index 0000000..00262ce
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/is_integer_spec.rb
@@ -0,0 +1,46 @@
+require 'spec_helper'
+
+describe 'is_integer' do
+ it { is_expected.not_to eq(nil) }
+
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params(1, 2).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+
+ it { is_expected.to run.with_params(3).and_return(true) }
+ it { is_expected.to run.with_params('3').and_return(true) }
+ it { is_expected.to run.with_params(-3).and_return(true) }
+ it { is_expected.to run.with_params('-3').and_return(true) }
+ it { is_expected.to run.with_params("123\nfoo").and_return(true) }
+ it { is_expected.to run.with_params("foo\n123").and_return(true) }
+
+ it { is_expected.to run.with_params(3.7).and_return(false) }
+ it { is_expected.to run.with_params('3.7').and_return(false) }
+ it { is_expected.to run.with_params(-3.7).and_return(false) }
+ it { is_expected.to run.with_params('-3.7').and_return(false) }
+
+ it { is_expected.to run.with_params('one').and_return(false) }
+ it { is_expected.to run.with_params([]).and_return(false) }
+ it { is_expected.to run.with_params([1]).and_return(false) }
+ it { is_expected.to run.with_params({}).and_return(false) }
+ it { is_expected.to run.with_params(true).and_return(false) }
+ it { is_expected.to run.with_params(false).and_return(false) }
+ it { is_expected.to run.with_params('0001234').and_return(false) }
+ it { is_expected.to run.with_params("foo\nbar").and_return(false) }
+
+ context 'with deprecation warning' do
+ after(:each) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
+ it 'displays a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params(50).and_return(true)
+ end
+ it 'displays no warning for deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'false'
+ scope.expects(:warning).with(includes('This method is deprecated')).never
+ is_expected.to run.with_params(50).and_return(true)
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/is_ip_address_spec.rb b/code/environments/production/modules/stdlib/spec/functions/is_ip_address_spec.rb
new file mode 100644
index 0000000..1c05726
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/is_ip_address_spec.rb
@@ -0,0 +1,40 @@
+require 'spec_helper'
+
+describe 'is_ip_address' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params([], []).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('1.2.3.4').and_return(true) }
+ it { is_expected.to run.with_params('1.2.3.255').and_return(true) }
+ it { is_expected.to run.with_params('1.2.3.256').and_return(false) }
+ it { is_expected.to run.with_params('1.2.3').and_return(false) }
+ it { is_expected.to run.with_params('1.2.3.4.5').and_return(false) }
+ it { is_expected.to run.with_params('fe00::1').and_return(true) }
+ it { is_expected.to run.with_params('fe80:0000:cd12:d123:e2f8:47ff:fe09:dd74').and_return(true) }
+ it { is_expected.to run.with_params('FE80:0000:CD12:D123:E2F8:47FF:FE09:DD74').and_return(true) }
+ it { is_expected.to run.with_params('fe80:0000:cd12:d123:e2f8:47ff:fe09:zzzz').and_return(false) }
+ it { is_expected.to run.with_params('fe80:0000:cd12:d123:e2f8:47ff:fe09').and_return(false) }
+ it { is_expected.to run.with_params('fe80:0000:cd12:d123:e2f8:47ff:fe09:dd74:dd74').and_return(false) }
+ it { is_expected.to run.with_params('').and_return(false) }
+ it { is_expected.to run.with_params('one').and_return(false) }
+ it { is_expected.to run.with_params(1).and_return(false) }
+ it { is_expected.to run.with_params({}).and_return(false) }
+ it { is_expected.to run.with_params([]).and_return(false) }
+
+ context 'Checking for deprecation warning', :if => Puppet.version.to_f < 4.0 do
+ # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
+ it 'displays a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('1.2.3.4').and_return(true)
+ end
+ it 'displays no warning for deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'false'
+ scope.expects(:warning).with(includes('This method is deprecated')).never
+ is_expected.to run.with_params('1.2.3.4').and_return(true)
+ end
+ after(:each) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/is_ipv4_address_spec.rb b/code/environments/production/modules/stdlib/spec/functions/is_ipv4_address_spec.rb
new file mode 100644
index 0000000..fdc2206
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/is_ipv4_address_spec.rb
@@ -0,0 +1,31 @@
+require 'spec_helper'
+
+describe 'is_ipv4_address' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+
+ SharedData::IPV4_PATTERNS.each do |value|
+ it { is_expected.to run.with_params(value).and_return(true) }
+ end
+
+ SharedData::IPV4_NEGATIVE_PATTERNS.each do |value|
+ it { is_expected.to run.with_params(value).and_return(false) }
+ end
+
+ context 'Checking for deprecation warning', :if => Puppet.version.to_f < 4.0 do
+ after(:each) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
+ it 'displays a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params(SharedData::IPV4_PATTERNS.first).and_return(true)
+ end
+ it 'displays no warning for deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'false'
+ scope.expects(:warning).with(includes('This method is deprecated')).never
+ is_expected.to run.with_params(SharedData::IPV4_PATTERNS.first).and_return(true)
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/is_ipv6_address_spec.rb b/code/environments/production/modules/stdlib/spec/functions/is_ipv6_address_spec.rb
new file mode 100644
index 0000000..d85bef3
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/is_ipv6_address_spec.rb
@@ -0,0 +1,29 @@
+require 'spec_helper'
+
+describe 'is_ipv6_address' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('2001:0db8:85a3:0000:0000:8a2e:0370:7334').and_return(true) }
+ it { is_expected.to run.with_params('85a3:0000:0000:8a2e:0370:7334:100.100.100.100').and_return(true) }
+ it { is_expected.to run.with_params('1.2.3').and_return(false) }
+ it { is_expected.to run.with_params('1.2.3.4.5').and_return(false) }
+ it { is_expected.to run.with_params('').and_return(false) }
+ it { is_expected.to run.with_params('one').and_return(false) }
+
+ context 'Checking for deprecation warning', :if => Puppet.version.to_f < 4.0 do
+ after(:each) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
+ it 'displays a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('2001:0db8:85a3:0000:0000:8a2e:0370:7334').and_return(true)
+ end
+ it 'displays no warning for deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'false'
+ scope.expects(:warning).with(includes('This method is deprecated')).never
+ is_expected.to run.with_params('2001:0db8:85a3:0000:0000:8a2e:0370:7334').and_return(true)
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/is_mac_address_spec.rb b/code/environments/production/modules/stdlib/spec/functions/is_mac_address_spec.rb
new file mode 100644
index 0000000..1f15702
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/is_mac_address_spec.rb
@@ -0,0 +1,30 @@
+require 'spec_helper'
+
+describe 'is_mac_address' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params([], []).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('00:a0:1f:12:7f:a0').and_return(true) }
+ it { is_expected.to run.with_params('00:A0:1F:12:7F:A0').and_return(true) }
+ it { is_expected.to run.with_params('00:00:00:00:00:0g').and_return(false) }
+ it { is_expected.to run.with_params('').and_return(false) }
+ it { is_expected.to run.with_params('one').and_return(false) }
+
+ context 'with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params('ƒốưř').and_return(false) }
+ it { is_expected.to run.with_params('三+').and_return(false) }
+ end
+
+ it {
+ pending 'should properly typecheck its arguments'
+ is_expected.to run.with_params(1).and_return(false)
+ }
+ it {
+ pending 'should properly typecheck its arguments'
+ is_expected.to run.with_params({}).and_return(false)
+ }
+ it {
+ pending 'should properly typecheck its arguments'
+ is_expected.to run.with_params([]).and_return(false)
+ }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/is_numeric_spec.rb b/code/environments/production/modules/stdlib/spec/functions/is_numeric_spec.rb
new file mode 100644
index 0000000..c936d73
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/is_numeric_spec.rb
@@ -0,0 +1,46 @@
+require 'spec_helper'
+
+describe 'is_numeric' do
+ it { is_expected.not_to eq(nil) }
+
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params(1, 2).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+
+ it { is_expected.to run.with_params(3).and_return(true) }
+ it { is_expected.to run.with_params('3').and_return(true) }
+ it { is_expected.to run.with_params(-3).and_return(true) }
+ it { is_expected.to run.with_params('-3').and_return(true) }
+
+ it { is_expected.to run.with_params(3.7).and_return(true) }
+ it { is_expected.to run.with_params('3.7').and_return(true) }
+ it { is_expected.to run.with_params(-3.7).and_return(true) }
+ it { is_expected.to run.with_params('-3.7').and_return(true) }
+
+ it { is_expected.to run.with_params('-342.2315e-12').and_return(true) }
+
+ it { is_expected.to run.with_params('one').and_return(false) }
+ it { is_expected.to run.with_params([]).and_return(false) }
+ it { is_expected.to run.with_params([1]).and_return(false) }
+ it { is_expected.to run.with_params({}).and_return(false) }
+ it { is_expected.to run.with_params(true).and_return(false) }
+ it { is_expected.to run.with_params(false).and_return(false) }
+ it { is_expected.to run.with_params('0001234').and_return(false) }
+ it { is_expected.to run.with_params(' - 1234').and_return(false) }
+
+ context 'with deprecation warning' do
+ after(:each) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
+ it 'displays a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params(7).and_return(true)
+ end
+ it 'displays no warning for deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'false'
+ scope.expects(:warning).with(includes('This method is deprecated')).never
+ is_expected.to run.with_params(7).and_return(true)
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/is_string_spec.rb b/code/environments/production/modules/stdlib/spec/functions/is_string_spec.rb
new file mode 100644
index 0000000..98b5578
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/is_string_spec.rb
@@ -0,0 +1,45 @@
+require 'spec_helper'
+
+describe 'is_string' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it {
+ pending('Current implementation ignores parameters after the first.')
+ is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
+ }
+
+ it { is_expected.to run.with_params(3).and_return(false) }
+ it { is_expected.to run.with_params('3').and_return(false) }
+ it { is_expected.to run.with_params(-3).and_return(false) }
+ it { is_expected.to run.with_params('-3').and_return(false) }
+
+ it { is_expected.to run.with_params(3.7).and_return(false) }
+ it { is_expected.to run.with_params('3.7').and_return(false) }
+ it { is_expected.to run.with_params(-3.7).and_return(false) }
+ it { is_expected.to run.with_params('-3.7').and_return(false) }
+
+ it { is_expected.to run.with_params([]).and_return(false) }
+ it { is_expected.to run.with_params([1]).and_return(false) }
+ it { is_expected.to run.with_params({}).and_return(false) }
+ it { is_expected.to run.with_params(true).and_return(false) }
+ it { is_expected.to run.with_params(false).and_return(false) }
+ it { is_expected.to run.with_params('one').and_return(true) }
+ it { is_expected.to run.with_params('0001234').and_return(true) }
+
+ context 'with deprecation warning' do
+ after(:each) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
+ it 'displays a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('sponge').and_return(true)
+ end
+ it 'displays no warning for deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'false'
+ scope.expects(:warning).with(includes('This method is deprecated')).never
+ is_expected.to run.with_params('bob').and_return(true)
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/join_keys_to_values_spec.rb b/code/environments/production/modules/stdlib/spec/functions/join_keys_to_values_spec.rb
new file mode 100644
index 0000000..8800499
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/join_keys_to_values_spec.rb
@@ -0,0 +1,29 @@
+require 'spec_helper'
+
+describe 'join_keys_to_values' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{Takes exactly two arguments}) }
+ it { is_expected.to run.with_params({}, '', '').and_raise_error(Puppet::ParseError, %r{Takes exactly two arguments}) }
+ it { is_expected.to run.with_params('one', '').and_raise_error(TypeError, %r{The first argument must be a hash}) }
+ it { is_expected.to run.with_params({}, 2).and_raise_error(TypeError, %r{The second argument must be a string}) }
+
+ it { is_expected.to run.with_params({}, '').and_return([]) }
+ it { is_expected.to run.with_params({}, ':').and_return([]) }
+ it { is_expected.to run.with_params({ 'key' => 'value' }, '').and_return(['keyvalue']) }
+ it { is_expected.to run.with_params({ 'key' => 'value' }, ':').and_return(['key:value']) }
+
+ context 'with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params({ 'ҝẽγ' => '√ạĺűē' }, ':').and_return(['ҝẽγ:√ạĺűē']) }
+ it { is_expected.to run.with_params({ 'ҝẽγ' => '√ạĺűē' }, '万').and_return(['ҝẽγ万√ạĺűē']) }
+ end
+
+ it { is_expected.to run.with_params({ 'key' => nil }, ':').and_return(['key:']) }
+ it 'runs join_keys_to_values(<hash with multiple keys>, ":") and return the proper array' do
+ result = subject.call([{ 'key1' => 'value1', 'key2' => 'value2' }, ':'])
+ expect(result.sort).to eq(['key1:value1', 'key2:value2'].sort)
+ end
+ it 'runs join_keys_to_values(<hash with array value>, " ") and return the proper array' do
+ result = subject.call([{ 'key1' => 'value1', 'key2' => %w[value2 value3] }, ' '])
+ expect(result.sort).to eq(['key1 value1', 'key2 value2', 'key2 value3'].sort)
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/join_spec.rb b/code/environments/production/modules/stdlib/spec/functions/join_spec.rb
new file mode 100644
index 0000000..c24ee76
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/join_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe 'join', :if => Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it {
+ pending('Current implementation ignores parameters after the second.')
+ is_expected.to run.with_params([], '', '').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
+ }
+ it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, %r{Requires array to work with}) }
+ it { is_expected.to run.with_params([], 2).and_raise_error(Puppet::ParseError, %r{Requires string to work with}) }
+
+ it { is_expected.to run.with_params([]).and_return('') }
+ it { is_expected.to run.with_params([], ':').and_return('') }
+ it { is_expected.to run.with_params(['one']).and_return('one') }
+ it { is_expected.to run.with_params(['one'], ':').and_return('one') }
+ it { is_expected.to run.with_params(%w[one two three]).and_return('onetwothree') }
+ it { is_expected.to run.with_params(%w[one two three], ':').and_return('one:two:three') }
+ it { is_expected.to run.with_params(%w[ōŋể ŧשợ ţђŕẽё], ':').and_return('ōŋể:ŧשợ:ţђŕẽё') }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/keys_spec.rb b/code/environments/production/modules/stdlib/spec/functions/keys_spec.rb
new file mode 100644
index 0000000..23a870e
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/keys_spec.rb
@@ -0,0 +1,24 @@
+require 'spec_helper'
+
+describe 'keys', :if => Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it {
+ pending('Current implementation ignores parameters after the first.')
+ is_expected.to run.with_params({}, {}).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
+ }
+ it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) }
+ it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) }
+ it { is_expected.to run.with_params({}).and_return([]) }
+ it { is_expected.to run.with_params('key' => 'value').and_return(['key']) }
+ it 'returns the array of keys' do
+ result = subject.call([{ 'key1' => 'value1', 'key2' => 'value2' }])
+ expect(result).to match_array(%w[key1 key2])
+ end
+
+ it 'runs with UTF8 and double byte characters' do
+ result = subject.call([{ 'ҝểү' => '√ẳŀμệ', 'キー' => '値' }])
+ expect(result).to match_array(%w[ҝểү キー])
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/length_spec.rb b/code/environments/production/modules/stdlib/spec/functions/length_spec.rb
new file mode 100644
index 0000000..550c557
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/length_spec.rb
@@ -0,0 +1,31 @@
+require 'spec_helper'
+
+describe 'length', :if => Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{'length' expects 1 argument, got none}) }
+ it { is_expected.to run.with_params([], 'extra').and_raise_error(ArgumentError, %r{'length' expects 1 argument, got 2}) }
+ it { is_expected.to run.with_params(1).and_raise_error(ArgumentError, %r{expects a value of type String, Array, or Hash, got Integer}) }
+ it { is_expected.to run.with_params(true).and_raise_error(ArgumentError, %r{expects a value of type String, Array, or Hash, got Boolean}) }
+ it { is_expected.to run.with_params('1').and_return(1) }
+ it { is_expected.to run.with_params('1.0').and_return(3) }
+ it { is_expected.to run.with_params([]).and_return(0) }
+ it { is_expected.to run.with_params(['a']).and_return(1) }
+ it { is_expected.to run.with_params(%w[one two three]).and_return(3) }
+ it { is_expected.to run.with_params(%w[one two three four]).and_return(4) }
+
+ it { is_expected.to run.with_params({}).and_return(0) }
+ it { is_expected.to run.with_params('1' => '2').and_return(1) }
+ it { is_expected.to run.with_params('1' => '2', '4' => '4').and_return(2) }
+ it { is_expected.to run.with_params('€' => '@', '竹' => 'ǿňè').and_return(2) }
+
+ it { is_expected.to run.with_params('').and_return(0) }
+ it { is_expected.to run.with_params('a').and_return(1) }
+ it { is_expected.to run.with_params('abc').and_return(3) }
+ it { is_expected.to run.with_params('abcd').and_return(4) }
+ it { is_expected.to run.with_params('万').and_return(1) }
+ it { is_expected.to run.with_params('āβćđ').and_return(4) }
+
+ context 'when using a class extending String' do
+ it { is_expected.to run.with_params(AlsoString.new('asdfghjkl')).and_return(9) }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/load_module_metadata_spec.rb b/code/environments/production/modules/stdlib/spec/functions/load_module_metadata_spec.rb
new file mode 100644
index 0000000..eb9a94b
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/load_module_metadata_spec.rb
@@ -0,0 +1,47 @@
+require 'spec_helper'
+
+describe 'load_module_metadata' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('one', 'two', 'three').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+
+ describe 'when calling with valid arguments' do
+ before :each do
+ allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}, :encoding => 'utf-8').and_return('{"name": "puppetlabs-stdlib"}')
+ allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}).and_return('{"name": "puppetlabs-stdlib"}')
+ end
+
+ context 'when calling with valid utf8 and double byte character arguments' do
+ before :each do
+ allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}, :encoding => 'utf-8').and_return('{"ĭďèʼnţĩƒіểя": "ċơņťęאּť ỡƒ ţħíš -
+この文字"}')
+ allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}).and_return('{"ĭďèʼnţĩƒіểя": "ċơņťęאּť ỡƒ ţħíš -
+この文字"}')
+ end
+
+ let(:prefix) { 'C:' if Puppet::Util::Platform.windows? }
+
+ it 'jsons parse the file' do
+ allow(scope).to receive(:function_get_module_path).with(['science']).and_return("#{prefix}/path/to/module/")
+ allow(File).to receive(:exists?).with("#{prefix}/path/to/module/metadata.json").and_return(true)
+ allow(File).to receive(:read).with("#{prefix}/path/to/module/metadata.json").and_return('{"name": "spencer-science"}')
+
+ result = subject.call(['science'])
+ expect(result['name']).to eq('spencer-science')
+ end
+
+ it 'fails by default if there is no metadata.json' do
+ allow(scope).to receive(:function_get_module_path).with(['science']).and_return("#{prefix}/path/to/module/")
+ allow(File).to receive(:exists?).with("#{prefix}/path/to/module/metadata.json").and_return(false)
+ expect { subject.call(['science']) }.to raise_error(Puppet::ParseError)
+ end
+
+ it 'returns nil if user allows empty metadata.json' do
+ allow(scope).to receive(:function_get_module_path).with(['science']).and_return("#{prefix}/path/to/module/")
+ allow(File).to receive(:exists?).with("#{prefix}/path/to/module/metadata.json").and_return(false)
+ result = subject.call(['science', true])
+ expect(result).to eq({})
+ end
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/loadjson_spec.rb b/code/environments/production/modules/stdlib/spec/functions/loadjson_spec.rb
new file mode 100644
index 0000000..fc4d97d
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/loadjson_spec.rb
@@ -0,0 +1,69 @@
+require 'spec_helper'
+
+describe 'loadjson' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{wrong number of arguments}i) }
+
+ describe 'when calling with valid arguments' do
+ before :each do
+ allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}, :encoding => 'utf-8').and_return('{"name": "puppetlabs-stdlib"}')
+ allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}).and_return('{"name": "puppetlabs-stdlib"}')
+ end
+
+ context 'when a non-existing file is specified' do
+ let(:filename) do
+ if Puppet::Util::Platform.windows?
+ 'C:/tmp/doesnotexist'
+ else
+ '/tmp/doesnotexist'
+ end
+ end
+
+ before(:each) do
+ allow(File).to receive(:exists?).with(filename).and_return(false).once
+ allow(PSON).to receive(:load).never
+ end
+ it { is_expected.to run.with_params(filename, 'default' => 'value').and_return('default' => 'value') }
+ it { is_expected.to run.with_params(filename, 'đẽƒằưļŧ' => '٧ẵłựέ').and_return('đẽƒằưļŧ' => '٧ẵłựέ') }
+ it { is_expected.to run.with_params(filename, 'デフォルト' => '値').and_return('デフォルト' => '値') }
+ end
+
+ context 'when an existing file is specified' do
+ let(:filename) do
+ if Puppet::Util::Platform.windows?
+ 'C:/tmp/doesexist'
+ else
+ '/tmp/doesexist'
+ end
+ end
+ let(:data) { { 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値' } }
+ let(:json) { '{"key":"value", {"ķęŷ":"νậŀųề" }, {"キー":"値" }' }
+
+ before(:each) do
+ allow(File).to receive(:exists?).with(filename).and_return(true).once
+ allow(File).to receive(:read).with(filename).and_return(json).once
+ allow(File).to receive(:read).with(filename).and_return(json).once
+ allow(PSON).to receive(:load).with(json).and_return(data).once
+ end
+ it { is_expected.to run.with_params(filename).and_return(data) }
+ end
+
+ context 'when the file could not be parsed' do
+ let(:filename) do
+ if Puppet::Util::Platform.windows?
+ 'C:/tmp/doesexist'
+ else
+ '/tmp/doesexist'
+ end
+ end
+ let(:json) { '{"key":"value"}' }
+
+ before(:each) do
+ allow(File).to receive(:exists?).with(filename).and_return(true).once
+ allow(File).to receive(:read).with(filename).and_return(json).once
+ allow(PSON).to receive(:load).with(json).once.and_raise StandardError, 'Something terrible have happened!'
+ end
+ it { is_expected.to run.with_params(filename, 'default' => 'value').and_return('default' => 'value') }
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/loadyaml_spec.rb b/code/environments/production/modules/stdlib/spec/functions/loadyaml_spec.rb
new file mode 100644
index 0000000..f104ca3
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/loadyaml_spec.rb
@@ -0,0 +1,39 @@
+require 'spec_helper'
+
+describe 'loadyaml' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{wrong number of arguments}i) }
+
+ context 'when a non-existing file is specified' do
+ let(:filename) { '/tmp/doesnotexist' }
+
+ before(:each) do
+ File.expects(:exists?).with(filename).returns(false).once
+ YAML.expects(:load_file).never
+ end
+ it { is_expected.to run.with_params(filename, 'default' => 'value').and_return('default' => 'value') }
+ it { is_expected.to run.with_params(filename, 'đẽƒằưļŧ' => '٧ẵłựέ').and_return('đẽƒằưļŧ' => '٧ẵłựέ') }
+ it { is_expected.to run.with_params(filename, 'デフォルト' => '値').and_return('デフォルト' => '値') }
+ end
+
+ context 'when an existing file is specified' do
+ let(:filename) { '/tmp/doesexist' }
+ let(:data) { { 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値' } }
+
+ before(:each) do
+ File.expects(:exists?).with(filename).returns(true).once
+ YAML.expects(:load_file).with(filename).returns(data).once
+ end
+ it { is_expected.to run.with_params(filename).and_return(data) }
+ end
+
+ context 'when the file could not be parsed' do
+ let(:filename) { '/tmp/doesexist' }
+
+ before(:each) do
+ File.expects(:exists?).with(filename).returns(true).once
+ YAML.stubs(:load_file).with(filename).once.raises StandardError, 'Something terrible have happened!'
+ end
+ it { is_expected.to run.with_params(filename, 'default' => 'value').and_return('default' => 'value') }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/lstrip_spec.rb b/code/environments/production/modules/stdlib/spec/functions/lstrip_spec.rb
new file mode 100644
index 0000000..7c215d9
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/lstrip_spec.rb
@@ -0,0 +1,35 @@
+require 'spec_helper'
+
+describe 'lstrip' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it {
+ pending('Current implementation ignores parameters after the first.')
+ is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
+ }
+ it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work with}) }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work with}) }
+ it { is_expected.to run.with_params('').and_return('') }
+ it { is_expected.to run.with_params(' ').and_return('') }
+ it { is_expected.to run.with_params(' ').and_return('') }
+ it { is_expected.to run.with_params("\t").and_return('') }
+ it { is_expected.to run.with_params("\t ").and_return('') }
+ it { is_expected.to run.with_params('one').and_return('one') }
+ it { is_expected.to run.with_params(' one').and_return('one') }
+ it { is_expected.to run.with_params(' one').and_return('one') }
+ it { is_expected.to run.with_params("\tone").and_return('one') }
+ it { is_expected.to run.with_params("\t one").and_return('one') }
+ it { is_expected.to run.with_params('one ').and_return('one ') }
+ it { is_expected.to run.with_params(' one ').and_return('one ') }
+ it { is_expected.to run.with_params(' one ').and_return('one ') }
+ it { is_expected.to run.with_params(' ǿňè ').and_return('ǿňè ') }
+ it { is_expected.to run.with_params("\tone ").and_return('one ') }
+ it { is_expected.to run.with_params("\t one ").and_return('one ') }
+ it { is_expected.to run.with_params("one \t").and_return("one \t") }
+ it { is_expected.to run.with_params(" one \t").and_return("one \t") }
+ it { is_expected.to run.with_params(" one \t").and_return("one \t") }
+ it { is_expected.to run.with_params("\tone \t").and_return("one \t") }
+ it { is_expected.to run.with_params("\t one \t").and_return("one \t") }
+ it { is_expected.to run.with_params(' o n e ').and_return('o n e ') }
+ it { is_expected.to run.with_params(AlsoString.new(' one ')).and_return('one ') }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/max_spec.rb b/code/environments/production/modules/stdlib/spec/functions/max_spec.rb
new file mode 100644
index 0000000..bacd2fc
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/max_spec.rb
@@ -0,0 +1,21 @@
+require 'spec_helper'
+
+describe 'max' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params(1).and_return(1) }
+ it { is_expected.to run.with_params(1, 2).and_return(2) }
+ it { is_expected.to run.with_params(1, 2, 3).and_return(3) }
+ it { is_expected.to run.with_params(3, 2, 1).and_return(3) }
+ it { is_expected.to run.with_params('one').and_return('one') }
+ it { is_expected.to run.with_params('one', 'two').and_return('two') }
+ it { is_expected.to run.with_params('one', 'two', 'three').and_return('two') }
+ it { is_expected.to run.with_params('three', 'two', 'one').and_return('two') }
+
+ describe 'implementation artifacts' do
+ it { is_expected.to run.with_params(1, 'one').and_return('one') }
+ it { is_expected.to run.with_params('1', 'one').and_return('one') }
+ it { is_expected.to run.with_params('1.3e1', '1.4e0').and_return('1.4e0') }
+ it { is_expected.to run.with_params(1.3e1, 1.4e0).and_return(1.3e1) }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/member_spec.rb b/code/environments/production/modules/stdlib/spec/functions/member_spec.rb
new file mode 100644
index 0000000..410c465
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/member_spec.rb
@@ -0,0 +1,23 @@
+require 'spec_helper'
+
+describe 'member' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it {
+ pending('Current implementation ignores parameters after the first.')
+ is_expected.to run.with_params([], [], []).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
+ }
+ it { is_expected.to run.with_params([], '').and_return(false) }
+ it { is_expected.to run.with_params([], ['']).and_return(false) }
+ it { is_expected.to run.with_params([''], '').and_return(true) }
+ it { is_expected.to run.with_params([''], ['']).and_return(true) }
+ it { is_expected.to run.with_params([], 'one').and_return(false) }
+ it { is_expected.to run.with_params([], ['one']).and_return(false) }
+ it { is_expected.to run.with_params(['one'], 'one').and_return(true) }
+ it { is_expected.to run.with_params(['one'], ['one']).and_return(true) }
+ it { is_expected.to run.with_params(%w[one two three four], %w[four two]).and_return(true) }
+ it { is_expected.to run.with_params(%w[ọאּẹ ŧẅồ ţҺŗęē ƒơџŕ], %w[ƒơџŕ ŧẅồ]).and_return(true) }
+ it { is_expected.to run.with_params(%w[one two three four], %w[four five]).and_return(false) }
+ it { is_expected.to run.with_params(%w[ọאּẹ ŧẅồ ţҺŗęē ƒơџŕ], ['ƒơџŕ', 'ƒί√ə']).and_return(false) }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/merge_spec.rb b/code/environments/production/modules/stdlib/spec/functions/merge_spec.rb
new file mode 100644
index 0000000..25e2658
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/merge_spec.rb
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+describe 'merge' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params({}, 'two').and_raise_error(Puppet::ParseError, %r{unexpected argument type String}) }
+ it { is_expected.to run.with_params({}, 1).and_raise_error(Puppet::ParseError, %r{unexpected argument type (Fixnum|Integer)}) }
+ it {
+ pending 'should not special case this'
+ is_expected.to run.with_params({}).and_return({})
+ }
+ it { is_expected.to run.with_params({}, {}).and_return({}) }
+ it { is_expected.to run.with_params({}, {}, {}).and_return({}) }
+ describe 'should accept empty strings as puppet undef' do
+ it { is_expected.to run.with_params({}, '').and_return({}) }
+ end
+ it { is_expected.to run.with_params({ 'key' => 'value' }, {}).and_return('key' => 'value') }
+ it { is_expected.to run.with_params({}, 'key' => 'value').and_return('key' => 'value') }
+ it { is_expected.to run.with_params({ 'key' => 'value1' }, 'key' => 'value2').and_return('key' => 'value2') }
+ it {
+ is_expected.to run \
+ .with_params({ 'key1' => 'value1' }, { 'key2' => 'value2' }, 'key3' => 'value3') \
+ .and_return('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3')
+ }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/min_spec.rb b/code/environments/production/modules/stdlib/spec/functions/min_spec.rb
new file mode 100644
index 0000000..2c325a4
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/min_spec.rb
@@ -0,0 +1,22 @@
+require 'spec_helper'
+
+describe 'min' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params(1).and_return(1) }
+ it { is_expected.to run.with_params(1, 2).and_return(1) }
+ it { is_expected.to run.with_params(1, 2, 3).and_return(1) }
+ it { is_expected.to run.with_params(3, 2, 1).and_return(1) }
+ it { is_expected.to run.with_params(12, 8).and_return(8) }
+ it { is_expected.to run.with_params('one').and_return('one') }
+ it { is_expected.to run.with_params('one', 'two').and_return('one') }
+ it { is_expected.to run.with_params('one', 'two', 'three').and_return('one') }
+ it { is_expected.to run.with_params('three', 'two', 'one').and_return('one') }
+
+ describe 'implementation artifacts' do
+ it { is_expected.to run.with_params(1, 'one').and_return(1) }
+ it { is_expected.to run.with_params('1', 'one').and_return('1') }
+ it { is_expected.to run.with_params('1.3e1', '1.4e0').and_return('1.3e1') }
+ it { is_expected.to run.with_params(1.3e1, 1.4e0).and_return(1.4e0) }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/num2bool_spec.rb b/code/environments/production/modules/stdlib/spec/functions/num2bool_spec.rb
new file mode 100644
index 0000000..60533e3
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/num2bool_spec.rb
@@ -0,0 +1,22 @@
+require 'spec_helper'
+
+describe 'num2bool' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params(1, 2).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('abc').and_raise_error(Puppet::ParseError, %r{does not look like a number}) }
+ it { is_expected.to run.with_params(1).and_return(true) }
+ it { is_expected.to run.with_params('1').and_return(true) }
+ it { is_expected.to run.with_params(1.5).and_return(true) }
+ it { is_expected.to run.with_params('1.5').and_return(true) }
+ it { is_expected.to run.with_params(-1).and_return(false) }
+ it { is_expected.to run.with_params('-1').and_return(false) }
+ it { is_expected.to run.with_params(-1.5).and_return(false) }
+ it { is_expected.to run.with_params('-1.5').and_return(false) }
+ it { is_expected.to run.with_params(0).and_return(false) }
+ it { is_expected.to run.with_params('0').and_return(false) }
+ it { is_expected.to run.with_params([]).and_return(false) }
+ it { is_expected.to run.with_params('[]').and_raise_error(Puppet::ParseError, %r{does not look like a number}) }
+ it { is_expected.to run.with_params({}).and_return(false) }
+ it { is_expected.to run.with_params('{}').and_raise_error(Puppet::ParseError, %r{does not look like a number}) }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/parsejson_spec.rb b/code/environments/production/modules/stdlib/spec/functions/parsejson_spec.rb
new file mode 100644
index 0000000..45abe3b
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/parsejson_spec.rb
@@ -0,0 +1,66 @@
+require 'spec_helper'
+
+describe 'parsejson' do
+ it 'exists' do
+ is_expected.not_to eq(nil)
+ end
+
+ it 'raises an error if called without any arguments' do
+ is_expected.to run.with_params
+ .and_raise_error(%r{wrong number of arguments}i)
+ end
+
+ context 'with correct JSON data' do
+ it 'is able to parse JSON data with a Hash' do
+ is_expected.to run.with_params('{"a":"1","b":"2"}')
+ .and_return('a' => '1', 'b' => '2')
+ end
+
+ it 'is able to parse JSON data with an Array' do
+ is_expected.to run.with_params('["a","b","c"]')
+ .and_return(%w[a b c])
+ end
+
+ it 'is able to parse empty JSON values' do
+ actual_array = %w[[] {}]
+ expected = [[], {}]
+ actual_array.each_with_index do |actual, index|
+ is_expected.to run.with_params(actual).and_return(expected[index])
+ end
+ end
+
+ it 'is able to parse JSON data with a mixed structure' do
+ is_expected.to run.with_params('{"a":"1","b":2,"c":{"d":[true,false]}}')
+ .and_return('a' => '1', 'b' => 2, 'c' => { 'd' => [true, false] })
+ end
+
+ it 'is able to parse JSON data with a UTF8 and double byte characters' do
+ is_expected.to run.with_params('{"×":"これ","ý":"記号","です":{"©":["Á","ß"]}}')
+ .and_return('×' => 'これ', 'ý' => '記号', 'です' => { '©' => %w[Á ß] })
+ end
+
+ it 'does not return the default value if the data was parsed correctly' do
+ is_expected.to run.with_params('{"a":"1"}', 'default_value')
+ .and_return('a' => '1')
+ end
+ end
+
+ context 'with incorrect JSON data' do
+ it 'raises an error with invalid JSON and no default' do
+ is_expected.to run.with_params('')
+ .and_raise_error(PSON::ParserError)
+ end
+
+ it 'supports a structure for a default value' do
+ is_expected.to run.with_params('', 'a' => '1')
+ .and_return('a' => '1')
+ end
+
+ ['', 1, 1.2, nil, true, false, [], {}, :yaml].each do |value|
+ it "should return the default value for an incorrect #{value.inspect} (#{value.class}) parameter" do
+ is_expected.to run.with_params(value, 'default_value')
+ .and_return('default_value')
+ end
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/parseyaml_spec.rb b/code/environments/production/modules/stdlib/spec/functions/parseyaml_spec.rb
new file mode 100644
index 0000000..bcf0afd
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/parseyaml_spec.rb
@@ -0,0 +1,83 @@
+require 'spec_helper'
+
+describe 'parseyaml' do
+ it 'exists' do
+ is_expected.not_to eq(nil)
+ end
+
+ it 'raises an error if called without any arguments' do
+ is_expected.to run.with_params
+ .and_raise_error(%r{wrong number of arguments}i)
+ end
+
+ context 'with correct YAML data' do
+ it 'is able to parse a YAML data with a String' do
+ actual_array = ['--- just a string', 'just a string']
+ actual_array.each do |actual|
+ is_expected.to run.with_params(actual).and_return('just a string')
+ end
+ end
+
+ it 'is able to parse YAML data with a Hash' do
+ is_expected.to run.with_params("---\na: '1'\nb: '2'\n")
+ .and_return('a' => '1', 'b' => '2')
+ end
+
+ it 'is able to parse YAML data with an Array' do
+ is_expected.to run.with_params("---\n- a\n- b\n- c\n")
+ .and_return(%w[a b c])
+ end
+
+ it 'is able to parse YAML data with a mixed structure' do
+ is_expected.to run.with_params("---\na: '1'\nb: 2\nc:\n d:\n - :a\n - true\n - false\n")
+ .and_return('a' => '1', 'b' => 2, 'c' => { 'd' => [:a, true, false] })
+ end
+
+ it 'is able to parse YAML data with a UTF8 and double byte characters' do
+ is_expected.to run.with_params("---\na: ×\nこれ: 記号\nです:\n ©:\n - Á\n - ß\n")
+ .and_return('a' => '×', 'これ' => '記号', 'です' => { '©' => %w[Á ß] })
+ end
+
+ it 'does not return the default value if the data was parsed correctly' do
+ is_expected.to run.with_params("---\na: '1'\n", 'default_value')
+ .and_return('a' => '1')
+ end
+ end
+
+ context 'on a modern ruby', :unless => RUBY_VERSION == '1.8.7' do
+ it 'raises an error with invalid YAML and no default' do
+ is_expected.to run.with_params('["one"')
+ .and_raise_error(Psych::SyntaxError)
+ end
+ end
+
+ context 'when running on ruby 1.8.7, which does not have Psych', :if => RUBY_VERSION == '1.8.7' do
+ it 'raises an error with invalid YAML and no default' do
+ is_expected.to run.with_params('["one"')
+ .and_raise_error(ArgumentError)
+ end
+ end
+
+ context 'with incorrect YAML data' do
+ it 'supports a structure for a default value' do
+ is_expected.to run.with_params('', 'a' => '1')
+ .and_return('a' => '1')
+ end
+
+ [1, 1.2, nil, true, false, [], {}, :yaml].each do |value|
+ it "should return the default value for an incorrect #{value.inspect} (#{value.class}) parameter" do
+ is_expected.to run.with_params(value, 'default_value')
+ .and_return('default_value')
+ end
+ end
+
+ context 'when running on modern rubies', :unless => RUBY_VERSION == '1.8.7' do
+ ['---', '...', '*8', ''].each do |value|
+ it "should return the default value for an incorrect #{value.inspect} string parameter" do
+ is_expected.to run.with_params(value, 'default_value')
+ .and_return('default_value')
+ end
+ end
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/pick_default_spec.rb b/code/environments/production/modules/stdlib/spec/functions/pick_default_spec.rb
new file mode 100644
index 0000000..2ddaa4b
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/pick_default_spec.rb
@@ -0,0 +1,26 @@
+require 'spec_helper'
+
+describe 'pick_default' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(RuntimeError, %r{Must receive at least one argument}) }
+
+ it { is_expected.to run.with_params('one', 'two').and_return('one') }
+ it { is_expected.to run.with_params('ớņệ', 'ťωơ').and_return('ớņệ') }
+ it { is_expected.to run.with_params('', 'two').and_return('two') }
+ it { is_expected.to run.with_params(:undef, 'two').and_return('two') }
+ it { is_expected.to run.with_params(:undefined, 'two').and_return('two') }
+ it { is_expected.to run.with_params(nil, 'two').and_return('two') }
+
+ ['', :undef, :undefined, nil, {}, [], 1, 'default'].each do |value|
+ describe "when providing #{value.inspect} as default" do
+ it { is_expected.to run.with_params('one', value).and_return('one') }
+ it { is_expected.to run.with_params('ớņệ', value).and_return('ớņệ') }
+ it { is_expected.to run.with_params([], value).and_return([]) }
+ it { is_expected.to run.with_params({}, value).and_return({}) }
+ it { is_expected.to run.with_params(value, value).and_return(value) }
+ it { is_expected.to run.with_params(:undef, value).and_return(value) }
+ it { is_expected.to run.with_params(:undefined, value).and_return(value) }
+ it { is_expected.to run.with_params(nil, value).and_return(value) }
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/pick_spec.rb b/code/environments/production/modules/stdlib/spec/functions/pick_spec.rb
new file mode 100644
index 0000000..d8c6fbf
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/pick_spec.rb
@@ -0,0 +1,17 @@
+require 'spec_helper'
+
+describe 'pick' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{must receive at least one non empty value}) }
+ it { is_expected.to run.with_params('', nil, :undef, :undefined).and_raise_error(Puppet::ParseError, %r{must receive at least one non empty value}) }
+ it { is_expected.to run.with_params('one', 'two').and_return('one') }
+ it { is_expected.to run.with_params('', 'two').and_return('two') }
+ it { is_expected.to run.with_params(:undef, 'two').and_return('two') }
+ it { is_expected.to run.with_params(:undefined, 'two').and_return('two') }
+ it { is_expected.to run.with_params(nil, 'two').and_return('two') }
+
+ context 'with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params(nil, 'このテキスト').and_return('このテキスト') }
+ it { is_expected.to run.with_params('', 'ŝẳмрłề џţƒ8 ţẽם', 'このテキスト').and_return('ŝẳмрłề џţƒ8 ţẽם') }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/prefix_spec.rb b/code/environments/production/modules/stdlib/spec/functions/prefix_spec.rb
new file mode 100644
index 0000000..b4c61ba
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/prefix_spec.rb
@@ -0,0 +1,29 @@
+require 'spec_helper'
+
+describe 'prefix' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it {
+ pending('Current implementation ignores parameters after the second.')
+ is_expected.to run.with_params([], 'a', '').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
+ }
+ it { is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, %r{expected first argument to be an Array or a Hash}) }
+ it { is_expected.to run.with_params([], 2).and_raise_error(Puppet::ParseError, %r{expected second argument to be a String}) }
+ it { is_expected.to run.with_params([]).and_return([]) }
+ it { is_expected.to run.with_params(['one', 2]).and_return(%w[one 2]) }
+ it { is_expected.to run.with_params(['ớņệ', 2]).and_return(%w[ớņệ 2]) }
+ it { is_expected.to run.with_params([], '').and_return([]) }
+ it { is_expected.to run.with_params([''], '').and_return(['']) }
+ it { is_expected.to run.with_params(['one'], 'pre').and_return(['preone']) }
+ it { is_expected.to run.with_params(%w[one two three], 'pre').and_return(%w[preone pretwo prethree]) }
+ it { is_expected.to run.with_params({}).and_return({}) }
+ it { is_expected.to run.with_params('key1' => 'value1', 2 => 3).and_return('key1' => 'value1', '2' => 3) }
+ it { is_expected.to run.with_params({}, '').and_return({}) }
+ it { is_expected.to run.with_params({ 'key' => 'value' }, '').and_return('key' => 'value') }
+ it { is_expected.to run.with_params({ 'key' => 'value' }, 'pre').and_return('prekey' => 'value') }
+ it {
+ is_expected.to run \
+ .with_params({ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }, 'pre') \
+ .and_return('prekey1' => 'value1', 'prekey2' => 'value2', 'prekey3' => 'value3')
+ }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/private_spec.rb b/code/environments/production/modules/stdlib/spec/functions/private_spec.rb
new file mode 100644
index 0000000..1efc045
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/private_spec.rb
@@ -0,0 +1,52 @@
+require 'spec_helper'
+
+describe 'private' do
+ it 'issues a warning' do
+ scope.expects(:warning).with("private() DEPRECATED: This function will cease to function on Puppet 4; please use assert_private() before upgrading to puppet 4 for backwards-compatibility, or migrate to the new parser's typing system.") # rubocop:disable Metrics/LineLength : unable to cut line to required length
+ begin
+ subject.call []
+ rescue # rubocop:disable Lint/HandleExceptions
+ # ignore this
+ end
+ end
+
+ context 'when called from inside module' do
+ it 'does not fail' do
+ scope.expects(:lookupvar).with('module_name').returns('foo')
+ scope.expects(:lookupvar).with('caller_module_name').returns('foo')
+ expect {
+ subject.call []
+ }.not_to raise_error
+ end
+ end
+
+ context 'with an explicit failure message' do
+ it 'prints the failure message on error' do
+ scope.expects(:lookupvar).with('module_name').returns('foo')
+ scope.expects(:lookupvar).with('caller_module_name').returns('bar')
+ expect {
+ subject.call ['failure message!']
+ }.to raise_error Puppet::ParseError, %r{failure message!}
+ end
+ end
+
+ context 'when called from private class' do
+ it 'fails with a class error message' do
+ scope.expects(:lookupvar).with('module_name').returns('foo')
+ scope.expects(:lookupvar).with('caller_module_name').returns('bar')
+ scope.source.expects(:name).returns('foo::baz')
+ scope.source.expects(:type).returns('hostclass')
+ expect { subject.call [] }.to raise_error Puppet::ParseError, %r{Class foo::baz is private}
+ end
+ end
+
+ context 'when called from private definition' do
+ it 'fails with a class error message' do
+ scope.expects(:lookupvar).with('module_name').returns('foo')
+ scope.expects(:lookupvar).with('caller_module_name').returns('bar')
+ scope.source.expects(:name).returns('foo::baz')
+ scope.source.expects(:type).returns('definition')
+ expect { subject.call [] }.to raise_error Puppet::ParseError, %r{Definition foo::baz is private}
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/pw_hash_spec.rb b/code/environments/production/modules/stdlib/spec/functions/pw_hash_spec.rb
new file mode 100644
index 0000000..31010d6
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/pw_hash_spec.rb
@@ -0,0 +1,79 @@
+require 'spec_helper'
+
+describe 'pw_hash' do
+ it { is_expected.not_to eq(nil) }
+
+ context 'when there are less than 3 arguments' do
+ it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('password').and_raise_error(ArgumentError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('password', 'sha-256').and_raise_error(ArgumentError, %r{wrong number of arguments}i) }
+ end
+
+ context 'when there are more than 3 arguments' do
+ it { is_expected.to run.with_params('password', 'sha-256', 'salt', 'extra').and_raise_error(ArgumentError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('password', 'sha-256', 'salt', 'extra', 'extra').and_raise_error(ArgumentError, %r{wrong number of arguments}i) }
+ end
+
+ context 'when the first argument is not a string' do
+ it { is_expected.to run.with_params([], 'sha-256', 'salt').and_raise_error(ArgumentError, %r{first argument must be a string}) }
+ it { is_expected.to run.with_params({}, 'sha-256', 'salt').and_raise_error(ArgumentError, %r{first argument must be a string}) }
+ it { is_expected.to run.with_params(1, 'sha-256', 'salt').and_raise_error(ArgumentError, %r{first argument must be a string}) }
+ it { is_expected.to run.with_params(true, 'sha-256', 'salt').and_raise_error(ArgumentError, %r{first argument must be a string}) }
+ end
+
+ context 'when the first argument is undefined' do
+ it { is_expected.to run.with_params('', 'sha-256', 'salt').and_return(nil) }
+ it { is_expected.to run.with_params(nil, 'sha-256', 'salt').and_return(nil) }
+ end
+
+ context 'when the second argument is not a string' do
+ it { is_expected.to run.with_params('password', [], 'salt').and_raise_error(ArgumentError, %r{second argument must be a string}) }
+ it { is_expected.to run.with_params('password', {}, 'salt').and_raise_error(ArgumentError, %r{second argument must be a string}) }
+ it { is_expected.to run.with_params('password', 1, 'salt').and_raise_error(ArgumentError, %r{second argument must be a string}) }
+ it { is_expected.to run.with_params('password', true, 'salt').and_raise_error(ArgumentError, %r{second argument must be a string}) }
+ end
+
+ context 'when the second argument is not one of the supported hashing algorithms' do
+ it { is_expected.to run.with_params('password', 'no such algo', 'salt').and_raise_error(ArgumentError, %r{is not a valid hash type}) }
+ end
+
+ context 'when the third argument is not a string' do
+ it { is_expected.to run.with_params('password', 'sha-256', []).and_raise_error(ArgumentError, %r{third argument must be a string}) }
+ it { is_expected.to run.with_params('password', 'sha-256', {}).and_raise_error(ArgumentError, %r{third argument must be a string}) }
+ it { is_expected.to run.with_params('password', 'sha-256', 1).and_raise_error(ArgumentError, %r{third argument must be a string}) }
+ it { is_expected.to run.with_params('password', 'sha-256', true).and_raise_error(ArgumentError, %r{third argument must be a string}) }
+ end
+
+ context 'when the third argument is empty' do
+ it { is_expected.to run.with_params('password', 'sha-512', '').and_raise_error(ArgumentError, %r{third argument must not be empty}) }
+ end
+
+ context 'when the third argument contains invalid characters' do
+ it { is_expected.to run.with_params('password', 'sha-512', 'one%').and_raise_error(ArgumentError, %r{characters in salt must be in the set}) }
+ end
+
+ context 'when running on a platform with a weak String#crypt implementation' do
+ before(:each) { allow_any_instance_of(String).to receive(:crypt).with('$1$1').and_return('a bad hash') } # rubocop:disable RSpec/AnyInstance : Unable to find a viable replacement
+
+ it { is_expected.to run.with_params('password', 'sha-512', 'salt').and_raise_error(Puppet::ParseError, %r{system does not support enhanced salts}) }
+ end
+
+ if RUBY_PLATFORM == 'java' || 'test'.crypt('$1$1') == '$1$1$Bp8CU9Oujr9SSEw53WV6G.'
+ describe 'on systems with enhanced salts support' do
+ it { is_expected.to run.with_params('password', 'md5', 'salt').and_return('$1$salt$qJH7.N4xYta3aEG/dfqo/0') }
+ it { is_expected.to run.with_params('password', 'sha-256', 'salt').and_return('$5$salt$Gcm6FsVtF/Qa77ZKD.iwsJlCVPY0XSMgLJL0Hnww/c1') }
+ it { is_expected.to run.with_params('password', 'sha-512', 'salt').and_return('$6$salt$IxDD3jeSOb5eB1CX5LBsqZFVkJdido3OUILO5Ifz5iwMuTS4XMS130MTSuDDl3aCI6WouIL9AjRbLCelDCy.g.') }
+ end
+
+ if Puppet::Util::Package.versioncmp(Puppet.version, '4.7.0') >= 0
+ describe 'when arguments are sensitive' do
+ it { is_expected.to run.with_params(Puppet::Pops::Types::PSensitiveType::Sensitive.new('password'), 'md5', 'salt').and_return('$1$salt$qJH7.N4xYta3aEG/dfqo/0') }
+ it {
+ is_expected.to run.with_params(Puppet::Pops::Types::PSensitiveType::Sensitive.new('password'), 'md5', Puppet::Pops::Types::PSensitiveType::Sensitive.new('salt'))
+ .and_return('$1$salt$qJH7.N4xYta3aEG/dfqo/0')
+ }
+ it { is_expected.to run.with_params('password', 'md5', Puppet::Pops::Types::PSensitiveType::Sensitive.new('salt')).and_return('$1$salt$qJH7.N4xYta3aEG/dfqo/0') }
+ end
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/range_spec.rb b/code/environments/production/modules/stdlib/spec/functions/range_spec.rb
new file mode 100644
index 0000000..1ae4adb
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/range_spec.rb
@@ -0,0 +1,157 @@
+require 'spec_helper'
+
+describe 'range' do
+ it { is_expected.not_to eq(nil) }
+
+ describe 'signature validation in puppet3', :unless => RSpec.configuration.puppet_future do
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it {
+ pending('Current implementation ignores parameters after the third.')
+ is_expected.to run.with_params(1, 2, 3, 4).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
+ }
+ it { is_expected.to run.with_params('1..2..3').and_raise_error(Puppet::ParseError, %r{Unable to compute range}i) }
+ it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, %r{Unknown range format}i) }
+ end
+
+ describe 'signature validation in puppet4', :if => RSpec.configuration.puppet_future do
+ it {
+ pending 'the puppet 4 implementation'
+ is_expected.to run.with_params.and_raise_error(ArgumentError)
+ }
+ it {
+ pending 'the puppet 4 implementation'
+ is_expected.to run.with_params('').and_raise_error(ArgumentError)
+ }
+ it {
+ pending 'the puppet 4 implementation'
+ is_expected.to run.with_params({}).and_raise_error(ArgumentError)
+ }
+ it {
+ pending 'the puppet 4 implementation'
+ is_expected.to run.with_params([]).and_raise_error(ArgumentError)
+ }
+ it {
+ pending 'the puppet 4 implementation'
+ is_expected.to run.with_params(true).and_raise_error(ArgumentError)
+ }
+ it {
+ is_expected.to run.with_params(1, 2, 'foo').and_raise_error(ArgumentError)
+ }
+ it {
+ pending 'the puppet 4 implementation'
+ is_expected.to run.with_params(1, 2, []).and_raise_error(ArgumentError)
+ }
+ it {
+ pending 'the puppet 4 implementation'
+ is_expected.to run.with_params(1, 2, {}).and_raise_error(ArgumentError)
+ }
+ it {
+ pending 'the puppet 4 implementation'
+ is_expected.to run.with_params(1, 2, true).and_raise_error(ArgumentError)
+ }
+ it {
+ pending 'the puppet 4 implementation'
+ is_expected.to run.with_params(1, 2, 3, 4).and_raise_error(ArgumentError)
+ }
+ it {
+ pending 'the puppet 4 implementation'
+ is_expected.to run.with_params('1..2..3').and_raise_error(ArgumentError)
+ }
+ end
+
+ context 'with characters as bounds' do
+ it { is_expected.to run.with_params('d', 'a').and_return([]) }
+ it { is_expected.to run.with_params('a', 'a').and_return(['a']) }
+ it { is_expected.to run.with_params('a', 'b').and_return(%w[a b]) }
+ it { is_expected.to run.with_params('a', 'd').and_return(%w[a b c d]) }
+ it { is_expected.to run.with_params('a', 'd', 1).and_return(%w[a b c d]) }
+ it { is_expected.to run.with_params('a', 'd', '1').and_return(%w[a b c d]) }
+ it { is_expected.to run.with_params('a', 'd', 2).and_return(%w[a c]) }
+ it { is_expected.to run.with_params('a', 'd', -2).and_return(%w[a c]) }
+ it { is_expected.to run.with_params('a', 'd', 3).and_return(%w[a d]) }
+ it { is_expected.to run.with_params('a', 'd', 4).and_return(['a']) }
+ end
+
+ context 'with strings as bounds' do
+ it { is_expected.to run.with_params('onea', 'oned').and_return(%w[onea oneb onec oned]) }
+ it { is_expected.to run.with_params('two', 'one').and_return([]) }
+ it { is_expected.to run.with_params('true', 'false').and_return([]) }
+ it { is_expected.to run.with_params('false', 'true').and_return(['false']) }
+ end
+
+ context 'with integers as bounds' do
+ it { is_expected.to run.with_params(4, 1).and_return([]) }
+ it { is_expected.to run.with_params(1, 1).and_return([1]) }
+ it { is_expected.to run.with_params(1, 2).and_return([1, 2]) }
+ it { is_expected.to run.with_params(1, 4).and_return([1, 2, 3, 4]) }
+ it { is_expected.to run.with_params(1, 4, 1).and_return([1, 2, 3, 4]) }
+ it { is_expected.to run.with_params(1, 4, '1').and_return([1, 2, 3, 4]) }
+ it { is_expected.to run.with_params(1, 4, 2).and_return([1, 3]) }
+ it { is_expected.to run.with_params(1, 4, -2).and_return([1, 3]) }
+ it { is_expected.to run.with_params(1, 4, 3).and_return([1, 4]) }
+ it { is_expected.to run.with_params(1, 4, 4).and_return([1]) }
+ end
+
+ context 'with integers as strings as bounds' do
+ it { is_expected.to run.with_params('4', '1').and_return([]) }
+ it { is_expected.to run.with_params('1', '1').and_return([1]) }
+ it { is_expected.to run.with_params('1', '2').and_return([1, 2]) }
+ it { is_expected.to run.with_params('1', '4').and_return([1, 2, 3, 4]) }
+ it { is_expected.to run.with_params('1', '4', 1).and_return([1, 2, 3, 4]) }
+ it { is_expected.to run.with_params('1', '4', '1').and_return([1, 2, 3, 4]) }
+ it { is_expected.to run.with_params('1', '4', 2).and_return([1, 3]) }
+ it { is_expected.to run.with_params('1', '4', -2).and_return([1, 3]) }
+ it { is_expected.to run.with_params('1', '4', 3).and_return([1, 4]) }
+ it { is_expected.to run.with_params('1', '4', 4).and_return([1]) }
+ end
+
+ context 'with prefixed numbers as strings as bounds' do
+ it { is_expected.to run.with_params('host01', 'host04').and_return(%w[host01 host02 host03 host04]) }
+ it { is_expected.to run.with_params('01', '04').and_return([1, 2, 3, 4]) }
+ end
+
+ context 'with prefixed numbers as utf8 strings as bounds' do
+ it { is_expected.to run.with_params('ħөŝŧ01', 'ħөŝŧ04').and_return(%w[ħөŝŧ01 ħөŝŧ02 ħөŝŧ03 ħөŝŧ04]) }
+ end
+
+ context 'with prefixed numbers as double byte character strings as bounds' do
+ it { is_expected.to run.with_params('ホスト01', 'ホスト04').and_return(%w[ホスト01 ホスト02 ホスト03 ホスト04]) }
+ end
+
+ context 'with dash-range syntax' do
+ it { is_expected.to run.with_params('4-1').and_return([]) }
+ it { is_expected.to run.with_params('1-1').and_return([1]) }
+ it { is_expected.to run.with_params('1-2').and_return([1, 2]) }
+ it { is_expected.to run.with_params('1-4').and_return([1, 2, 3, 4]) }
+ end
+
+ context 'with two-dot-range syntax' do
+ it { is_expected.to run.with_params('4..1').and_return([]) }
+ it { is_expected.to run.with_params('1..1').and_return([1]) }
+ it { is_expected.to run.with_params('1..2').and_return([1, 2]) }
+ it { is_expected.to run.with_params('1..4').and_return([1, 2, 3, 4]) }
+ end
+
+ context 'with three-dot-range syntax' do
+ it { is_expected.to run.with_params('4...1').and_return([]) }
+ it { is_expected.to run.with_params('1...1').and_return([]) }
+ it { is_expected.to run.with_params('1...2').and_return([1]) }
+ it { is_expected.to run.with_params('1...3').and_return([1, 2]) }
+ it { is_expected.to run.with_params('1...5').and_return([1, 2, 3, 4]) }
+ end
+
+ describe 'when passing mixed arguments as bounds' do
+ it {
+ pending('these bounds should not be allowed as ruby will OOM hard. e.g. `(\'host0\'..\'hosta\').to_a` has 3239930 elements on ruby 1.9, adding more \'0\'s and \'a\'s increases that exponentially') # rubocop:disable Metrics/LineLength : unable to cut line to required length
+ is_expected.to run.with_params('0', 'a').and_raise_error(Puppet::ParseError, %r{cannot interpolate between numeric and non-numeric bounds})
+ }
+ it {
+ pending('these bounds should not be allowed as ruby will OOM hard. e.g. `(\'host0\'..\'hosta\').to_a` has 3239930 elements on ruby 1.9, adding more \'0\'s and \'a\'s increases that exponentially') # rubocop:disable Metrics/LineLength : unable to cut line to required length
+ is_expected.to run.with_params(0, 'a').and_raise_error(Puppet::ParseError, %r{cannot interpolate between numeric and non-numeric bounds})
+ }
+ it {
+ pending('these bounds should not be allowed as ruby will OOM hard. e.g. `(\'host0\'..\'hosta\').to_a` has 3239930 elements on ruby 1.9, adding more \'0\'s and \'a\'s increases that exponentially') # rubocop:disable Metrics/LineLength : unable to cut line to required length
+ is_expected.to run.with_params('h0', 'ha').and_raise_error(Puppet::ParseError, %r{cannot interpolate between numeric and non-numeric bounds})
+ }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/regexpescape_spec.rb b/code/environments/production/modules/stdlib/spec/functions/regexpescape_spec.rb
new file mode 100644
index 0000000..d5b1f15
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/regexpescape_spec.rb
@@ -0,0 +1,41 @@
+require 'spec_helper'
+
+describe 'regexpescape' do
+ describe 'signature validation' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it {
+ pending('Current implementation ignores parameters after the first.')
+ is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
+ }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
+ it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
+ it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
+ end
+
+ describe 'handling normal strings' do
+ it 'calls ruby\'s Regexp.escape function' do
+ Regexp.expects(:escape).with('regexp_string').returns('escaped_regexp_string').once
+ is_expected.to run.with_params('regexp_string').and_return('escaped_regexp_string')
+ end
+ end
+
+ describe 'handling classes derived from String' do
+ it 'calls ruby\'s Regexp.escape function' do
+ regexp_string = AlsoString.new('regexp_string')
+ Regexp.expects(:escape).with(regexp_string).returns('escaped_regexp_string').once
+ is_expected.to run.with_params(regexp_string).and_return('escaped_regexp_string')
+ end
+ end
+
+ describe 'strings in arrays handling' do
+ it { is_expected.to run.with_params([]).and_return([]) }
+ it { is_expected.to run.with_params(['one*', 'two']).and_return(['one\*', 'two']) }
+ it { is_expected.to run.with_params(['one*', 1, true, {}, 'two']).and_return(['one\*', 1, true, {}, 'two']) }
+
+ context 'with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params(['ŏʼnε*']).and_return(['ŏʼnε\*']) }
+ it { is_expected.to run.with_params(['インターネット*']).and_return(['インターネット\*']) }
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/reject_spec.rb b/code/environments/production/modules/stdlib/spec/functions/reject_spec.rb
new file mode 100644
index 0000000..f083e74
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/reject_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe 'reject' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params([], 'pattern', 'extra').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+
+ it {
+ pending('reject does not actually check this, and raises NoMethodError instead')
+ is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, %r{first argument not an array})
+ }
+ it {
+ pending('reject does not actually check this, and raises NoMethodError instead')
+ is_expected.to run.with_params(1, 'two').and_raise_error(Puppet::ParseError, %r{first argument not an array})
+ }
+ it { is_expected.to run.with_params([], 'two').and_return([]) }
+ it { is_expected.to run.with_params(%w[one two three], 'two').and_return(%w[one three]) }
+ it { is_expected.to run.with_params(%w[one two three], 't(wo|hree)').and_return(['one']) }
+ it { is_expected.to run.with_params(%w[όʼnệ ţщồ ţңяέέ], 'ţ(щồ|ңяέέ)').and_return(['όʼnệ']) }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/reverse_spec.rb b/code/environments/production/modules/stdlib/spec/functions/reverse_spec.rb
new file mode 100644
index 0000000..6573fa7
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/reverse_spec.rb
@@ -0,0 +1,33 @@
+require 'spec_helper'
+
+describe 'reverse' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it {
+ pending('Current implementation ignores parameters after the first.')
+ is_expected.to run.with_params([], 'extra').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
+ }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
+ it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
+ it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
+ it { is_expected.to run.with_params([]).and_return([]) }
+ it { is_expected.to run.with_params(['a']).and_return(['a']) }
+ it { is_expected.to run.with_params(['one']).and_return(['one']) }
+ it { is_expected.to run.with_params(%w[one two three]).and_return(%w[three two one]) }
+ it { is_expected.to run.with_params(%w[one two three four]).and_return(%w[four three two one]) }
+ it { is_expected.to run.with_params(%w[ổňë ťŵọ ŧңяəė ƒŏůŗ]).and_return(%w[ƒŏůŗ ŧңяəė ťŵọ ổňë]) }
+
+ it { is_expected.to run.with_params('').and_return('') }
+ it { is_expected.to run.with_params('a').and_return('a') }
+ it { is_expected.to run.with_params('abc').and_return('cba') }
+ it { is_expected.to run.with_params('abcd').and_return('dcba') }
+ it { is_expected.to run.with_params('āβćđ').and_return('đćβā') }
+
+ context 'when using a class extending String' do
+ it 'calls its reverse method' do
+ value = AlsoString.new('asdfghjkl')
+ value.expects(:reverse).returns('foo')
+ expect(subject).to run.with_params(value).and_return('foo')
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/round_spec.rb b/code/environments/production/modules/stdlib/spec/functions/round_spec.rb
new file mode 100644
index 0000000..af99afd
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/round_spec.rb
@@ -0,0 +1,14 @@
+require 'spec_helper'
+
+describe 'round' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params(34.3).and_return(34) }
+ it { is_expected.to run.with_params(-34.3).and_return(-34) }
+ it { is_expected.to run.with_params(34.5).and_return(35) }
+ it { is_expected.to run.with_params(-34.5).and_return(-35) }
+ it { is_expected.to run.with_params(34.7).and_return(35) }
+ it { is_expected.to run.with_params(-34.7).and_return(-35) }
+ it { is_expected.to run.with_params('test').and_raise_error Puppet::ParseError }
+ it { is_expected.to run.with_params('test', 'best').and_raise_error Puppet::ParseError }
+ it { is_expected.to run.with_params(3, 4).and_raise_error Puppet::ParseError }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/rstrip_spec.rb b/code/environments/production/modules/stdlib/spec/functions/rstrip_spec.rb
new file mode 100644
index 0000000..c8cbeb1
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/rstrip_spec.rb
@@ -0,0 +1,35 @@
+require 'spec_helper'
+
+describe 'rstrip' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it {
+ pending('Current implementation ignores parameters after the first.')
+ is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
+ }
+ it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work with}) }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work with}) }
+ it { is_expected.to run.with_params('').and_return('') }
+ it { is_expected.to run.with_params(' ').and_return('') }
+ it { is_expected.to run.with_params(' ').and_return('') }
+ it { is_expected.to run.with_params("\t").and_return('') }
+ it { is_expected.to run.with_params("\t ").and_return('') }
+ it { is_expected.to run.with_params('one').and_return('one') }
+ it { is_expected.to run.with_params(' one').and_return(' one') }
+ it { is_expected.to run.with_params(' one').and_return(' one') }
+ it { is_expected.to run.with_params("\tone").and_return("\tone") }
+ it { is_expected.to run.with_params("\t one").and_return("\t one") }
+ it { is_expected.to run.with_params('one ').and_return('one') }
+ it { is_expected.to run.with_params(' one ').and_return(' one') }
+ it { is_expected.to run.with_params(' one ').and_return(' one') }
+ it { is_expected.to run.with_params(' ǿňè ').and_return(' ǿňè') }
+ it { is_expected.to run.with_params("\tone ").and_return("\tone") }
+ it { is_expected.to run.with_params("\t one ").and_return("\t one") }
+ it { is_expected.to run.with_params("one\t").and_return('one') }
+ it { is_expected.to run.with_params(" one\t").and_return(' one') }
+ it { is_expected.to run.with_params(" one\t").and_return(' one') }
+ it { is_expected.to run.with_params("\tone\t").and_return("\tone") }
+ it { is_expected.to run.with_params("\t one\t").and_return("\t one") }
+ it { is_expected.to run.with_params(' o n e ').and_return(' o n e') }
+ it { is_expected.to run.with_params(AlsoString.new(' one ')).and_return(' one') }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/seeded_rand_spec.rb b/code/environments/production/modules/stdlib/spec/functions/seeded_rand_spec.rb
new file mode 100644
index 0000000..9b7078a
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/seeded_rand_spec.rb
@@ -0,0 +1,58 @@
+require 'spec_helper'
+
+describe 'seeded_rand' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params(1).and_raise_error(ArgumentError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params(0, '').and_raise_error(ArgumentError, %r{first argument must be a positive integer}) }
+ it { is_expected.to run.with_params(1.5, '').and_raise_error(ArgumentError, %r{first argument must be a positive integer}) }
+ it { is_expected.to run.with_params(-10, '').and_raise_error(ArgumentError, %r{first argument must be a positive integer}) }
+ it { is_expected.to run.with_params('-10', '').and_raise_error(ArgumentError, %r{first argument must be a positive integer}) }
+ it { is_expected.to run.with_params('string', '').and_raise_error(ArgumentError, %r{first argument must be a positive integer}) }
+ it { is_expected.to run.with_params([], '').and_raise_error(ArgumentError, %r{first argument must be a positive integer}) }
+ it { is_expected.to run.with_params({}, '').and_raise_error(ArgumentError, %r{first argument must be a positive integer}) }
+ it { is_expected.to run.with_params(1, 1).and_raise_error(ArgumentError, %r{second argument must be a string}) }
+ it { is_expected.to run.with_params(1, []).and_raise_error(ArgumentError, %r{second argument must be a string}) }
+ it { is_expected.to run.with_params(1, {}).and_raise_error(ArgumentError, %r{second argument must be a string}) }
+
+ it 'provides a random number strictly less than the given max' do
+ expect(seeded_rand(3, 'seed')).to satisfy { |n| n.to_i < 3 } # rubocop:disable Lint/AmbiguousBlockAssociation : Cannot parenthesize without break code or violating other Rubocop rules
+ end
+
+ it 'provides a random number greater or equal to zero' do
+ expect(seeded_rand(3, 'seed')).to satisfy { |n| n.to_i >= 0 } # rubocop:disable Lint/AmbiguousBlockAssociation : Cannot parenthesize without break code or violating other Rubocop rules
+ end
+
+ it "provides the same 'random' value on subsequent calls for the same host" do
+ expect(seeded_rand(10, 'seed')).to eql(seeded_rand(10, 'seed'))
+ end
+
+ it 'allows seed to control the random value on a single host' do
+ first_random = seeded_rand(1000, 'seed1')
+ second_different_random = seeded_rand(1000, 'seed2')
+
+ expect(first_random).not_to eql(second_different_random)
+ end
+
+ it 'does not return different values for different hosts' do
+ val1 = seeded_rand(1000, 'foo', :host => 'first.host.com')
+ val2 = seeded_rand(1000, 'foo', :host => 'second.host.com')
+
+ expect(val1).to eql(val2)
+ end
+
+ def seeded_rand(max, seed, args = {})
+ host = args[:host] || '127.0.0.1'
+
+ # workaround not being able to use let(:facts) because some tests need
+ # multiple different hostnames in one context
+ scope.stubs(:lookupvar).with('::fqdn', {}).returns(host)
+
+ scope.function_seeded_rand([max, seed])
+ end
+
+ context 'with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params(1000, 'ǿňè') }
+ it { is_expected.to run.with_params(1000, '文字列') }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/shell_escape_spec.rb b/code/environments/production/modules/stdlib/spec/functions/shell_escape_spec.rb
new file mode 100644
index 0000000..ed63bc3
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/shell_escape_spec.rb
@@ -0,0 +1,29 @@
+require 'spec_helper'
+
+describe 'shell_escape' do
+ it { is_expected.not_to eq(nil) }
+
+ describe 'signature validation' do
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('foo', 'bar').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ end
+
+ describe 'stringification' do
+ it { is_expected.to run.with_params(10).and_return('10') }
+ it { is_expected.to run.with_params(false).and_return('false') }
+ end
+
+ describe 'escaping' do
+ it { is_expected.to run.with_params('foo').and_return('foo') }
+ it { is_expected.to run.with_params('foo bar').and_return('foo\ bar') }
+ it {
+ is_expected.to run.with_params('~`!@#$%^&*()_+-=[]\{}|;\':",./<>?')
+ .and_return('\~\`\!@\#\$\%\^\&\*\(\)_\+-\=\[\]\\\\\{\}\|\;\\\':\",./\<\>\?')
+ }
+ end
+
+ context 'with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params('スペー スを含むテ キスト').and_return('\\ス\\ペ\\ー\\ \\ス\\を\\含\\む\\テ\\ \\ \\キ\\ス\\ト') }
+ it { is_expected.to run.with_params('μťƒ 8 ŧĕχť').and_return('\\μ\\ť\\ƒ\\ 8\\ \\ \\ŧ\\ĕ\\χ\\ť') }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/shell_join_spec.rb b/code/environments/production/modules/stdlib/spec/functions/shell_join_spec.rb
new file mode 100644
index 0000000..b1f7ff2
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/shell_join_spec.rb
@@ -0,0 +1,30 @@
+require 'spec_helper'
+
+describe 'shell_join' do
+ it { is_expected.not_to eq(nil) }
+
+ describe 'signature validation' do
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params(['foo'], ['bar']).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('foo').and_raise_error(Puppet::ParseError, %r{is not an Array}i) }
+ end
+
+ describe 'shell argument joining' do
+ it { is_expected.to run.with_params(['foo']).and_return('foo') }
+ it { is_expected.to run.with_params(%w[foo bar]).and_return('foo bar') }
+ it { is_expected.to run.with_params(['foo', 'bar baz']).and_return('foo bar\ baz') }
+ it {
+ is_expected.to run.with_params(['~`!@#$', '%^&*()_+-=', '[]\{}|;\':"', ',./<>?'])
+ .and_return('\~\`\!@\#\$ \%\^\&\*\(\)_\+-\= \[\]\\\\\{\}\|\;\\\':\" ,./\<\>\?')
+ }
+
+ context 'with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params(%w[μťƒ 8 ŧĕχť]).and_return('\\μ\\ť\\ƒ 8 \\ŧ\\ĕ\\χ\\ť') }
+ it { is_expected.to run.with_params(['スペー', 'スを含むテ', ' キスト']).and_return('\\ス\\ペ\\ー \\ス\\を\\含\\む\\テ \\ \\キ\\ス\\ト') }
+ end
+ end
+
+ describe 'stringification' do
+ it { is_expected.to run.with_params([10, false, 'foo']).and_return('10 false foo') }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/shell_split_spec.rb b/code/environments/production/modules/stdlib/spec/functions/shell_split_spec.rb
new file mode 100644
index 0000000..beda043
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/shell_split_spec.rb
@@ -0,0 +1,33 @@
+require 'spec_helper'
+
+describe 'shell_split' do
+ it { is_expected.not_to eq(nil) }
+
+ describe 'signature validation' do
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('foo', 'bar').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ end
+
+ describe 'stringification' do
+ it { is_expected.to run.with_params(10).and_return(['10']) }
+ it { is_expected.to run.with_params(false).and_return(['false']) }
+ end
+
+ describe 'shell line spliting' do
+ it { is_expected.to run.with_params('foo').and_return(['foo']) }
+ it { is_expected.to run.with_params('foo bar').and_return(%w[foo bar]) }
+ it {
+ is_expected.to run.with_params('\~\`\!@\#\$\%\^\&\*\(\)_\+-\=\[\]\\\\\{\}\|\;\\\':\",./\<\>\?')
+ .and_return(['~`!@#$%^&*()_+-=[]\{}|;\':",./<>?'])
+ }
+ it {
+ is_expected.to run.with_params('\~\`\!@\#\$ \%\^\&\*\(\)_\+-\= \[\]\\\\\{\}\|\;\\\':\" ,./\<\>\?')
+ .and_return(['~`!@#$', '%^&*()_+-=', '[]\{}|;\':"', ',./<>?'])
+ }
+
+ context 'with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params('\\μ\\ť\\ƒ 8 \\ŧ\\ĕ\\χ\\ť').and_return(%w[μťƒ 8 ŧĕχť]) }
+ it { is_expected.to run.with_params('\\ス\\ペ\\ー \\ス\\を\\含\\む\\テ \\ \\キ\\ス\\ト').and_return(['スペー', 'スを含むテ', ' キスト']) }
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/shuffle_spec.rb b/code/environments/production/modules/stdlib/spec/functions/shuffle_spec.rb
new file mode 100644
index 0000000..eba3afa
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/shuffle_spec.rb
@@ -0,0 +1,38 @@
+require 'spec_helper'
+
+describe 'shuffle' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it {
+ pending('Current implementation ignores parameters after the first.')
+ is_expected.to run.with_params([], 'extra').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
+ }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
+ it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
+ it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
+
+ context 'when running with a specific seed' do
+ # make tests deterministic
+ before(:each) { srand(2) }
+
+ it { is_expected.to run.with_params([]).and_return([]) }
+ it { is_expected.to run.with_params(['a']).and_return(['a']) }
+ it { is_expected.to run.with_params(['one']).and_return(['one']) }
+ it { is_expected.to run.with_params(%w[one two three]).and_return(%w[two one three]) }
+ it { is_expected.to run.with_params(%w[one two three four]).and_return(%w[four three two one]) }
+
+ it { is_expected.to run.with_params('').and_return('') }
+ it { is_expected.to run.with_params('a').and_return('a') }
+ it { is_expected.to run.with_params('abc').and_return('bac') }
+ it { is_expected.to run.with_params('abcd').and_return('dcba') }
+
+ context 'with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params('ůţƒ8 ŧέχŧ şŧґíńģ').and_return('ģńş ůχţέƒŧí8ґŧŧ ') }
+ it { is_expected.to run.with_params('日本語の文字列').and_return('字本日語文列の') }
+ end
+
+ context 'when using a class extending String' do
+ it { is_expected.to run.with_params(AlsoString.new('asdfghjkl')).and_return('lkhdsfajg') }
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/size_spec.rb b/code/environments/production/modules/stdlib/spec/functions/size_spec.rb
new file mode 100644
index 0000000..a4079ea
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/size_spec.rb
@@ -0,0 +1,38 @@
+require 'spec_helper'
+
+describe 'size' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it {
+ pending('Current implementation ignores parameters after the first.')
+ is_expected.to run.with_params([], 'extra').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
+ }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Unknown type given}) }
+ it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{Unknown type given}) }
+ it { is_expected.to run.with_params('1').and_raise_error(Puppet::ParseError, %r{Requires either string, array or hash to work}) }
+ it { is_expected.to run.with_params('1.0').and_raise_error(Puppet::ParseError, %r{Requires either string, array or hash to work}) }
+ it { is_expected.to run.with_params([]).and_return(0) }
+ it { is_expected.to run.with_params(['a']).and_return(1) }
+ it { is_expected.to run.with_params(%w[one two three]).and_return(3) }
+ it { is_expected.to run.with_params(%w[one two three four]).and_return(4) }
+
+ it { is_expected.to run.with_params({}).and_return(0) }
+ it { is_expected.to run.with_params('1' => '2').and_return(1) }
+ it { is_expected.to run.with_params('1' => '2', '4' => '4').and_return(2) }
+ it { is_expected.to run.with_params('€' => '@', '竹' => 'ǿňè').and_return(2) }
+
+ it { is_expected.to run.with_params('').and_return(0) }
+ it { is_expected.to run.with_params('a').and_return(1) }
+ it { is_expected.to run.with_params('abc').and_return(3) }
+ it { is_expected.to run.with_params('abcd').and_return(4) }
+ it { is_expected.to run.with_params('万').and_return(1) }
+ it { is_expected.to run.with_params('āβćđ').and_return(4) }
+
+ context 'when using a class extending String' do
+ it 'calls its size method' do
+ value = AlsoString.new('asdfghjkl')
+ value.expects(:size).returns('foo')
+ expect(subject).to run.with_params(value).and_return('foo')
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/sort_spec.rb b/code/environments/production/modules/stdlib/spec/functions/sort_spec.rb
new file mode 100644
index 0000000..f21d19f
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/sort_spec.rb
@@ -0,0 +1,33 @@
+require 'spec_helper'
+
+describe 'sort' do
+ describe 'signature validation' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params([], 'extra').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it {
+ pending('stricter input checking')
+ is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{requires string or array})
+ }
+ it {
+ pending('stricter input checking')
+ is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{requires string or array})
+ }
+ it {
+ pending('stricter input checking')
+ is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{requires string or array})
+ }
+ end
+
+ context 'when called with an array' do
+ it { is_expected.to run.with_params([]).and_return([]) }
+ it { is_expected.to run.with_params(['a']).and_return(['a']) }
+ it { is_expected.to run.with_params(%w[c b a]).and_return(%w[a b c]) }
+ end
+
+ context 'when called with a string' do
+ it { is_expected.to run.with_params('').and_return('') }
+ it { is_expected.to run.with_params('a').and_return('a') }
+ it { is_expected.to run.with_params('cbda').and_return('abcd') }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/sprintf_hash_spec.rb b/code/environments/production/modules/stdlib/spec/functions/sprintf_hash_spec.rb
new file mode 100644
index 0000000..4bead46
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/sprintf_hash_spec.rb
@@ -0,0 +1,33 @@
+require 'spec_helper'
+
+describe 'sprintf_hash' do
+ it 'exists' do
+ is_expected.not_to eq(nil)
+ end
+
+ context 'with param count' do
+ it 'fails with no arguments' do
+ is_expected.to run.with_params.and_raise_error(ArgumentError, %r{expects 2 arguments}i)
+ end
+ it 'fails with 1 argument' do
+ is_expected.to run.with_params('').and_raise_error(ArgumentError, %r{expects 2 arguments}i)
+ end
+ it 'fails with too many arguments' do
+ is_expected.to run.with_params('', '', '').and_raise_error(ArgumentError, %r{expects 2 arguments}i)
+ end
+ end
+
+ context 'with param type' do
+ it 'fails with wrong format type' do
+ is_expected.to run.with_params(false, {}).and_raise_error(ArgumentError, %r{parameter 'format' expects a String value}i)
+ end
+ it 'fails with wrong arguments type' do
+ is_expected.to run.with_params('', false).and_raise_error(ArgumentError, %r{parameter 'arguments' expects a Hash value}i)
+ end
+ end
+
+ it 'prints formats with name placeholders' do
+ is_expected.to run.with_params('string %<foo>s and integer %<bar>b', 'foo' => '_foo_', 'bar' => 5) # rubocop:disable Style/FormatStringToken : Template tokens needed for purposes of test
+ .and_return('string _foo_ and integer 101')
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/squeeze_spec.rb b/code/environments/production/modules/stdlib/spec/functions/squeeze_spec.rb
new file mode 100644
index 0000000..05bd884
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/squeeze_spec.rb
@@ -0,0 +1,50 @@
+require 'spec_helper'
+
+describe 'squeeze' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('', '', '').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params(1).and_raise_error(NoMethodError) }
+ it { is_expected.to run.with_params({}).and_raise_error(NoMethodError) }
+ it { is_expected.to run.with_params(true).and_raise_error(NoMethodError) }
+
+ context 'when squeezing a single string' do
+ it { is_expected.to run.with_params('').and_return('') }
+ it { is_expected.to run.with_params('a').and_return('a') }
+ it { is_expected.to run.with_params('aaaaaaaaa').and_return('a') }
+ it { is_expected.to run.with_params('aaaaaaaaa', 'a').and_return('a') }
+ it { is_expected.to run.with_params('aaaaaaaaabbbbbbbbbbcccccccccc', 'b-c').and_return('aaaaaaaaabc') }
+ end
+
+ context 'with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params('ậậậậậậậậậậậậậậậậậậậậ').and_return('ậ') }
+ it { is_expected.to run.with_params('語語語語語語語', '語').and_return('語') }
+ it { is_expected.to run.with_params('ậậậậậậậậậậậậậậậậậ語語語語©©©©©', '©').and_return('ậậậậậậậậậậậậậậậậậ語語語語©') }
+ end
+
+ context 'when squeezing values in an array' do
+ it {
+ is_expected.to run \
+ .with_params(['', 'a', 'aaaaaaaaa', 'aaaaaaaaabbbbbbbbbbcccccccccc']) \
+ .and_return(['', 'a', 'a', 'abc'])
+ }
+ it {
+ is_expected.to run \
+ .with_params(['', 'a', 'aaaaaaaaa', 'aaaaaaaaabbbbbbbbbbcccccccccc'], 'a') \
+ .and_return(['', 'a', 'a', 'abbbbbbbbbbcccccccccc'])
+ }
+ it {
+ is_expected.to run \
+ .with_params(['', 'a', 'aaaaaaaaa', 'aaaaaaaaabbbbbbbbbbcccccccccc'], 'b-c') \
+ .and_return(['', 'a', 'aaaaaaaaa', 'aaaaaaaaabc'])
+ }
+ end
+
+ context 'when using a class extending String' do
+ it 'calls its squeeze method' do
+ value = AlsoString.new('aaaaaaaaa')
+ value.expects(:squeeze).returns('foo')
+ expect(subject).to run.with_params(value).and_return('foo')
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/str2bool_spec.rb b/code/environments/production/modules/stdlib/spec/functions/str2bool_spec.rb
new file mode 100644
index 0000000..fe43c4c
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/str2bool_spec.rb
@@ -0,0 +1,23 @@
+require 'spec_helper'
+
+describe 'str2bool' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it {
+ pending('Current implementation ignores parameters after the first.')
+ is_expected.to run.with_params('true', 'extra').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
+ }
+ it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, %r{Unknown type of boolean given}) }
+
+ describe 'when testing values that mean "true"' do
+ ['TRUE', '1', 't', 'y', 'true', 'yes', true].each do |value|
+ it { is_expected.to run.with_params(value).and_return(true) }
+ end
+ end
+
+ describe 'when testing values that mean "false"' do
+ ['FALSE', '', '0', 'f', 'n', 'false', 'no', false, 'undef', 'undefined'].each do |value|
+ it { is_expected.to run.with_params(value).and_return(false) }
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/str2saltedsha512_spec.rb b/code/environments/production/modules/stdlib/spec/functions/str2saltedsha512_spec.rb
new file mode 100644
index 0000000..e7513c9
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/str2saltedsha512_spec.rb
@@ -0,0 +1,26 @@
+require 'spec_helper'
+
+describe 'str2saltedsha512' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('password', 2).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires a String argument}) }
+
+ context 'when running with a specific seed' do
+ # make tests deterministic
+ before(:each) { srand(2) }
+
+ it {
+ is_expected.to run.with_params('')
+ .and_return('0f8a612f4eeed08e47b3875d00f33c5688f7926298f2d9b5fe19d1323f910bc78b6f7b5892596d2fabaa65e7a8d99b3768c102610cf0432c4827eee01f09451e3fae4f7a')
+ }
+ it {
+ is_expected.to run.with_params('password')
+ .and_return('0f8a612f43134376566c5707718d600effcfb17581fc9d3fa64d7f447dfda317c174ffdb498d2c5bd5c2075dab41c9d7ada5afbdc6b55354980eb5ba61802371e6b64956')
+ }
+ it {
+ is_expected.to run.with_params('verylongpassword')
+ .and_return('0f8a612f7a448537540e062daa8621f9bae326ca8ccb899e1bdb10e7c218cebfceae2530b856662565fdc4d81e986fc50cfbbc46d50436610ed9429ff5e43f2c45b5d039')
+ }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/strftime_spec.rb b/code/environments/production/modules/stdlib/spec/functions/strftime_spec.rb
new file mode 100644
index 0000000..92a6893
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/strftime_spec.rb
@@ -0,0 +1,26 @@
+require 'spec_helper'
+
+describe 'strftime' do
+ it 'exists' do
+ expect(Puppet::Parser::Functions.function('strftime')).to eq('function_strftime')
+ end
+
+ it 'raises a ParseError if there is less than 1 arguments' do
+ expect { scope.function_strftime([]) }.to(raise_error(Puppet::ParseError))
+ end
+
+ it 'using %s should be higher then when I wrote this test' do
+ result = scope.function_strftime(['%s'])
+ expect(result.to_i).to(be > 1_311_953_157)
+ end
+
+ it 'using %s should be greater than 1.5 trillion' do
+ result = scope.function_strftime(['%s'])
+ expect(result.to_i).to(be > 1_500_000_000)
+ end
+
+ it 'returns a date when given %Y-%m-%d' do
+ result = scope.function_strftime(['%Y-%m-%d'])
+ expect(result).to match(%r{^\d{4}-\d{2}-\d{2}$})
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/strip_spec.rb b/code/environments/production/modules/stdlib/spec/functions/strip_spec.rb
new file mode 100644
index 0000000..e13f33a
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/strip_spec.rb
@@ -0,0 +1,35 @@
+require 'spec_helper'
+
+describe 'strip' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it {
+ pending('Current implementation ignores parameters after the first.')
+ is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
+ }
+ it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work with}) }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work with}) }
+ it { is_expected.to run.with_params('').and_return('') }
+ it { is_expected.to run.with_params(' ').and_return('') }
+ it { is_expected.to run.with_params(' ').and_return('') }
+ it { is_expected.to run.with_params("\t").and_return('') }
+ it { is_expected.to run.with_params("\t ").and_return('') }
+ it { is_expected.to run.with_params('one').and_return('one') }
+ it { is_expected.to run.with_params(' one').and_return('one') }
+ it { is_expected.to run.with_params(' one').and_return('one') }
+ it { is_expected.to run.with_params("\tone").and_return('one') }
+ it { is_expected.to run.with_params("\t one").and_return('one') }
+ it { is_expected.to run.with_params('one ').and_return('one') }
+ it { is_expected.to run.with_params(' one ').and_return('one') }
+ it { is_expected.to run.with_params(' one ').and_return('one') }
+ it { is_expected.to run.with_params("\tone ").and_return('one') }
+ it { is_expected.to run.with_params("\t one ").and_return('one') }
+ it { is_expected.to run.with_params("one \t").and_return('one') }
+ it { is_expected.to run.with_params(" one \t").and_return('one') }
+ it { is_expected.to run.with_params(" one \t").and_return('one') }
+ it { is_expected.to run.with_params("\tone \t").and_return('one') }
+ it { is_expected.to run.with_params("\t one \t").and_return('one') }
+ it { is_expected.to run.with_params(' o n e ').and_return('o n e') }
+ it { is_expected.to run.with_params(' ỏŋέ ').and_return('ỏŋέ') }
+ it { is_expected.to run.with_params(AlsoString.new(' one ')).and_return('one') }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/suffix_spec.rb b/code/environments/production/modules/stdlib/spec/functions/suffix_spec.rb
new file mode 100644
index 0000000..f4d5bc1
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/suffix_spec.rb
@@ -0,0 +1,40 @@
+require 'spec_helper'
+
+describe 'suffix' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it {
+ pending('Current implementation ignores parameters after the second.')
+ is_expected.to run.with_params([], 'a', '').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
+ }
+ it { is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, %r{expected first argument to be an Array}) }
+ it { is_expected.to run.with_params([], 2).and_raise_error(Puppet::ParseError, %r{expected second argument to be a String}) }
+ it { is_expected.to run.with_params([]).and_return([]) }
+ it { is_expected.to run.with_params(['one', 2]).and_return(%w[one 2]) }
+ it { is_expected.to run.with_params([], '').and_return([]) }
+ it { is_expected.to run.with_params([''], '').and_return(['']) }
+ it { is_expected.to run.with_params(['one'], 'post').and_return(['onepost']) }
+ it { is_expected.to run.with_params(%w[one two three], 'post').and_return(%w[onepost twopost threepost]) }
+ it { is_expected.to run.with_params(['ỗńέ', 'ťשׂǿ', 'ŧҺř℮ə'], 'рổŝţ').and_return(['ỗńέрổŝţ', 'ťשׂǿрổŝţ', 'ŧҺř℮əрổŝţ']) }
+
+ it {
+ is_expected.to run.with_params({}).and_return({})
+ }
+ it {
+ is_expected.to run.with_params('key1' => 'value1', 2 => 3).and_return('key1' => 'value1', '2' => 3)
+ }
+ it {
+ is_expected.to run.with_params({}, '').and_return({})
+ }
+ it {
+ is_expected.to run.with_params({ 'key' => 'value' }, '').and_return('key' => 'value')
+ }
+ it {
+ is_expected.to run.with_params({ 'key' => 'value' }, 'post').and_return('keypost' => 'value')
+ }
+ it {
+ is_expected.to run \
+ .with_params({ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }, 'post') \
+ .and_return('key1post' => 'value1', 'key2post' => 'value2', 'key3post' => 'value3')
+ }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/swapcase_spec.rb b/code/environments/production/modules/stdlib/spec/functions/swapcase_spec.rb
new file mode 100644
index 0000000..a970d71
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/swapcase_spec.rb
@@ -0,0 +1,40 @@
+require 'spec_helper'
+
+describe 'swapcase' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it {
+ pending('Current implementation ignores parameters after the first.')
+ is_expected.to run.with_params('a', '').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
+ }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
+ it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
+ it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
+ describe 'with strings as inputs' do
+ it { is_expected.to run.with_params('').and_return('') }
+ it { is_expected.to run.with_params('one').and_return('ONE') }
+ it { is_expected.to run.with_params('ONE').and_return('one') }
+ it { is_expected.to run.with_params('oNe').and_return('OnE') }
+ end
+ describe 'with arrays as inputs' do
+ it { is_expected.to run.with_params([]).and_return([]) }
+ describe 'only containing strings' do
+ it { is_expected.to run.with_params(['']).and_return(['']) }
+ it { is_expected.to run.with_params(['one']).and_return(['ONE']) }
+ it { is_expected.to run.with_params(['ONE']).and_return(['one']) }
+ it { is_expected.to run.with_params(['oNe']).and_return(['OnE']) }
+ it { is_expected.to run.with_params(%w[one ONE]).and_return(%w[ONE one]) }
+ it { is_expected.to run.with_params(%w[ONE OnE]).and_return(%w[one oNe]) }
+ it { is_expected.to run.with_params(%w[oNe one]).and_return(%w[OnE ONE]) }
+ end
+ describe 'containing mixed types' do
+ it { is_expected.to run.with_params(['OnE', {}]).and_return(['oNe', {}]) }
+ it { is_expected.to run.with_params(['OnE', 1]).and_return(['oNe', 1]) }
+ it { is_expected.to run.with_params(['OnE', []]).and_return(['oNe', []]) }
+ it { is_expected.to run.with_params(['OnE', ['two']]).and_return(['oNe', ['two']]) }
+ end
+ end
+ it 'accepts objects which extend String' do
+ is_expected.to run.with_params(AlsoString.new('OnE')).and_return('oNe')
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/time_spec.rb b/code/environments/production/modules/stdlib/spec/functions/time_spec.rb
new file mode 100644
index 0000000..2d9472b
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/time_spec.rb
@@ -0,0 +1,21 @@
+require 'spec_helper'
+
+describe 'time' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params('a', '').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+
+ context 'when running at a specific time' do
+ before(:each) do
+ # get a value before stubbing the function
+ test_time = Time.utc(2006, 10, 13, 8, 15, 11)
+ Time.expects(:new).with.returns(test_time).once
+ end
+ it { is_expected.to run.with_params.and_return(1_160_727_311) }
+ it { is_expected.to run.with_params('').and_return(1_160_727_311) }
+ it { is_expected.to run.with_params([]).and_return(1_160_727_311) }
+ it { is_expected.to run.with_params({}).and_return(1_160_727_311) }
+ it { is_expected.to run.with_params('foo').and_return(1_160_727_311) }
+ it { is_expected.to run.with_params('UTC').and_return(1_160_727_311) }
+ it { is_expected.to run.with_params('America/New_York').and_return(1_160_727_311) }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/to_bytes_spec.rb b/code/environments/production/modules/stdlib/spec/functions/to_bytes_spec.rb
new file mode 100644
index 0000000..f3efd90
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/to_bytes_spec.rb
@@ -0,0 +1,70 @@
+require 'spec_helper'
+
+describe 'to_bytes' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('1', 'extras').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params([]).and_raise_error(TypeError, %r{(can't convert|no implicit conversion of) Array (in)?to String}) }
+ it { is_expected.to run.with_params({}).and_raise_error(TypeError, %r{(can't convert|no implicit conversion of) Hash (in)?to String}) }
+ it { is_expected.to run.with_params(true).and_raise_error(TypeError, %r{(can't convert|no implicit conversion of) (TrueClass|true) (in)?to String}) }
+
+ describe 'when passing numbers' do
+ it { is_expected.to run.with_params(0).and_return(0) }
+ it { is_expected.to run.with_params(1).and_return(1) }
+ it { is_expected.to run.with_params(-1).and_return(-1) }
+ it { is_expected.to run.with_params(1.1).and_return(1.1) }
+ it { is_expected.to run.with_params(-1.1).and_return(-1.1) }
+ end
+
+ describe 'when passing numbers as strings' do
+ describe 'without a unit' do
+ it { is_expected.to run.with_params('1').and_return(1) }
+ it { is_expected.to run.with_params('-1').and_return(-1) }
+ # these are so wrong
+ it { is_expected.to run.with_params('1.1').and_return(1) }
+ it { is_expected.to run.with_params('-1.1').and_return(-1) }
+ end
+
+ describe 'with a unit' do
+ it { is_expected.to run.with_params('1k').and_return(1024) }
+ it { is_expected.to run.with_params('-1kB').and_return(-1024) }
+ it { is_expected.to run.with_params('1M').and_return(1024 * 1024) }
+ it { is_expected.to run.with_params('1G').and_return(1024 * 1024 * 1024) }
+ it { is_expected.to run.with_params('1T').and_return(1024 * 1024 * 1024 * 1024) }
+ it { is_expected.to run.with_params('1P').and_return(1024 * 1024 * 1024 * 1024 * 1024) }
+ it { is_expected.to run.with_params('1E').and_return(1024 * 1024 * 1024 * 1024 * 1024 * 1024) }
+ it { is_expected.to run.with_params('1.5e3M').and_return(1_572_864_000) }
+
+ it { is_expected.to run.with_params('4k').and_return(4 * 1024) }
+ it { is_expected.to run.with_params('-4kB').and_return(4 * -1024) }
+ it { is_expected.to run.with_params('4M').and_return(4 * 1024 * 1024) }
+ it { is_expected.to run.with_params('4G').and_return(4 * 1024 * 1024 * 1024) }
+ it { is_expected.to run.with_params('4T').and_return(4 * 1024 * 1024 * 1024 * 1024) }
+ it { is_expected.to run.with_params('4P').and_return(4 * 1024 * 1024 * 1024 * 1024 * 1024) }
+ it { is_expected.to run.with_params('4E').and_return(4 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024) }
+
+ # these are so wrong
+ it { is_expected.to run.with_params('1.0001 k').and_return(1024) }
+ it { is_expected.to run.with_params('-1.0001 kB').and_return(-1024) }
+ end
+
+ describe 'with a unknown unit' do
+ it { is_expected.to run.with_params('1KB').and_raise_error(Puppet::ParseError, %r{Unknown prefix}) }
+ it { is_expected.to run.with_params('1K').and_raise_error(Puppet::ParseError, %r{Unknown prefix}) }
+ it { is_expected.to run.with_params('1mb').and_raise_error(Puppet::ParseError, %r{Unknown prefix}) }
+ it { is_expected.to run.with_params('1m').and_raise_error(Puppet::ParseError, %r{Unknown prefix}) }
+ it { is_expected.to run.with_params('1%').and_raise_error(Puppet::ParseError, %r{Unknown prefix}) }
+ it { is_expected.to run.with_params('1 p').and_raise_error(Puppet::ParseError, %r{Unknown prefix}) }
+ end
+ end
+
+ # these are so wrong
+ describe 'when passing random stuff' do
+ it { is_expected.to run.with_params('-1....1').and_return(-1) }
+ it { is_expected.to run.with_params('-1.e.e.e.1').and_return(-1) }
+ it { is_expected.to run.with_params('-1+1').and_return(-1) }
+ it { is_expected.to run.with_params('1-1').and_return(1) }
+ it { is_expected.to run.with_params('1 kaboom').and_return(1024) }
+ it { is_expected.to run.with_params('kaboom').and_return(0) }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/to_json_pretty_spec.rb b/code/environments/production/modules/stdlib/spec/functions/to_json_pretty_spec.rb
new file mode 100644
index 0000000..a8da623
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/to_json_pretty_spec.rb
@@ -0,0 +1,16 @@
+require 'spec_helper'
+
+describe 'to_json_pretty' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params([]).and_return("[\n\n]\n") }
+ it { is_expected.to run.with_params(['one']).and_return("[\n \"one\"\n]\n") }
+ it { is_expected.to run.with_params(%w[one two]).and_return("[\n \"one\",\n \"two\"\n]\n") }
+ it { is_expected.to run.with_params({}).and_return("{\n}\n") }
+ it { is_expected.to run.with_params('key' => 'value').and_return("{\n \"key\": \"value\"\n}\n") }
+ it {
+ is_expected.to run.with_params('one' => { 'oneA' => 'A', 'oneB' => { 'oneB1' => '1', 'oneB2' => '2' } }, 'two' => %w[twoA twoB])
+ .and_return("{\n \"one\": {\n \"oneA\": \"A\",\n \"oneB\": {\n \"oneB1\": \"1\",\n \"oneB2\": \"2\"\n }\n },\n \"two\": [\n \"twoA\",\n \"twoB\"\n ]\n}\n") # rubocop:disable Metrics/LineLength : Unable to reduce line to required length
+ }
+ it { is_expected.to run.with_params({ 'one' => '1', 'two' => nil }, true).and_return("{\n \"one\": \"1\"\n}\n") }
+ it { is_expected.to run.with_params(['one', 'two', nil, 'three'], true).and_return("[\n \"one\",\n \"two\",\n \"three\"\n]\n") }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/to_json_spec.rb b/code/environments/production/modules/stdlib/spec/functions/to_json_spec.rb
new file mode 100644
index 0000000..187ca3c
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/to_json_spec.rb
@@ -0,0 +1,22 @@
+require 'spec_helper'
+
+describe 'to_json' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params('').and_return('""') }
+ it { is_expected.to run.with_params(true).and_return('true') }
+ it { is_expected.to run.with_params('one').and_return('"one"') }
+ it { is_expected.to run.with_params([]).and_return('[]') }
+ it { is_expected.to run.with_params(['one']).and_return('["one"]') }
+ it { is_expected.to run.with_params(%w[one two]).and_return('["one","two"]') }
+ it { is_expected.to run.with_params({}).and_return('{}') }
+ it { is_expected.to run.with_params('key' => 'value').and_return('{"key":"value"}') }
+ it {
+ is_expected.to run.with_params('one' => { 'oneA' => 'A', 'oneB' => { 'oneB1' => '1', 'oneB2' => '2' } }, 'two' => %w[twoA twoB])
+ .and_return('{"one":{"oneA":"A","oneB":{"oneB1":"1","oneB2":"2"}},"two":["twoA","twoB"]}')
+ }
+
+ it { is_expected.to run.with_params('‰').and_return('"‰"') }
+ it { is_expected.to run.with_params('竹').and_return('"竹"') }
+ it { is_expected.to run.with_params('Ü').and_return('"Ü"') }
+ it { is_expected.to run.with_params('∇').and_return('"∇"') }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/to_yaml_spec.rb b/code/environments/production/modules/stdlib/spec/functions/to_yaml_spec.rb
new file mode 100644
index 0000000..16948f6
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/to_yaml_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe 'to_yaml' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params('').and_return("--- ''\n") }
+ it { is_expected.to run.with_params(true).and_return("--- true\n...\n") }
+ it { is_expected.to run.with_params('one').and_return("--- one\n...\n") }
+ it { is_expected.to run.with_params([]).and_return("--- []\n") }
+ it { is_expected.to run.with_params(['one']).and_return("---\n- one\n") }
+ it { is_expected.to run.with_params(%w[one two]).and_return("---\n- one\n- two\n") }
+ it { is_expected.to run.with_params({}).and_return("--- {}\n") }
+ it { is_expected.to run.with_params('key' => 'value').and_return("---\nkey: value\n") }
+ it {
+ is_expected.to run.with_params('one' => { 'oneA' => 'A', 'oneB' => { 'oneB1' => '1', 'oneB2' => '2' } }, 'two' => %w[twoA twoB])
+ .and_return("---\none:\n oneA: A\n oneB:\n oneB1: '1'\n oneB2: '2'\ntwo:\n- twoA\n- twoB\n")
+ }
+
+ it { is_expected.to run.with_params('‰').and_return("--- \"‰\"\n") }
+ it { is_expected.to run.with_params('∇').and_return("--- \"∇\"\n") }
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/try_get_value_spec.rb b/code/environments/production/modules/stdlib/spec/functions/try_get_value_spec.rb
new file mode 100644
index 0000000..630296b
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/try_get_value_spec.rb
@@ -0,0 +1,108 @@
+require 'spec_helper'
+
+describe 'try_get_value' do
+ let(:data) do
+ {
+ 'a' => {
+ 'g' => '2',
+ 'e' => [
+ 'f0',
+ 'f1',
+ {
+ 'x' => {
+ 'y' => 'z',
+ },
+ },
+ 'f3',
+ ],
+ },
+ 'b' => true,
+ 'c' => false,
+ 'd' => '1',
+ }
+ end
+
+ context 'with single values' do
+ it 'exists' do
+ is_expected.not_to eq(nil)
+ end
+
+ it 'is able to return a single value' do
+ is_expected.to run.with_params('test').and_return('test')
+ end
+
+ it 'uses the default value if data is a single value and path is present' do
+ is_expected.to run.with_params('test', 'path', 'default').and_return('default')
+ end
+
+ it 'returns default if there is no data' do
+ is_expected.to run.with_params(nil, nil, 'default').and_return('default')
+ end
+
+ it 'is able to use data structures as default values' do
+ is_expected.to run.with_params('test', 'path', data).and_return(data)
+ end
+ end
+
+ context 'with structure values' do
+ it 'is able to extracts a single hash value' do
+ is_expected.to run.with_params(data, 'd', 'default').and_return('1')
+ end
+
+ it 'is able to extract a deeply nested hash value' do
+ is_expected.to run.with_params(data, 'a/g', 'default').and_return('2')
+ end
+
+ it 'returns the default value if the path is not found' do
+ is_expected.to run.with_params(data, 'missing', 'default').and_return('default')
+ end
+
+ it 'returns the default value if the path is too long' do
+ is_expected.to run.with_params(data, 'a/g/c/d', 'default').and_return('default')
+ end
+
+ it 'supports an array index in the path' do
+ is_expected.to run.with_params(data, 'a/e/1', 'default').and_return('f1')
+ end
+
+ it 'returns the default value if an array index is not a number' do
+ is_expected.to run.with_params(data, 'a/b/c', 'default').and_return('default')
+ end
+
+ it 'returns the default value if and index is out of array length' do
+ is_expected.to run.with_params(data, 'a/e/5', 'default').and_return('default')
+ end
+
+ it 'is able to path though both arrays and hashes' do
+ is_expected.to run.with_params(data, 'a/e/2/x/y', 'default').and_return('z')
+ end
+
+ it 'is able to return "true" value: default' do
+ is_expected.to run.with_params(data, 'b', 'default').and_return(true)
+ end
+
+ it 'is able to return "true" value' do
+ is_expected.to run.with_params(data, 'm', true).and_return(true)
+ end
+
+ it 'is able to return "false" value: default' do
+ is_expected.to run.with_params(data, 'c', 'default').and_return(false)
+ end
+
+ it 'is able to return "false" value' do
+ is_expected.to run.with_params(data, 'm', false).and_return(false)
+ end
+
+ it 'returns "nil" if value is not found and no default value is provided' do
+ is_expected.to run.with_params(data, 'a/1').and_return(nil)
+ end
+
+ it 'is able to use a custom path separator' do
+ is_expected.to run.with_params(data, 'a::g', 'default', '::').and_return('2')
+ end
+
+ it 'is able to use a custom path separator: default' do
+ is_expected.to run.with_params(data, 'a::c', 'default', '::').and_return('default')
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/type3x_spec.rb b/code/environments/production/modules/stdlib/spec/functions/type3x_spec.rb
new file mode 100644
index 0000000..3a71ed9
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/type3x_spec.rb
@@ -0,0 +1,41 @@
+require 'spec_helper'
+
+describe 'type3x' do
+ it 'exists' do
+ expect(Puppet::Parser::Functions.function('type3x')).to eq('function_type3x')
+ end
+
+ it 'raises a ParseError if there is less than 1 arguments' do
+ expect { scope.function_type3x([]) }.to(raise_error(Puppet::ParseError))
+ end
+
+ it 'returns string when given a string' do
+ result = scope.function_type3x(['aaabbbbcccc'])
+ expect(result).to(eq('string'))
+ end
+
+ it 'returns array when given an array' do
+ result = scope.function_type3x([%w[aaabbbbcccc asdf]])
+ expect(result).to(eq('array'))
+ end
+
+ it 'returns hash when given a hash' do
+ result = scope.function_type3x([{ 'a' => 1, 'b' => 2 }])
+ expect(result).to(eq('hash'))
+ end
+
+ it 'returns integer when given an integer' do
+ result = scope.function_type3x(['1'])
+ expect(result).to(eq('integer'))
+ end
+
+ it 'returns float when given a float' do
+ result = scope.function_type3x(['1.34'])
+ expect(result).to(eq('float'))
+ end
+
+ it 'returns boolean when given a boolean' do
+ result = scope.function_type3x([true])
+ expect(result).to(eq('boolean'))
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/type_of_spec.rb b/code/environments/production/modules/stdlib/spec/functions/type_of_spec.rb
new file mode 100644
index 0000000..4f55b2c
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/type_of_spec.rb
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+if ENV['FUTURE_PARSER'] == 'yes'
+ describe 'type_of' do
+ pending 'teach rspec-puppet to load future-only functions under 3.7.5' do
+ it { is_expected.not_to eq(nil) }
+ end
+ end
+end
+
+if Puppet.version.to_f >= 4.0
+ describe 'type_of' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(ArgumentError) }
+ it { is_expected.to run.with_params('', '').and_raise_error(ArgumentError) }
+
+ it 'gives the type of a string' do
+ expect(subject.call({}, 'hello world')).to be_kind_of(Puppet::Pops::Types::PStringType)
+ end
+
+ it 'gives the type of an integer' do
+ expect(subject.call({}, 5)).to be_kind_of(Puppet::Pops::Types::PIntegerType)
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/type_spec.rb b/code/environments/production/modules/stdlib/spec/functions/type_spec.rb
new file mode 100644
index 0000000..a28a913
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/type_spec.rb
@@ -0,0 +1,42 @@
+require 'spec_helper'
+
+describe 'type' do
+ it 'exists' do
+ expect(Puppet::Parser::Functions.function('type')).to eq('function_type')
+ end
+
+ it 'gives a deprecation warning when called' do
+ scope.expects(:warning).with("type() DEPRECATED: This function will cease to function on Puppet 4; please use type3x() before upgrading to puppet 4 for backwards-compatibility, or migrate to the new parser's typing system.") # rubocop:disable Metrics/LineLength : Unable to reduce to required length
+ scope.function_type(['aoeu'])
+ end
+
+ it 'returns string when given a string' do
+ result = scope.function_type(['aaabbbbcccc'])
+ expect(result).to(eq('string'))
+ end
+
+ it 'returns array when given an array' do
+ result = scope.function_type([%w[aaabbbbcccc asdf]])
+ expect(result).to(eq('array'))
+ end
+
+ it 'returns hash when given a hash' do
+ result = scope.function_type([{ 'a' => 1, 'b' => 2 }])
+ expect(result).to(eq('hash'))
+ end
+
+ it 'returns integer when given an integer' do
+ result = scope.function_type(['1'])
+ expect(result).to(eq('integer'))
+ end
+
+ it 'returns float when given a float' do
+ result = scope.function_type(['1.34'])
+ expect(result).to(eq('float'))
+ end
+
+ it 'returns boolean when given a boolean' do
+ result = scope.function_type([true])
+ expect(result).to(eq('boolean'))
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/union_spec.rb b/code/environments/production/modules/stdlib/spec/functions/union_spec.rb
new file mode 100644
index 0000000..d8dfc4f
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/union_spec.rb
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+describe 'union' do
+ describe 'argument checking' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('one', []).and_raise_error(Puppet::ParseError, %r{Every parameter must be an array}) }
+ it { is_expected.to run.with_params([], 'two').and_raise_error(Puppet::ParseError, %r{Every parameter must be an array}) }
+ it { is_expected.to run.with_params({}, {}).and_raise_error(Puppet::ParseError, %r{Every parameter must be an array}) }
+ end
+
+ it { is_expected.to run.with_params([], []).and_return([]) }
+ it { is_expected.to run.with_params([], ['one']).and_return(['one']) }
+ it { is_expected.to run.with_params(['one'], []).and_return(['one']) }
+ it { is_expected.to run.with_params(['one'], ['one']).and_return(['one']) }
+ it { is_expected.to run.with_params(['one'], ['two']).and_return(%w[one two]) }
+ it { is_expected.to run.with_params(%w[one two three], %w[two three]).and_return(%w[one two three]) }
+ it { is_expected.to run.with_params(%w[one two two three], %w[two three]).and_return(%w[one two three]) }
+ it { is_expected.to run.with_params(%w[one two three], %w[two two three]).and_return(%w[one two three]) }
+ it { is_expected.to run.with_params(%w[one two], %w[two three], %w[one three]).and_return(%w[one two three]) }
+ it { is_expected.to run.with_params(%w[one two], %w[three four], %w[one two three], ['four']).and_return(%w[one two three four]) }
+ it { is_expected.to run.with_params(%w[ốńə ţשׂợ], %w[ŧĥяếệ ƒởųŗ], %w[ốńə ţשׂợ ŧĥяếệ], ['ƒởųŗ']).and_return(%w[ốńə ţשׂợ ŧĥяếệ ƒởųŗ]) }
+ it 'does not confuse types' do is_expected.to run.with_params(%w[1 2 3], [1, 2]).and_return(['1', '2', '3', 1, 2]) end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/unique_spec.rb b/code/environments/production/modules/stdlib/spec/functions/unique_spec.rb
new file mode 100644
index 0000000..b8481e0
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/unique_spec.rb
@@ -0,0 +1,31 @@
+require 'spec_helper'
+
+describe 'unique' do
+ if Puppet.version.to_f < 5.0
+ describe 'signature validation' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it {
+ pending('Current implementation ignores parameters after the first.')
+ is_expected.to run.with_params([], 'extra').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
+ }
+ it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
+ it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
+ end
+
+ context 'when called with an array' do
+ it { is_expected.to run.with_params([]).and_return([]) }
+ it { is_expected.to run.with_params(['a']).and_return(['a']) }
+ it { is_expected.to run.with_params(%w[a b a]).and_return(%w[a b]) }
+ it { is_expected.to run.with_params(%w[ã ъ ã]).and_return(%w[ã ъ]) }
+ end
+
+ context 'when called with a string' do
+ it { is_expected.to run.with_params('').and_return('') }
+ it { is_expected.to run.with_params('a').and_return('a') }
+ it { is_expected.to run.with_params('aaba').and_return('ab') }
+ it { is_expected.to run.with_params('ããъã').and_return('ãъ') }
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/unix2dos_spec.rb b/code/environments/production/modules/stdlib/spec/functions/unix2dos_spec.rb
new file mode 100644
index 0000000..a6af64f
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/unix2dos_spec.rb
@@ -0,0 +1,40 @@
+require 'spec_helper'
+
+describe 'unix2dos' do
+ context 'when checking parameter validity' do
+ it { is_expected.not_to eq(nil) }
+ it do
+ is_expected.to run.with_params.and_raise_error(ArgumentError, %r{Wrong number of arguments})
+ end
+ it do
+ is_expected.to run.with_params('one', 'two').and_raise_error(ArgumentError, %r{Wrong number of arguments})
+ end
+ it do
+ is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError)
+ end
+ it do
+ is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError)
+ end
+ it do
+ is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError)
+ end
+ end
+
+ context 'when converting from unix to dos format' do
+ sample_text = "Hello\nWorld\n"
+ desired_output = "Hello\r\nWorld\r\n"
+
+ it 'outputs dos format' do
+ is_expected.to run.with_params(sample_text).and_return(desired_output)
+ end
+ end
+
+ context 'when converting from dos to dos format' do
+ sample_text = "Hello\r\nWorld\r\n"
+ desired_output = "Hello\r\nWorld\r\n"
+
+ it 'outputs dos format' do
+ is_expected.to run.with_params(sample_text).and_return(desired_output)
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/upcase_spec.rb b/code/environments/production/modules/stdlib/spec/functions/upcase_spec.rb
new file mode 100644
index 0000000..2ef5282
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/upcase_spec.rb
@@ -0,0 +1,26 @@
+require 'spec_helper'
+
+describe 'upcase' do
+ describe 'signature validation' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires an array, hash or object that responds to upcase}) }
+ it { is_expected.to run.with_params([1]).and_raise_error(Puppet::ParseError, %r{Requires an array, hash or object that responds to upcase}) }
+ end
+
+ describe 'normal string handling' do
+ it { is_expected.to run.with_params('abc').and_return('ABC') }
+ it { is_expected.to run.with_params('Abc').and_return('ABC') }
+ it { is_expected.to run.with_params('ABC').and_return('ABC') }
+ end
+
+ describe 'handling classes derived from String' do
+ it { is_expected.to run.with_params(AlsoString.new('ABC')).and_return('ABC') }
+ end
+
+ describe 'strings in arrays handling' do
+ it { is_expected.to run.with_params([]).and_return([]) }
+ it { is_expected.to run.with_params(%w[One twO]).and_return(%w[ONE TWO]) }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/uriescape_spec.rb b/code/environments/production/modules/stdlib/spec/functions/uriescape_spec.rb
new file mode 100644
index 0000000..3f1fd9d
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/uriescape_spec.rb
@@ -0,0 +1,36 @@
+require 'spec_helper'
+
+describe 'uriescape' do
+ describe 'signature validation' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it {
+ pending('Current implementation ignores parameters after the first.')
+ is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
+ }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
+ it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
+ it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
+ end
+
+ describe 'handling normal strings' do
+ it 'calls ruby\'s URI.escape function' do
+ URI.expects(:escape).with('uri_string').returns('escaped_uri_string').once
+ is_expected.to run.with_params('uri_string').and_return('escaped_uri_string')
+ end
+ end
+
+ describe 'handling classes derived from String' do
+ it 'calls ruby\'s URI.escape function' do
+ uri_string = AlsoString.new('uri_string')
+ URI.expects(:escape).with(uri_string).returns('escaped_uri_string').once
+ is_expected.to run.with_params(uri_string).and_return('escaped_uri_string')
+ end
+ end
+
+ describe 'strings in arrays handling' do
+ it { is_expected.to run.with_params([]).and_return([]) }
+ it { is_expected.to run.with_params(['one}', 'two']).and_return(['one%7D', 'two']) }
+ it { is_expected.to run.with_params(['one}', 1, true, {}, 'two']).and_return(['one%7D', 1, true, {}, 'two']) }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/validate_absolute_path_spec.rb b/code/environments/production/modules/stdlib/spec/functions/validate_absolute_path_spec.rb
new file mode 100644
index 0000000..5e93bb3
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/validate_absolute_path_spec.rb
@@ -0,0 +1,72 @@
+require 'spec_helper'
+
+describe 'validate_absolute_path' do
+ after(:each) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+
+ # Checking for deprecation warning
+ it 'displays a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('c:/')
+ end
+
+ describe 'signature validation' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ end
+
+ describe 'valid paths handling' do
+ %w[
+ C:/
+ C:\\
+ C:\\WINDOWS\\System32
+ C:/windows/system32
+ X:/foo/bar
+ X:\\foo\\bar
+ \\\\host\\windows
+ //host/windows
+ /
+ /var/tmp
+ /var/opt/../lib/puppet
+ ].each do |path|
+ it { is_expected.to run.with_params(path) }
+ it { is_expected.to run.with_params(['/tmp', path]) }
+ end
+ end
+
+ describe 'invalid path handling' do
+ context 'with garbage inputs' do
+ [
+ nil,
+ [nil],
+ [nil, nil],
+ { 'foo' => 'bar' },
+ {},
+ '',
+ ].each do |path|
+ it { is_expected.to run.with_params(path).and_raise_error(Puppet::ParseError, %r{is not an absolute path}) }
+ it { is_expected.to run.with_params([path]).and_raise_error(Puppet::ParseError, %r{is not an absolute path}) }
+ it { is_expected.to run.with_params(['/tmp', path]).and_raise_error(Puppet::ParseError, %r{is not an absolute path}) }
+ end
+ end
+
+ context 'with relative paths' do
+ %w[
+ relative1
+ .
+ ..
+ ./foo
+ ../foo
+ etc/puppetlabs/puppet
+ opt/puppet/bin
+ relative\\windows
+ ].each do |path|
+ it { is_expected.to run.with_params(path).and_raise_error(Puppet::ParseError, %r{is not an absolute path}) }
+ it { is_expected.to run.with_params([path]).and_raise_error(Puppet::ParseError, %r{is not an absolute path}) }
+ it { is_expected.to run.with_params(['/tmp', path]).and_raise_error(Puppet::ParseError, %r{is not an absolute path}) }
+ end
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/validate_array_spec.rb b/code/environments/production/modules/stdlib/spec/functions/validate_array_spec.rb
new file mode 100644
index 0000000..660974a
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/validate_array_spec.rb
@@ -0,0 +1,35 @@
+require 'spec_helper'
+
+describe 'validate_array' do
+ describe 'signature validation' do
+ after(:each) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ it { is_expected.not_to eq(nil) }
+ # Checking for deprecation warning
+ it 'displays a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params([])
+ end
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+
+ describe 'valid inputs' do
+ it { is_expected.to run.with_params([]) }
+ it { is_expected.to run.with_params(['one']) }
+ it { is_expected.to run.with_params([], ['two']) }
+ it { is_expected.to run.with_params(['one'], ['two']) }
+ end
+
+ describe 'invalid inputs' do
+ it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{is not an Array}) }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{is not an Array}) }
+ it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{is not an Array}) }
+ it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, %r{is not an Array}) }
+ it { is_expected.to run.with_params([], {}).and_raise_error(Puppet::ParseError, %r{is not an Array}) }
+ it { is_expected.to run.with_params([], 1).and_raise_error(Puppet::ParseError, %r{is not an Array}) }
+ it { is_expected.to run.with_params([], true).and_raise_error(Puppet::ParseError, %r{is not an Array}) }
+ it { is_expected.to run.with_params([], 'one').and_raise_error(Puppet::ParseError, %r{is not an Array}) }
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/validate_augeas_spec.rb b/code/environments/production/modules/stdlib/spec/functions/validate_augeas_spec.rb
new file mode 100644
index 0000000..2dd0df8
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/validate_augeas_spec.rb
@@ -0,0 +1,75 @@
+require 'spec_helper'
+
+describe 'validate_augeas' do
+ if Puppet.features.augeas?
+ describe 'signature validation' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('', '', [], '', 'extra').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('one', 'one', 'MSG to User', '4th arg').and_raise_error(NoMethodError) }
+ end
+
+ describe 'valid inputs' do
+ inputs = [
+ ["root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns'],
+ ["proc /proc proc nodev,noexec,nosuid 0 0\n", 'Fstab.lns'],
+ ]
+
+ inputs.each do |input|
+ it { is_expected.to run.with_params(*input) }
+ end
+ end
+
+ describe 'valid inputs which fail augeas validation' do
+ # The intent here is to make sure valid inputs raise exceptions when they
+ # don't specify an error message to display. This is the behvior in
+ # 2.2.x and prior.
+ inputs = [
+ ["root:x:0:0:root\n", 'Passwd.lns'],
+ ["127.0.1.1\n", 'Hosts.lns'],
+ ]
+
+ inputs.each do |input|
+ it { is_expected.to run.with_params(*input).and_raise_error(Puppet::ParseError, %r{validate_augeas.*?matched less than it should}) }
+ end
+ end
+
+ describe 'when specifying nice error messages' do
+ # The intent here is to make sure the function returns the 4th argument
+ # in the exception thrown
+ inputs = [
+ ["root:x:0:0:root\n", 'Passwd.lns', [], 'Failed to validate passwd content'],
+ ["127.0.1.1\n", 'Hosts.lns', [], 'Wrong hosts content'],
+ ]
+
+ inputs.each do |input|
+ it { is_expected.to run.with_params(*input).and_raise_error(Puppet::ParseError, %r{#{input[3]}}) }
+ end
+ end
+
+ describe 'matching additional tests' do
+ inputs = [
+ ["root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/foobar']],
+ ["root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/root/shell[.="/bin/sh"]', 'foobar']],
+ ]
+
+ inputs.each do |input|
+ it { is_expected.to run.with_params(*input) }
+ end
+ end
+
+ describe 'failing additional tests' do
+ inputs = [
+ ["foobar:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/foobar']],
+ ["root:x:0:0:root:/root:/bin/sh\n", 'Passwd.lns', ['$file/root/shell[.="/bin/sh"]', 'foobar']],
+ ]
+
+ inputs.each do |input|
+ it { is_expected.to run.with_params(*input).and_raise_error(Puppet::ParseError, %r{testing path}) }
+ end
+ end
+ else
+ skip 'ruby-augeas not installed'
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/validate_bool_spec.rb b/code/environments/production/modules/stdlib/spec/functions/validate_bool_spec.rb
new file mode 100644
index 0000000..565d52e
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/validate_bool_spec.rb
@@ -0,0 +1,36 @@
+require 'spec_helper'
+
+describe 'validate_bool' do
+ after(:each) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+
+ # Checking for deprecation warning
+ it 'displays a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params(true)
+ end
+
+ describe 'signature validation' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ end
+
+ describe 'acceptable values' do
+ it { is_expected.to run.with_params(true) }
+ it { is_expected.to run.with_params(false) }
+ it { is_expected.to run.with_params(true, false, false, true) }
+ end
+
+ describe 'validation failures' do
+ it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, %r{is not a boolean}) }
+ it { is_expected.to run.with_params(true, 'one').and_raise_error(Puppet::ParseError, %r{is not a boolean}) }
+ it { is_expected.to run.with_params('one', false).and_raise_error(Puppet::ParseError, %r{is not a boolean}) }
+ it { is_expected.to run.with_params('true').and_raise_error(Puppet::ParseError, %r{is not a boolean}) }
+ it { is_expected.to run.with_params('false').and_raise_error(Puppet::ParseError, %r{is not a boolean}) }
+ it { is_expected.to run.with_params(true, 'false').and_raise_error(Puppet::ParseError, %r{is not a boolean}) }
+ it { is_expected.to run.with_params('true', false).and_raise_error(Puppet::ParseError, %r{is not a boolean}) }
+ it { is_expected.to run.with_params('true', false, false, false, false, false).and_raise_error(Puppet::ParseError, %r{is not a boolean}) }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/validate_cmd_spec.rb b/code/environments/production/modules/stdlib/spec/functions/validate_cmd_spec.rb
new file mode 100644
index 0000000..91fd0d1
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/validate_cmd_spec.rb
@@ -0,0 +1,41 @@
+require 'spec_helper'
+
+describe 'validate_cmd', :unless => Puppet::Util::Platform.windows? do
+ let(:touch) { File.exist?('/usr/bin/touch') ? '/usr/bin/touch' : '/bin/touch' }
+
+ describe 'signature validation' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('', '', '', 'extra').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it {
+ pending('should implement stricter type checking')
+ is_expected.to run.with_params([], '', '').and_raise_error(Puppet::ParseError, %r{content must be a string})
+ }
+ it {
+ pending('should implement stricter type checking')
+ is_expected.to run.with_params('', [], '').and_raise_error(Puppet::ParseError, %r{checkscript must be a string})
+ }
+ it {
+ pending('should implement stricter type checking')
+ is_expected.to run.with_params('', '', []).and_raise_error(Puppet::ParseError, %r{custom error message must be a string})
+ }
+ end
+
+ context 'when validation fails' do
+ context 'with % placeholder' do
+ it {
+ is_expected.to run
+ .with_params('', "#{touch} % /no/such/file").and_raise_error(Puppet::ParseError, %r{Execution of '#{touch} \S+ \/no\/such\/file' returned 1:.*(cannot touch|o such file or)})
+ }
+ it { is_expected.to run.with_params('', "#{touch} % /no/such/file", 'custom error').and_raise_error(Puppet::ParseError, %r{custom error}) }
+ end
+ context 'without % placeholder' do
+ it {
+ is_expected.to run
+ .with_params('', "#{touch} /no/such/file").and_raise_error(Puppet::ParseError, %r{Execution of '#{touch} \/no\/such\/file \S+' returned 1:.*(cannot touch|o such file or)})
+ }
+ it { is_expected.to run.with_params('', "#{touch} /no/such/file", 'custom error').and_raise_error(Puppet::ParseError, %r{custom error}) }
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/validate_domain_name_spec.rb b/code/environments/production/modules/stdlib/spec/functions/validate_domain_name_spec.rb
new file mode 100644
index 0000000..0ac1a3d
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/validate_domain_name_spec.rb
@@ -0,0 +1,35 @@
+require 'spec_helper'
+
+describe 'validate_domain_name' do
+ describe 'signature validation' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ end
+
+ describe 'valid inputs' do
+ it { is_expected.to run.with_params('com', 'com.') }
+ it { is_expected.to run.with_params('x.com', 'x.com.') }
+ it { is_expected.to run.with_params('foo.example.com', 'foo.example.com.') }
+ it { is_expected.to run.with_params('2foo.example.com', '2foo.example.com.') }
+ it { is_expected.to run.with_params('www.2foo.example.com', 'www.2foo.example.com.') }
+ it { is_expected.to run.with_params('domain.tld', 'puppet.com') }
+ end
+
+ describe 'invalid inputs' do
+ it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+
+ it { is_expected.to run.with_params('foo.example.com', []).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params('foo.example.com', {}).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params('foo.example.com', 1).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params('foo.example.com', true).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+
+ it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, %r{is not a syntactically correct domain name}) }
+ it { is_expected.to run.with_params('invalid domain').and_raise_error(Puppet::ParseError, %r{is not a syntactically correct domain name}) }
+ it { is_expected.to run.with_params('-foo.example.com').and_raise_error(Puppet::ParseError, %r{is not a syntactically correct domain name}) }
+ it { is_expected.to run.with_params('www.example.2com').and_raise_error(Puppet::ParseError, %r{is not a syntactically correct domain name}) }
+ it { is_expected.to run.with_params('192.168.1.1').and_raise_error(Puppet::ParseError, %r{is not a syntactically correct domain name}) }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/validate_email_address_spec.rb b/code/environments/production/modules/stdlib/spec/functions/validate_email_address_spec.rb
new file mode 100644
index 0000000..520c7a4
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/validate_email_address_spec.rb
@@ -0,0 +1,23 @@
+require 'spec_helper'
+
+describe 'validate_email_address' do
+ describe 'signature validation' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ end
+
+ describe 'valid inputs' do
+ it { is_expected.to run.with_params('bob@gmail.com') }
+ it { is_expected.to run.with_params('alice+puppetlabs.com@gmail.com') }
+ end
+
+ describe 'invalid inputs' do
+ it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, %r{is not a valid email}) }
+ it { is_expected.to run.with_params('bob@gmail.com', {}).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params('bob@gmail.com', true).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params('bob@gmail.com', 'one').and_raise_error(Puppet::ParseError, %r{is not a valid email}) }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/validate_hash_spec.rb b/code/environments/production/modules/stdlib/spec/functions/validate_hash_spec.rb
new file mode 100644
index 0000000..be212de
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/validate_hash_spec.rb
@@ -0,0 +1,38 @@
+require 'spec_helper'
+
+describe 'validate_hash' do
+ describe 'signature validation' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+
+ describe 'check for deprecation warning' do
+ after(:each) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ # Checking for deprecation warning
+ it 'displays a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('key' => 'value')
+ end
+ end
+
+ describe 'valid inputs' do
+ it { is_expected.to run.with_params({}) }
+ it { is_expected.to run.with_params('key' => 'value') }
+ it { is_expected.to run.with_params({}, 'key' => 'value') }
+ it { is_expected.to run.with_params({ 'key1' => 'value1' }, 'key2' => 'value2') }
+ end
+
+ describe 'invalid inputs' do
+ it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, %r{is not a Hash}) }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{is not a Hash}) }
+ it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{is not a Hash}) }
+ it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, %r{is not a Hash}) }
+ it { is_expected.to run.with_params({}, []).and_raise_error(Puppet::ParseError, %r{is not a Hash}) }
+ it { is_expected.to run.with_params({}, 1).and_raise_error(Puppet::ParseError, %r{is not a Hash}) }
+ it { is_expected.to run.with_params({}, true).and_raise_error(Puppet::ParseError, %r{is not a Hash}) }
+ it { is_expected.to run.with_params({}, 'one').and_raise_error(Puppet::ParseError, %r{is not a Hash}) }
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/validate_integer_spec.rb b/code/environments/production/modules/stdlib/spec/functions/validate_integer_spec.rb
new file mode 100644
index 0000000..4792d95
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/validate_integer_spec.rb
@@ -0,0 +1,101 @@
+require 'spec_helper'
+
+describe 'validate_integer' do
+ after(:each) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+
+ # Checking for deprecation warning
+ it 'displays a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params(3)
+ end
+
+ describe 'signature validation' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params(1, 2, 3, 4).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+
+ [true, 'true', false, 'false', 'iAmAString', '1test', '1 test', 'test 1', 'test 1 test', 7.0, -7.0, {}, { 'key' => 'value' }, { 1 => 2 }, '', :undef, 'x'].each do |invalid|
+ it { is_expected.to run.with_params(invalid).and_raise_error(Puppet::ParseError, %r{to be an Integer}) }
+ it { is_expected.to run.with_params(invalid, 10).and_raise_error(Puppet::ParseError, %r{to be an Integer}) }
+ it { is_expected.to run.with_params(invalid, 10, -10).and_raise_error(Puppet::ParseError, %r{to be an Integer}) }
+ it { is_expected.to run.with_params([0, 1, 2, invalid, 3, 4], 10, -10).and_raise_error(Puppet::ParseError, %r{to be an Integer}) }
+ end
+
+ context 'when running on modern rubies', :unless => RUBY_VERSION == '1.8.7' do
+ it { is_expected.to run.with_params([0, 1, 2, { 1 => 2 }, 3, 4], 10, -10).and_raise_error(Puppet::ParseError, %r{to be an Integer}) }
+ end
+
+ context 'when running on ruby, which munges hashes weirdly', :if => RUBY_VERSION == '1.8.7' do
+ it { is_expected.to run.with_params([0, 1, 2, { 1 => 2 }, 3, 4], 10, -10).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params([0, 1, 2, { 0 => 2 }, 3, 4], 10, -10).and_raise_error(Puppet::ParseError) }
+ end
+
+ it { is_expected.to run.with_params(1, '').and_raise_error(Puppet::ParseError, %r{to be unset or an Integer}) }
+ it { is_expected.to run.with_params(1, 2, '').and_raise_error(Puppet::ParseError, %r{to be unset or an Integer}) }
+ it { is_expected.to run.with_params(1, 2, 3).and_raise_error(Puppet::ParseError, %r{second argument to be larger than third argument}) }
+ end
+
+ context 'with no range constraints' do
+ it { is_expected.to run.with_params(1) }
+ it { is_expected.to run.with_params(-1) }
+ it { is_expected.to run.with_params('1') }
+ it { is_expected.to run.with_params('-1') }
+ it { is_expected.to run.with_params([1, 2, 3, 4]) }
+ it { is_expected.to run.with_params([1, '2', '3', 4]) }
+ end
+
+ context 'with a maximum limit of 10' do
+ describe 'rejects numbers greater than the limit' do
+ it { is_expected.to run.with_params(11, 10).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) }
+ it { is_expected.to run.with_params(100, 10).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) }
+ it { is_expected.to run.with_params(2**65, 10).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) }
+ it { is_expected.to run.with_params([1, 2, 10, 100], 10).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) }
+ end
+
+ describe 'accepts numbers less or equal to the limit' do
+ it { is_expected.to run.with_params(10, 10) }
+ it { is_expected.to run.with_params(1, 10) }
+ it { is_expected.to run.with_params(-1, 10) }
+ it { is_expected.to run.with_params('1', 10) }
+ it { is_expected.to run.with_params('-1', 10) }
+ it { is_expected.to run.with_params([1, 2, 3, 4], 10) }
+ it { is_expected.to run.with_params([1, '2', '3', 4], 10) }
+ end
+ end
+
+ context 'with a minimum limit of -10' do
+ describe 'rejects numbers greater than the upper limit' do
+ it { is_expected.to run.with_params(11, 10, -10).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) }
+ it { is_expected.to run.with_params(100, 10, -10).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) }
+ it { is_expected.to run.with_params(2**65, 10, -10).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) }
+ it { is_expected.to run.with_params([1, 2, 10, 100], 10, -10).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) }
+ end
+
+ describe 'rejects numbers smaller than the lower limit' do
+ it { is_expected.to run.with_params(-11, 10, -10).and_raise_error(Puppet::ParseError, %r{to be greater or equal}) }
+ it { is_expected.to run.with_params(-100, 10, -10).and_raise_error(Puppet::ParseError, %r{to be greater or equal}) }
+ it { is_expected.to run.with_params(-2**65, 10, -10).and_raise_error(Puppet::ParseError, %r{to be greater or equal}) }
+ it { is_expected.to run.with_params([-10, 1, 2, 10, -100], 10, -10).and_raise_error(Puppet::ParseError, %r{to be greater or equal}) }
+ end
+
+ describe 'accepts numbers between and including the limits' do
+ it { is_expected.to run.with_params(10, 10, -10) }
+ it { is_expected.to run.with_params(-10, 10, -10) }
+ it { is_expected.to run.with_params(1, 10, -10) }
+ it { is_expected.to run.with_params(-1, 10, -10) }
+ it { is_expected.to run.with_params('1', 10, -10) }
+ it { is_expected.to run.with_params('-1', 10, -10) }
+ it { is_expected.to run.with_params([1, 2, 3, 4], 10, -10) }
+ it { is_expected.to run.with_params([1, '2', '3', 4], 10, -10) }
+ end
+ end
+
+ it { is_expected.to run.with_params(10, 10, 10) }
+
+ describe 'empty upper limit is interpreted as infinity' do
+ it { is_expected.to run.with_params(11, '', 10) }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/validate_ip_address_spec.rb b/code/environments/production/modules/stdlib/spec/functions/validate_ip_address_spec.rb
new file mode 100644
index 0000000..714f7b2
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/validate_ip_address_spec.rb
@@ -0,0 +1,64 @@
+require 'spec_helper'
+
+describe 'validate_ip_address' do
+ describe 'signature validation' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ end
+
+ describe 'valid inputs' do
+ it { is_expected.to run.with_params('0.0.0.0') }
+ it { is_expected.to run.with_params('8.8.8.8') }
+ it { is_expected.to run.with_params('127.0.0.1') }
+ it { is_expected.to run.with_params('10.10.10.10') }
+ it { is_expected.to run.with_params('194.232.104.150') }
+ it { is_expected.to run.with_params('244.24.24.24') }
+ it { is_expected.to run.with_params('255.255.255.255') }
+ it { is_expected.to run.with_params('1.2.3.4', '5.6.7.8') }
+ it { is_expected.to run.with_params('3ffe:0505:0002::') }
+ it { is_expected.to run.with_params('3ffe:0505:0002::', '3ffe:0505:0002::2') }
+ it { is_expected.to run.with_params('::1/64') }
+ it { is_expected.to run.with_params('fe80::a00:27ff:fe94:44d6/64') }
+
+ context 'Checking for deprecation warning', :if => Puppet.version.to_f < 4.0 do
+ after(:each) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
+ it 'displays a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('1.2.3.4')
+ end
+ it 'displays no warning for deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'false'
+ scope.expects(:warning).with(includes('This method is deprecated')).never
+ is_expected.to run.with_params('1.2.3.4')
+ end
+ end
+
+ context 'with netmasks' do
+ it { is_expected.to run.with_params('8.8.8.8/0') }
+ it { is_expected.to run.with_params('8.8.8.8/16') }
+ it { is_expected.to run.with_params('8.8.8.8/32') }
+ it { is_expected.to run.with_params('8.8.8.8/255.255.0.0') }
+ end
+ end
+
+ describe 'invalid inputs' do
+ it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, %r{is not a valid IP}) }
+ it { is_expected.to run.with_params('0.0.0').and_raise_error(Puppet::ParseError, %r{is not a valid IP}) }
+ it { is_expected.to run.with_params('0.0.0.256').and_raise_error(Puppet::ParseError, %r{is not a valid IP}) }
+ it { is_expected.to run.with_params('0.0.0.0.0').and_raise_error(Puppet::ParseError, %r{is not a valid IP}) }
+ it { is_expected.to run.with_params('1.2.3.4', {}).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params('1.2.3.4', 1).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params('1.2.3.4', true).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params('1.2.3.4', 'one').and_raise_error(Puppet::ParseError, %r{is not a valid IP}) }
+ it { is_expected.to run.with_params('::1', {}).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params('::1', true).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params('::1', 'one').and_raise_error(Puppet::ParseError, %r{is not a valid IP}) }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/validate_ipv4_address_spec.rb b/code/environments/production/modules/stdlib/spec/functions/validate_ipv4_address_spec.rb
new file mode 100644
index 0000000..72a8018
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/validate_ipv4_address_spec.rb
@@ -0,0 +1,40 @@
+require 'spec_helper'
+
+describe 'validate_ipv4_address' do
+ describe 'signature validation' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ end
+
+ context 'Checking for deprecation warning', :if => Puppet.version.to_f < 4.0 do
+ after(:each) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
+ it 'displays a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params(SharedData::IPV4_PATTERNS.first)
+ end
+ it 'displays no warning for deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'false'
+ scope.expects(:warning).with(includes('This method is deprecated')).never
+ is_expected.to run.with_params(SharedData::IPV4_PATTERNS.first)
+ end
+ end
+
+ SharedData::IPV4_PATTERNS.each do |value|
+ it { is_expected.to run.with_params(value) }
+ end
+
+ SharedData::IPV4_NEGATIVE_PATTERNS.each do |value|
+ it { is_expected.to run.with_params(value).and_raise_error(Puppet::ParseError, %r{is not a valid IPv4}) }
+ end
+
+ describe 'invalid inputs' do
+ [{}, [], 1, true].each do |invalid|
+ it { is_expected.to run.with_params(invalid).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params(SharedData::IPV4_PATTERNS.first, invalid).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/validate_ipv6_address_spec.rb b/code/environments/production/modules/stdlib/spec/functions/validate_ipv6_address_spec.rb
new file mode 100644
index 0000000..5f4e312
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/validate_ipv6_address_spec.rb
@@ -0,0 +1,59 @@
+require 'spec_helper'
+
+describe 'validate_ipv6_address' do
+ describe 'signature validation' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ end
+
+ context 'Checking for deprecation warning', :if => Puppet.version.to_f < 4.0 do
+ after(:each) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
+ it 'displays a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('3ffe:0505:0002::')
+ end
+ it 'displays no warning for deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'false'
+ scope.expects(:warning).with(includes('This method is deprecated')).never
+ is_expected.to run.with_params('3ffe:0505:0002::')
+ end
+ end
+
+ describe 'valid inputs' do
+ it { is_expected.to run.with_params('3ffe:0505:0002::') }
+ it { is_expected.to run.with_params('3ffe:0505:0002::', '3ffe:0505:0002::2') }
+ it { is_expected.to run.with_params('::1/64') }
+ it { is_expected.to run.with_params('fe80::a00:27ff:fe94:44d6/64') }
+ it { is_expected.to run.with_params('fe80:0000:0000:0000:0204:61ff:fe9d:f156') }
+ it { is_expected.to run.with_params('fe80:0:0:0:204:61ff:fe9d:f156') }
+ it { is_expected.to run.with_params('fe80::204:61ff:fe9d:f156') }
+ it { is_expected.to run.with_params('fe80:0:0:0:0204:61ff:254.157.241.86') }
+ it { is_expected.to run.with_params('::1') }
+ it { is_expected.to run.with_params('fe80::') }
+ it { is_expected.to run.with_params('2001::') }
+ end
+
+ describe 'invalid inputs' do
+ it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, %r{is not a valid IPv6}) }
+ it { is_expected.to run.with_params('0.0.0').and_raise_error(Puppet::ParseError, %r{is not a valid IPv6}) }
+ it { is_expected.to run.with_params('0.0.0.256').and_raise_error(Puppet::ParseError, %r{is not a valid IPv6}) }
+ it { is_expected.to run.with_params('0.0.0.0.0').and_raise_error(Puppet::ParseError, %r{is not a valid IPv6}) }
+ it { is_expected.to run.with_params('::ffff:2.3.4').and_raise_error(Puppet::ParseError, %r{is not a valid IPv6}) }
+ it { is_expected.to run.with_params('::ffff:257.1.2.3').and_raise_error(Puppet::ParseError, %r{is not a valid IPv6}) }
+ it { is_expected.to run.with_params('::ffff:12345678901234567890.1.26').and_raise_error(Puppet::ParseError, %r{is not a valid IPv6}) }
+ it { is_expected.to run.with_params('affe:beef').and_raise_error(Puppet::ParseError, %r{is not a valid IPv6}) }
+ it { is_expected.to run.with_params('::1', {}).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params('::1', true).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params('::1', 'one').and_raise_error(Puppet::ParseError, %r{is not a valid IPv6}) }
+ context 'unless running on ruby 1.8.7', :if => RUBY_VERSION != '1.8.7' do
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params('::1', 1).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/validate_legacy_spec.rb b/code/environments/production/modules/stdlib/spec/functions/validate_legacy_spec.rb
new file mode 100644
index 0000000..06c3b51
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/validate_legacy_spec.rb
@@ -0,0 +1,68 @@
+require 'spec_helper'
+
+if Puppet::Util::Package.versioncmp(Puppet.version, '4.4.0') >= 0
+ describe 'validate_legacy' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(ArgumentError) }
+
+ describe 'when passing the type assertion and passing the previous validation' do
+ before(:each) do
+ scope.expects(:function_validate_foo).with([5]).once
+ Puppet.expects(:notice).never
+ end
+ it 'passes without notice' do
+ is_expected.to run.with_params('Integer', 'validate_foo', 5)
+ end
+ end
+
+ describe 'when passing the type assertion and failing the previous validation' do
+ before(:each) do
+ scope.expects(:function_validate_foo).with([5]).raises(Puppet::ParseError, 'foo').once
+ Puppet.expects(:notice).with(includes('Accepting previously invalid value for target type'))
+ end
+ it 'passes with a notice about newly accepted value' do
+ is_expected.to run.with_params('Integer', 'validate_foo', 5)
+ end
+ end
+
+ describe 'when failing the type assertion and passing the previous validation' do
+ before(:each) do
+ scope.expects(:function_validate_foo).with(['5']).once
+ subject.func.expects(:call_function).with('deprecation', 'validate_legacy', includes('Integer')).once
+ end
+ it 'passes with a deprecation message' do
+ is_expected.to run.with_params('Integer', 'validate_foo', '5')
+ end
+ end
+
+ describe 'when failing the type assertion and failing the previous validation' do
+ before(:each) do
+ scope.expects(:function_validate_foo).with(['5']).raises(Puppet::ParseError, 'foo').once
+ subject.func.expects(:call_function).with('fail', includes('Integer')).once
+ end
+ it 'fails with a helpful message' do
+ is_expected.to run.with_params('Integer', 'validate_foo', '5')
+ end
+ end
+
+ describe 'when passing in undef' do
+ before(:each) do
+ scope.expects(:function_validate_foo).with([:undef]).once
+ Puppet.expects(:notice).never
+ end
+ it 'works' do
+ is_expected.to run.with_params('Optional[Integer]', 'validate_foo', :undef)
+ end
+ end
+
+ describe 'when passing in multiple arguments' do
+ before(:each) do
+ scope.expects(:function_validate_foo).with([:undef, 1, 'foo']).once
+ Puppet.expects(:notice).never
+ end
+ it 'passes with a deprecation message' do
+ is_expected.to run.with_params('Optional[Integer]', 'validate_foo', :undef, 1, 'foo')
+ end
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/validate_numeric_spec.rb b/code/environments/production/modules/stdlib/spec/functions/validate_numeric_spec.rb
new file mode 100644
index 0000000..75217a2
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/validate_numeric_spec.rb
@@ -0,0 +1,100 @@
+require 'spec_helper'
+
+describe 'validate_numeric' do
+ after(:each) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+
+ # Checking for deprecation warning
+ it 'displays a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params(3)
+ end
+
+ describe 'signature validation' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params(1, 2, 3, 4).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+
+ [true, 'true', false, 'false', 'iAmAString', '1test', '1 test', 'test 1', 'test 1 test', {}, { 'key' => 'value' }, { 1 => 2 }, '', :undef, 'x'].each do |invalid|
+ it { is_expected.to run.with_params(invalid).and_raise_error(Puppet::ParseError, %r{to be a Numeric}) }
+ it { is_expected.to run.with_params(invalid, 10.0).and_raise_error(Puppet::ParseError, %r{to be a Numeric}) }
+ it { is_expected.to run.with_params(invalid, 10.0, -10.0).and_raise_error(Puppet::ParseError, %r{to be a Numeric}) }
+ end
+
+ context 'when running on modern rubies', :unless => RUBY_VERSION == '1.8.7' do
+ it { is_expected.to run.with_params([0, 1, 2, { 1 => 2 }, 3, 4], 10, -10).and_raise_error(Puppet::ParseError, %r{to be a Numeric}) }
+ end
+
+ context 'when running on ruby, which munges hashes weirdly', :if => RUBY_VERSION == '1.8.7' do
+ it { is_expected.to run.with_params([0, 1, 2, { 1 => 2 }, 3, 4], 10, -10).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params([0, 1, 2, { 0 => 2 }, 3, 4], 10, -10).and_raise_error(Puppet::ParseError) }
+ end
+
+ it { is_expected.to run.with_params(1, '').and_raise_error(Puppet::ParseError, %r{to be unset or a Numeric}) }
+ it { is_expected.to run.with_params(1, 2, '').and_raise_error(Puppet::ParseError, %r{to be unset or a Numeric}) }
+ it { is_expected.to run.with_params(1, 2, 3).and_raise_error(Puppet::ParseError, %r{second argument to be larger than third argument}) }
+ end
+
+ context 'with no range constraints' do
+ it { is_expected.to run.with_params(1) }
+ it { is_expected.to run.with_params(-1) }
+ it { is_expected.to run.with_params('1') }
+ it { is_expected.to run.with_params('-1') }
+ it { is_expected.to run.with_params([1, 2, 3, 4]) }
+ it { is_expected.to run.with_params([1, '2', '3', 4]) }
+ end
+
+ context 'with a maximum limit of 10.0' do
+ describe 'rejects numbers greater than the limit' do
+ it { is_expected.to run.with_params(11, 10.0).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) }
+ it { is_expected.to run.with_params(100, 10.0).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) }
+ it { is_expected.to run.with_params(2**65, 10.0).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) }
+ it { is_expected.to run.with_params([1, 2, 10.0, 100], 10.0).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) }
+ end
+
+ describe 'accepts numbers less or equal to the limit' do
+ it { is_expected.to run.with_params(10.0, 10.0) }
+ it { is_expected.to run.with_params(1, 10.0) }
+ it { is_expected.to run.with_params(-1, 10.0) }
+ it { is_expected.to run.with_params('1', 10.0) }
+ it { is_expected.to run.with_params('-1', 10.0) }
+ it { is_expected.to run.with_params([1, 2, 3, 4], 10.0) }
+ it { is_expected.to run.with_params([1, '2', '3', 4], 10.0) }
+ end
+ end
+
+ context 'with a minimum limit of -10.0' do
+ describe 'rejects numbers greater than the upper limit' do
+ it { is_expected.to run.with_params(11, 10.0, -10.0).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) }
+ it { is_expected.to run.with_params(100, 10.0, -10.0).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) }
+ it { is_expected.to run.with_params(2**65, 10.0, -10.0).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) }
+ it { is_expected.to run.with_params([1, 2, 10.0, 100], 10.0, -10.0).and_raise_error(Puppet::ParseError, %r{to be smaller or equal}) }
+ end
+
+ describe 'rejects numbers smaller than the lower limit' do
+ it { is_expected.to run.with_params(-11, 10.0, -10.0).and_raise_error(Puppet::ParseError, %r{to be greater or equal}) }
+ it { is_expected.to run.with_params(-100, 10.0, -10.0).and_raise_error(Puppet::ParseError, %r{to be greater or equal}) }
+ it { is_expected.to run.with_params(-2**65, 10.0, -10.0).and_raise_error(Puppet::ParseError, %r{to be greater or equal}) }
+ it { is_expected.to run.with_params([-10.0, 1, 2, 10.0, -100], 10.0, -10.0).and_raise_error(Puppet::ParseError, %r{to be greater or equal}) }
+ end
+
+ describe 'accepts numbers between and including the limits' do
+ it { is_expected.to run.with_params(10.0, 10.0, -10.0) }
+ it { is_expected.to run.with_params(-10.0, 10.0, -10.0) }
+ it { is_expected.to run.with_params(1, 10.0, -10.0) }
+ it { is_expected.to run.with_params(-1, 10.0, -10.0) }
+ it { is_expected.to run.with_params('1', 10.0, -10.0) }
+ it { is_expected.to run.with_params('-1', 10.0, -10.0) }
+ it { is_expected.to run.with_params([1, 2, 3, 4], 10.0, -10.0) }
+ it { is_expected.to run.with_params([1, '2', '3', 4], 10.0, -10.0) }
+ end
+ end
+
+ it { is_expected.to run.with_params(10.0, 10.0, 10.0) }
+
+ describe 'empty upper limit is interpreted as infinity' do
+ it { is_expected.to run.with_params(11, '', 10.0) }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/validate_re_spec.rb b/code/environments/production/modules/stdlib/spec/functions/validate_re_spec.rb
new file mode 100644
index 0000000..84391b3
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/validate_re_spec.rb
@@ -0,0 +1,56 @@
+require 'spec_helper'
+
+describe 'validate_re' do
+ after(:each) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+
+ # Checking for deprecation warning
+ it 'displays a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('', '')
+ end
+
+ describe 'signature validation' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('', '', '', 'extra').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+
+ describe 'valid inputs' do
+ it { is_expected.to run.with_params('', '') }
+ it { is_expected.to run.with_params('', ['']) }
+ it { is_expected.to run.with_params('', [''], 'custom error') }
+ it { is_expected.to run.with_params('one', '^one') }
+ it { is_expected.to run.with_params('one', ['^one', '^two']) }
+ it { is_expected.to run.with_params('one', ['^one', '^two'], 'custom error') }
+ end
+
+ describe 'invalid inputs' do
+ it { is_expected.to run.with_params('', []).and_raise_error(Puppet::ParseError, %r{does not match}) }
+ it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, %r{does not match}) }
+ it { is_expected.to run.with_params('', 'two').and_raise_error(Puppet::ParseError, %r{does not match}) }
+ it { is_expected.to run.with_params('', ['two']).and_raise_error(Puppet::ParseError, %r{does not match}) }
+ it { is_expected.to run.with_params('', ['two'], 'custom error').and_raise_error(Puppet::ParseError, %r{custom error}) }
+ it { is_expected.to run.with_params('notone', '^one').and_raise_error(Puppet::ParseError, %r{does not match}) }
+ it { is_expected.to run.with_params('notone', ['^one', '^two']).and_raise_error(Puppet::ParseError, %r{does not match}) }
+ it { is_expected.to run.with_params('notone', ['^one', '^two'], 'custom error').and_raise_error(Puppet::ParseError, %r{custom error}) }
+ end
+
+ describe 'non-string inputs' do
+ [
+ 1, # Fixnum
+ 3.14, # Float
+ nil, # NilClass
+ true, # TrueClass
+ false, # FalseClass
+ ['10'], # Array
+ :key, # Symbol
+ { :key => 'val' }, # Hash
+ ].each do |input|
+ it { is_expected.to run.with_params(input, '.*').and_raise_error(Puppet::ParseError, %r{needs to be a String}) }
+ end
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/validate_slength_spec.rb b/code/environments/production/modules/stdlib/spec/functions/validate_slength_spec.rb
new file mode 100644
index 0000000..bde989b
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/validate_slength_spec.rb
@@ -0,0 +1,81 @@
+require 'spec_helper'
+
+describe 'validate_slength' do
+ after(:each) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+
+ # Checking for deprecation warning
+ it 'displays a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('1234567890', 10)
+ end
+
+ describe 'signature validation' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('', 2, 3, 'extra').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, %r{second argument to be a positive Numeric}) }
+ it { is_expected.to run.with_params('', -1).and_raise_error(Puppet::ParseError, %r{second argument to be a positive Numeric}) }
+ it { is_expected.to run.with_params('', 1, '').and_raise_error(Puppet::ParseError, %r{third argument to be unset or a positive Numeric}) }
+ it { is_expected.to run.with_params('', 1, -1).and_raise_error(Puppet::ParseError, %r{third argument to be unset or a positive Numeric}) }
+ it { is_expected.to run.with_params('', 1, 2).and_raise_error(Puppet::ParseError, %r{argument to be equal to or larger than third argument}) }
+ end
+
+ context 'with a maximum length of 10' do
+ describe 'rejects strings longer than the limit' do
+ it { is_expected.to run.with_params('1234567890a', 10).and_raise_error(Puppet::ParseError, %r{Expected length}) }
+ it { is_expected.to run.with_params('1234567890abcdef', 10).and_raise_error(Puppet::ParseError, %r{Expected length}) }
+ it { is_expected.to run.with_params(%w[one 1234567890abcdef], 10).and_raise_error(Puppet::ParseError, %r{Expected length}) }
+ end
+
+ describe 'accepts strings shorter or equal to the limit' do
+ it { is_expected.to run.with_params('1234567890', 10) }
+ it { is_expected.to run.with_params('12345', 10) }
+ it { is_expected.to run.with_params(%w[one two], 10) }
+ end
+ end
+
+ context 'with a minimum length of 5' do
+ describe 'rejects strings longer than the upper limit' do
+ it { is_expected.to run.with_params('1234567890a', 10, 5).and_raise_error(Puppet::ParseError, %r{Expected length}) }
+ it { is_expected.to run.with_params('1234567890abcdef', 10, 5).and_raise_error(Puppet::ParseError, %r{Expected length}) }
+ end
+
+ describe 'rejects numbers shorter than the lower limit' do
+ it { is_expected.to run.with_params('one', 10, 5).and_raise_error(Puppet::ParseError, %r{Expected length}) }
+ it { is_expected.to run.with_params(%w[12345678 two], 10, 5).and_raise_error(Puppet::ParseError, %r{Expected length}) }
+ end
+
+ describe 'accepts strings of length between and including the limits' do
+ it { is_expected.to run.with_params('12345', 10, 5) }
+ it { is_expected.to run.with_params('123456', 10, 5) }
+ it { is_expected.to run.with_params('1234567', 10, 5) }
+ it { is_expected.to run.with_params('12345678', 10, 5) }
+ it { is_expected.to run.with_params('123456789', 10, 5) }
+ it { is_expected.to run.with_params('1234567890', 10, 5) }
+ it { is_expected.to run.with_params(%w[1233456 12345678], 10, 5) }
+ end
+ end
+
+ describe 'corner cases' do
+ it {
+ pending('this should work')
+ is_expected.to run.with_params('', 0, 0)
+ }
+ it { is_expected.to run.with_params('1234567890', 10, 10) }
+ end
+
+ describe 'empty upper limit is interpreted as infinity' do
+ it {
+ pending('not implemented')
+ is_expected.to run.with_params('1234567890ab', '', 10)
+ }
+ it {
+ pending('not implemented')
+ is_expected.to run.with_params('12345678', '', 10).and_raise_error(Puppet::ParseError, %r{Expected length})
+ }
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/validate_string_spec.rb b/code/environments/production/modules/stdlib/spec/functions/validate_string_spec.rb
new file mode 100644
index 0000000..4459f00
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/validate_string_spec.rb
@@ -0,0 +1,33 @@
+require 'spec_helper'
+
+describe 'validate_string' do
+ after(:each) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+
+ # Checking for deprecation warning
+ it 'displays a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('', '')
+ end
+
+ describe 'signature validation' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+
+ describe 'valid inputs' do
+ it { is_expected.to run.with_params('') }
+ it { is_expected.to run.with_params(nil) }
+ it { is_expected.to run.with_params('one') }
+ it { is_expected.to run.with_params('one', 'two') }
+ end
+
+ describe 'invalid inputs' do
+ it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/validate_x509_rsa_key_pair_spec.rb b/code/environments/production/modules/stdlib/spec/functions/validate_x509_rsa_key_pair_spec.rb
new file mode 100644
index 0000000..891edd2
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/validate_x509_rsa_key_pair_spec.rb
@@ -0,0 +1,181 @@
+require 'spec_helper'
+
+describe 'validate_x509_rsa_key_pair' do
+ # rubocop:disable Layout/IndentHeredoc : Heredoc's are meant to be indented in this way
+ let(:valid_cert) do
+ <<DOC
+-----BEGIN CERTIFICATE-----
+MIIC9jCCAeCgAwIBAgIRAK11n3X7aypJ7FPM8UFyAeowCwYJKoZIhvcNAQELMBIx
+EDAOBgNVBAoTB0FjbWUgQ28wHhcNMTUxMTIzMjIzOTU4WhcNMTYxMTIyMjIzOTU4
+WjASMRAwDgYDVQQKEwdBY21lIENvMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
+CgKCAQEAz9bY/piKahD10AiJSfbI2A8NG5UwRz0r9T/WfvNVdhgrsGFgNQjvpUoZ
+nNJpQIHBbgMOiXqfATFjJl5FjEkSf7GUHohlGVls9MX2JmVvknzsiitd75H/EJd+
+N+k915lix8Vqmj8d1CTlbF/8tEjzANI67Vqw5QTuqebO7rkIUvRg6yiRfSo75FK1
+RinCJyl++kmleBwQZBInQyg95GvJ5JTqMzBs67DeeyzskDhTeTePRYVF2NwL8QzY
+htvLIBERTNsyU5i7nkxY5ptUwgFUwd93LH4Q19tPqL5C5RZqXxhE51thOOwafm+a
+W/cRkqYqV+tv+j1jJ3WICyF1JNW0BQIDAQABo0swSTAOBgNVHQ8BAf8EBAMCAKAw
+EwYDVR0lBAwwCgYIKwYBBQUHAwEwDAYDVR0TAQH/BAIwADAUBgNVHREEDTALggls
+b2NhbGhvc3QwCwYJKoZIhvcNAQELA4IBAQAzRo0hpVTrFQZLIXpwvKwZVGvJdCkV
+P95DTsSk/VTGV+/YtxrRqks++hJZnctm2PbnTsCAoIP3AMx+vicCKiKrxvpsLU8/
++6cowUbcuGMdSQktwDqbAgEhQlLsETll06w1D/KC+ejOc4+LRn3GQcEyGDtMk/EX
+IeAvBZHr4/kVXWnfo6kzCLcku1f8yE/yDEFClZe9XV1Lk/s+3YfXVtNnMJJ1giZI
+QVOe6CkmuQq+4AtIeW8aLkvlfp632jag1F77a1y+L268koKkj0hBMrtcErVQaxmq
+xym0+soR4Tk4pTIGckeFglrLxkP2JpM/yTwSEAVlmG9vgTliYKyR0uMl
+-----END CERTIFICATE-----
+DOC
+ end
+
+ let(:valid_key) do
+ <<DOC
+-----BEGIN RSA PRIVATE KEY-----
+MIIEogIBAAKCAQEAz9bY/piKahD10AiJSfbI2A8NG5UwRz0r9T/WfvNVdhgrsGFg
+NQjvpUoZnNJpQIHBbgMOiXqfATFjJl5FjEkSf7GUHohlGVls9MX2JmVvknzsiitd
+75H/EJd+N+k915lix8Vqmj8d1CTlbF/8tEjzANI67Vqw5QTuqebO7rkIUvRg6yiR
+fSo75FK1RinCJyl++kmleBwQZBInQyg95GvJ5JTqMzBs67DeeyzskDhTeTePRYVF
+2NwL8QzYhtvLIBERTNsyU5i7nkxY5ptUwgFUwd93LH4Q19tPqL5C5RZqXxhE51th
+OOwafm+aW/cRkqYqV+tv+j1jJ3WICyF1JNW0BQIDAQABAoIBADAiZ/r+xP+vkd5u
+O61/lCBFzBlZQecdybJw6HJaVK6XBndA9hESUr4LHUdui6W+51ddKd65IV4bXAUk
+zCKjQb+FFvLDT/bA+TTvLATUdTSN7hJJ3OWBAHuNOlQklof6JCB0Hi4+89+P8/pX
+eKUgR/cmuTMDT/iaXdPHeqFbBQyA1ZpQFRjN5LyyJMS/9FkywuNc5wlpsArtc51T
+gIKENUZCuPhosR+kMFc2iuTNvqZWPhvouSrmhi2O6nSqV+oy0+irlqSpCF2GsCI8
+72TtLpq94Grrq0BEH5avouV+Lp4k83vO65OKCQKUFQlxz3Xkxm2U3J7KzxqnRtM3
+/b+cJ/kCgYEA6/yOnaEYhH/7ijhZbPn8RujXZ5VGJXKJqIuaPiHMmHVS5p1j6Bah
+2PcnqJA2IlLs3UloN+ziAxAIH6KCBiwlQ/uPBNMMaJsIjPNBEy8axjndKhKUpidg
+R0OJ7RQqMShOJ8akrSfWdPtXC/GBuwCYE//t77GgZaIMO3FcT9EKA48CgYEA4Xcx
+Fia0Jg9iyAhNmUOXI6hWcGENavMx01+x7XFhbnMjIKTZevFfTnTkrX6HyLXyGtMU
+gHOn+k4PE/purI4ARrKO8m5wYEKqSIt4dBMTkIXXirfQjXgfjR8E4T/aPe5fOFZo
+7OYuxLRtzmG1C2sW4txwKAKX1LaWcVx/RLSttSsCgYBbcj8Brk+F6OJcqYFdzXGJ
+OOlf5mSMVlopyg83THmwCqbZXtw8L6kAHqZrl5airmfDSJLuOQlMDoZXW+3u3mSC
+d5TwVahVUN57YDgzaumBLyMZDqIz0MZqVy23hTzkV64Rk9R0lR9xrYQJyMhw4sYL
+2f0mCTsSpzz+O+t9so+i2QKBgEC38gMlwPhb2kMI/x1LZYr6uzUu5qcYf+jowy4h
+KZKGwkKQj0zXFEB1FV8nvtpCP+irRmtIx6L13SYi8LnfWPzyLE4ynVdES5TfVAgd
+obQOdzx+XwL8xDHCAaiWp5K3ZeXKB/xYZnxYPlzLdyh76Ond1OPnOqX4c16+6llS
+c7pZAoGATd9NckT0XtXLEsF3IraDivq8dP6bccX2DNfS8UeEvRRrRwpFpSRrmuGb
+jbG4yzoIX4RjQfj/z48hwhJB+cKiN9WwcPsFXtHe7v3F6BRwK0JUfrCiXad8/SGZ
+KAf7Dfqi608zBdnPWHacre2Y35gPHB00nFQOLS6u46aBNSq07YA=
+-----END RSA PRIVATE KEY-----
+DOC
+ end
+
+ let(:another_valid_key) do
+ <<DOC
+-----BEGIN RSA PRIVATE KEY-----
+MIIEpAIBAAKCAQEAoISxYJBTPAeAzFnm+lE/ljLlmGal2Xr3vwZKkvJiuKA/m4QJ
+0ZNdtkBSDOVuG2dXVv6W4sChRtsCdvuVe7bjTYvlU8TWM3VEJDL9l9cRXScxxlKQ
+Xwb35y1yV35NJfaK/jzm9KcErtQQs1RxvGlWRaohmLM8uQcuhjZfMsSlQoHQD5LX
+sbPtk82RPyxYc1dj2vsaoi1VvuP2+jv4xLQOmNJY1bT5GTurqiltmxEtWhNNmGg0
+2wtK00ifqLVO5HNc3gXQCDM2M99Sbmn1YtbrgsU9xMYfcPmvQvb+YoKskyoqck+c
+HR//hi7vslbxABrny15LBkEfRc4TickphSGYXwIDAQABAoIBAATEzGw8/WwMIQRx
+K06GeWgh7PZBHm4+m/ud2TtSXiJ0CE+7dXs3cJJIiOd/LW08/bhE6gCkjmYHfaRB
+Ryicv1X/cPmzIFX5BuQ4a5ZGOmrVDkKBE27vSxAgJoR46RvWnjx9XLMp/xaekDxz
+psldK8X4DvV1ZbltgDFWji947hvyqUtHdKnkQnc5j7aCIFJf9GMfzaeeDPMaL8WF
+mVL4iy9EAOjNOHBshZj/OHyU5FbJ8ROwZQlCOiLCdFegftSIXt8EYDnjB3BdsALH
+N6hquqrD7xDKyRbTD0K7lqxUubuMwTQpi61jZD8TBTXEPyFVAnoMpXkc0Y+np40A
+YiIsR+kCgYEAyrc4Bh6fb9gt49IXGXOSRZ5i5+TmJho4kzIONrJ7Ndclwx9wzHfh
+eGBodWaw5CxxQGMf4vEiaZrpAiSFeDffBLR+Wa2TFE5aWkdYkR34maDjO00m4PE1
+S+YsZoGw7rGmmj+KS4qv2T26FEHtUI+F31RC1FPohLsQ22Jbn1ORipsCgYEAyrYB
+J2Ncf2DlX1C0GfxyUHQOTNl0V5gpGvpbZ0WmWksumYz2kSGOAJkxuDKd9mKVlAcz
+czmN+OOetuHTNqds2JJKKJy6hJbgCdd9aho3dId5Xs4oh4YwuFQiG8R/bJZfTlXo
+99Qr02L7MmDWYLmrR3BA/93UPeorHPtjqSaYU40CgYEAtmGfWwokIglaSDVVqQVs
+3YwBqmcrla5TpkMLvLRZ2/fktqfL4Xod9iKu+Klajv9ZKTfFkXWno2HHL7FSD/Yc
+hWwqnV5oDIXuDnlQOse/SeERb+IbD5iUfePpoJQgbrCQlwiB0TNGwOojR2SFMczf
+Ai4aLlQLx5dSND9K9Y7HS+8CgYEAixlHQ2r4LuQjoTs0ytwi6TgqE+vn3K+qDTwc
+eoods7oBWRaUn1RCKAD3UClToZ1WfMRQNtIYrOAsqdveXpOWqioAP0wE5TTOuZIo
+GiWxRgIsc7TNtOmNBv+chCdbNP0emxdyjJUIGb7DFnfCw47EjHnn8Guc13uXaATN
+B2ZXgoUCgYAGa13P0ggUf5BMJpBd8S08jKRyvZb1CDXcUCuGtk2yEx45ern9U5WY
+zJ13E5z9MKKO8nkGBqrRfjJa8Xhxk4HKNFuzHEet5lvNE7IKCF4YQRb0ZBhnb/78
++4ZKjFki1RrWRNSw9TdvrK6qaDKgTtCTtfRVXAYQXUgq7lSFOTtL3A==
+-----END RSA PRIVATE KEY-----
+DOC
+ end
+ # rubocop:enable Layout/IndentHeredoc
+
+ let(:valid_cert_but_indented) do
+ valid_cert.gsub(%r{^}, ' ')
+ end
+
+ let(:valid_key_but_indented) do
+ valid_key.gsub(%r{^}, ' ')
+ end
+
+ let(:malformed_cert) do
+ truncate_middle(valid_cert)
+ end
+
+ let(:malformed_key) do
+ truncate_middle(valid_key)
+ end
+
+ let(:bad_cert) do
+ 'foo'
+ end
+
+ let(:bad_key) do
+ 'bar'
+ end
+
+ context 'with function signature validation' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params(0, 1, 2, 3).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ end
+
+ context 'with valid input' do
+ describe 'valid certificate and key' do
+ it { is_expected.to run.with_params(valid_cert, valid_key) }
+ end
+ end
+
+ context 'with bad input' do
+ describe 'valid certificate, valid but indented key' do
+ it { is_expected.to run.with_params(valid_cert, valid_key_but_indented).and_raise_error(Puppet::ParseError, %r{Not a valid RSA key}) }
+ end
+
+ describe 'valid certificate, malformed key' do
+ it { is_expected.to run.with_params(valid_cert, malformed_key).and_raise_error(Puppet::ParseError, %r{Not a valid RSA key}) }
+ end
+
+ describe 'valid certificate, bad key' do
+ it { is_expected.to run.with_params(valid_cert, bad_key).and_raise_error(Puppet::ParseError, %r{Not a valid RSA key}) }
+ end
+
+ describe 'valid but indented certificate, valid key' do
+ it { is_expected.to run.with_params(valid_cert_but_indented, valid_key).and_raise_error(Puppet::ParseError, %r{Not a valid x509 certificate}) }
+ end
+
+ describe 'malformed certificate, valid key' do
+ it { is_expected.to run.with_params(malformed_cert, valid_key).and_raise_error(Puppet::ParseError, %r{Not a valid x509 certificate}) }
+ end
+
+ describe 'bad certificate, valid key' do
+ it { is_expected.to run.with_params(bad_cert, valid_key).and_raise_error(Puppet::ParseError, %r{Not a valid x509 certificate}) }
+ end
+
+ describe 'validate certificate and key; certficate not signed by key' do
+ it { is_expected.to run.with_params(valid_cert, another_valid_key).and_raise_error(Puppet::ParseError, %r{Certificate signature does not match supplied key}) }
+ end
+
+ describe 'valid cert and key but arguments in wrong order' do
+ it { is_expected.to run.with_params(valid_key, valid_cert).and_raise_error(Puppet::ParseError, %r{Not a valid x509 certificate}) }
+ end
+
+ describe 'non-string arguments' do
+ it { is_expected.to run.with_params({}, {}).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params(1, 1).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params(true, true).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params('foo', {}).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params(1, 'bar').and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ it { is_expected.to run.with_params('baz', true).and_raise_error(Puppet::ParseError, %r{is not a string}) }
+ end
+ end
+
+ def truncate_middle(string)
+ chars_to_truncate = 48
+ middle = (string.length / 2).floor
+ start_pos = middle - (chars_to_truncate / 2)
+ end_pos = middle + (chars_to_truncate / 2)
+
+ string[start_pos...end_pos] = ''
+ string
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/values_at_spec.rb b/code/environments/production/modules/stdlib/spec/functions/values_at_spec.rb
new file mode 100644
index 0000000..c405423
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/values_at_spec.rb
@@ -0,0 +1,54 @@
+require 'spec_helper'
+
+describe 'values_at' do
+ describe 'signature validation' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it {
+ pending('Current implementation ignores parameters after the first two.')
+ is_expected.to run.with_params([], 0, 1).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
+ }
+ it { is_expected.to run.with_params('', 1).and_raise_error(Puppet::ParseError, %r{Requires array}i) }
+ it { is_expected.to run.with_params({}, 1).and_raise_error(Puppet::ParseError, %r{Requires array}i) }
+ it { is_expected.to run.with_params(true, 1).and_raise_error(Puppet::ParseError, %r{Requires array}i) }
+ it { is_expected.to run.with_params(1, 1).and_raise_error(Puppet::ParseError, %r{Requires array}i) }
+ it { is_expected.to run.with_params([0, 1, 2], 'two').and_raise_error(Puppet::ParseError, %r{Unknown format of given index}) }
+ it { is_expected.to run.with_params([0, 1, 2], []).and_raise_error(Puppet::ParseError, %r{provide at least one positive index}) }
+ it { is_expected.to run.with_params([0, 1, 2], '-1-1').and_raise_error(Puppet::ParseError, %r{Unknown format of given index}) }
+ it { is_expected.to run.with_params([0, 1, 2], '2-1').and_raise_error(Puppet::ParseError, %r{Stop index in given indices range is smaller than the start index}) }
+ end
+
+ context 'when requesting a single item' do
+ it { is_expected.to run.with_params([0, 1, 2], -1).and_raise_error(Puppet::ParseError, %r{Unknown format of given index}) }
+ it { is_expected.to run.with_params([0, 1, 2], 0).and_return([0]) }
+ it { is_expected.to run.with_params([0, 1, 2], 1).and_return([1]) }
+ it { is_expected.to run.with_params([0, 1, 2], [1]).and_return([1]) }
+ it { is_expected.to run.with_params([0, 1, 2], '1').and_return([1]) }
+ it { is_expected.to run.with_params([0, 1, 2], '1-1').and_return([1]) }
+ it { is_expected.to run.with_params([0, 1, 2], 2).and_return([2]) }
+ it { is_expected.to run.with_params([0, 1, 2], 3).and_raise_error(Puppet::ParseError, %r{index exceeds array size}) }
+ end
+
+ context 'when requesting a single item using UTF8 and double byte characters' do
+ it { is_expected.to run.with_params(%w[ẩ β с ď], 0).and_return(['ẩ']) }
+ it { is_expected.to run.with_params(%w[文 字 の 値], 2).and_return(['の']) }
+ end
+
+ context 'when requesting multiple items' do
+ it { is_expected.to run.with_params([0, 1, 2], [1, -1]).and_raise_error(Puppet::ParseError, %r{Unknown format of given index}) }
+ it { is_expected.to run.with_params([0, 1, 2], [0, 2]).and_return([0, 2]) }
+ it { is_expected.to run.with_params([0, 1, 2], ['0-2', 1, 2]).and_return([0, 1, 2, 1, 2]) }
+ it { is_expected.to run.with_params([0, 1, 2], [3, 2]).and_raise_error(Puppet::ParseError, %r{index exceeds array size}) }
+
+ describe 'different range syntaxes' do
+ it { is_expected.to run.with_params([0, 1, 2], '0-2').and_return([0, 1, 2]) }
+ it { is_expected.to run.with_params([0, 1, 2], '0..2').and_return([0, 1, 2]) }
+ it { is_expected.to run.with_params([0, 1, 2], '0...2').and_return([0, 1]) }
+ it {
+ pending('fix this bounds check')
+ is_expected.to run.with_params([0, 1, 2], '0...3').and_return([0, 1, 2])
+ }
+ end
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/values_spec.rb b/code/environments/production/modules/stdlib/spec/functions/values_spec.rb
new file mode 100644
index 0000000..85554c6
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/values_spec.rb
@@ -0,0 +1,24 @@
+require 'spec_helper'
+
+describe 'values', :if => Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it {
+ pending('Current implementation ignores parameters after the first.')
+ is_expected.to run.with_params({}, 'extra').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
+ }
+ it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) }
+ it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) }
+ it { is_expected.to run.with_params({}).and_return([]) }
+ it { is_expected.to run.with_params('key' => 'value').and_return(['value']) }
+ it 'returns the array of values' do
+ result = subject.call([{ 'key1' => 'value1', 'key2' => 'value2', 'duplicate_value_key' => 'value2' }])
+ expect(result).to match_array(%w[value1 value2 value2])
+ end
+
+ it 'runs with UTF8 and double byte characters' do
+ result = subject.call([{ 'かぎ' => '使用', 'ҝĕұ' => '√ẩŀứệ', 'ҝĕұďŭрļǐçằťè' => '√ẩŀứệ' }])
+ expect(result).to match_array(['使用', '√ẩŀứệ', '√ẩŀứệ'])
+ end
+end
diff --git a/code/environments/production/modules/stdlib/spec/functions/zip_spec.rb b/code/environments/production/modules/stdlib/spec/functions/zip_spec.rb
new file mode 100644
index 0000000..2cc8c0c
--- /dev/null
+++ b/code/environments/production/modules/stdlib/spec/functions/zip_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe 'zip' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
+ it {
+ pending('Current implementation ignores parameters after the third.')
+ is_expected.to run.with_params([], [], true, []).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
+ }
+ it { is_expected.to run.with_params([], []).and_return([]) }
+ it { is_expected.to run.with_params([1, 2, 3], [4, 5, 6]).and_return([[1, 4], [2, 5], [3, 6]]) }
+ it { is_expected.to run.with_params([1, 2, 3], [4, 5, 6], false).and_return([[1, 4], [2, 5], [3, 6]]) }
+ it { is_expected.to run.with_params([1, 2, 3], [4, 5, 6], true).and_return([1, 4, 2, 5, 3, 6]) }
+
+ context 'with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params(%w[ầ ь ć], %w[đ ề ƒ]).and_return([%w[ầ đ], %w[ь ề], %w[ć ƒ]]) }
+ it { is_expected.to run.with_params(%w[ペ 含 値], %w[ッ 文 イ]).and_return([%w[ペ ッ], %w[含 文], %w[値 イ]]) }
+ end
+end