From d3cd028b90bcfea0cd3ca19662019053f5fed7cc Mon Sep 17 00:00:00 2001 From: Ben Ford Date: Sat, 4 Jan 2020 00:51:11 -0800 Subject: [PATCH] Porting functions to the modern Puppet 4.x API --- lib/puppet/functions/access.rb | 62 +++++++++++++++ .../apache_directories_custom_fragment.rb | 60 +++++++++++++++ lib/puppet/functions/array_true.rb | 77 +++++++++++++++++++ lib/puppet/functions/deep_merge.rb | 45 +++++++++++ lib/puppet/functions/hash_eval.rb | 52 +++++++++++++ lib/puppet/functions/hash_key_equals.rb | 63 +++++++++++++++ lib/puppet/functions/is_dir.rb | 52 +++++++++++++ lib/puppet/functions/merge_yaml.rb | 60 +++++++++++++++ lib/puppet/functions/to_string.rb | 46 +++++++++++ lib/puppet/functions/value_true.rb | 51 ++++++++++++ lib/puppet/functions/values_no_error.rb | 62 +++++++++++++++ spec/functions/_access_spec.rb | 41 ++++++++++ ...apache_directories_custom_fragment_spec.rb | 41 ++++++++++ spec/functions/_array_true_spec.rb | 41 ++++++++++ spec/functions/_deep_merge_spec.rb | 41 ++++++++++ spec/functions/_hash_eval_spec.rb | 41 ++++++++++ spec/functions/_hash_key_equals_spec.rb | 41 ++++++++++ spec/functions/_is_dir_spec.rb | 41 ++++++++++ spec/functions/_merge_yaml_spec.rb | 41 ++++++++++ spec/functions/_to_string_spec.rb | 41 ++++++++++ spec/functions/_value_true_spec.rb | 41 ++++++++++ spec/functions/_values_no_error_spec.rb | 41 ++++++++++ 22 files changed, 1081 insertions(+) create mode 100644 lib/puppet/functions/access.rb create mode 100644 lib/puppet/functions/apache_directories_custom_fragment.rb create mode 100644 lib/puppet/functions/array_true.rb create mode 100644 lib/puppet/functions/deep_merge.rb create mode 100644 lib/puppet/functions/hash_eval.rb create mode 100644 lib/puppet/functions/hash_key_equals.rb create mode 100644 lib/puppet/functions/is_dir.rb create mode 100644 lib/puppet/functions/merge_yaml.rb create mode 100644 lib/puppet/functions/to_string.rb create mode 100644 lib/puppet/functions/value_true.rb create mode 100644 lib/puppet/functions/values_no_error.rb create mode 100644 spec/functions/_access_spec.rb create mode 100644 spec/functions/_apache_directories_custom_fragment_spec.rb create mode 100644 spec/functions/_array_true_spec.rb create mode 100644 spec/functions/_deep_merge_spec.rb create mode 100644 spec/functions/_hash_eval_spec.rb create mode 100644 spec/functions/_hash_key_equals_spec.rb create mode 100644 spec/functions/_is_dir_spec.rb create mode 100644 spec/functions/_merge_yaml_spec.rb create mode 100644 spec/functions/_to_string_spec.rb create mode 100644 spec/functions/_value_true_spec.rb create mode 100644 spec/functions/_values_no_error_spec.rb diff --git a/lib/puppet/functions/access.rb b/lib/puppet/functions/access.rb new file mode 100644 index 0000000..46618c9 --- /dev/null +++ b/lib/puppet/functions/access.rb @@ -0,0 +1,62 @@ +# This is an autogenerated function, ported from the original legacy version. +# It /should work/ as is, but will not have all the benefits of the modern +# function API. You should see the function docs to learn how to add function +# signatures for type safety and to document this function using puppet-strings. +# +# https://puppet.com/docs/puppet/latest/custom_functions_ruby.html +# +# ---- original file header ---- +require "vine" + +# +# access.rb +# + +# ---- original file header ---- +# +# @summary +# +# Uses Vine gem to deep access hash/array keys +# +# +Puppet::Functions.create_function(:'access') do + # @param args + # The original array of arguments. Port this to individually managed params + # to get the full benefit of the modern function API. + # + # @return [Data type] + # Describe what the function returns here + # + dispatch :default_impl do + # Call the method named 'default_impl' when this is matched + # Port this to match individual params for better type safety + repeated_param 'Any', :args + end + + + def default_impl(*args) + + + unless (args.length == 2) || (args.length == 3) + raise Puppet::ParseError, ("access(): wrong number of arguments (#{args.length}; must be 2 or 3)") + end + + container = args[0] + + if (!container.is_a?(Hash)) && (!container.is_a?(Array)) + raise Puppet::ParseError, ("access(): expecting first parameter as Array or Hash, #{container.class} given") + end + + keys = args[1] + + default = (args[2].nil?) ? nil : args[2] + + if container.access(keys).class == NilClass + return default + end + + return container.access(keys) + + + end +end diff --git a/lib/puppet/functions/apache_directories_custom_fragment.rb b/lib/puppet/functions/apache_directories_custom_fragment.rb new file mode 100644 index 0000000..721d641 --- /dev/null +++ b/lib/puppet/functions/apache_directories_custom_fragment.rb @@ -0,0 +1,60 @@ +# This is an autogenerated function, ported from the original legacy version. +# It /should work/ as is, but will not have all the benefits of the modern +# function API. You should see the function docs to learn how to add function +# signatures for type safety and to document this function using puppet-strings. +# +# https://puppet.com/docs/puppet/latest/custom_functions_ruby.html +# +# ---- original file header ---- +# +# apache_directories_custom_fragment.rb +# + +# ---- original file header ---- +# +# @summary +# +# Takes 'directories' hash match puppet-apache vhosts requirement. Explodes custom_fragment list into +# \n separated string. +# +# +Puppet::Functions.create_function(:'apache_directories_custom_fragment') do + # @param args + # The original array of arguments. Port this to individually managed params + # to get the full benefit of the modern function API. + # + # @return [Data type] + # Describe what the function returns here + # + dispatch :default_impl do + # Call the method named 'default_impl' when this is matched + # Port this to match individual params for better type safety + repeated_param 'Any', :args + end + + + def default_impl(*args) + + + unless args.length == 1 + raise Puppet::ParseError, ("apache_directories_custom_fragment(): wrong number of arguments (#{args.length}; must be 1)") + end + + directories = args[0] + + unless directories.is_a?(Hash) + raise Puppet::ParseError, ("apache_directories_custom_fragment(): expects a hash)") + end + + directories.each do |index, directory| + next if !directory.key?('custom_fragment') + next if !directory['custom_fragment'].is_a?(Array) + + directories[index]['custom_fragment'] = directory['custom_fragment'].join("\n ") + end + + return directories + + + end +end diff --git a/lib/puppet/functions/array_true.rb b/lib/puppet/functions/array_true.rb new file mode 100644 index 0000000..142b8bf --- /dev/null +++ b/lib/puppet/functions/array_true.rb @@ -0,0 +1,77 @@ +# This is an autogenerated function, ported from the original legacy version. +# It /should work/ as is, but will not have all the benefits of the modern +# function API. You should see the function docs to learn how to add function +# signatures for type safety and to document this function using puppet-strings. +# +# https://puppet.com/docs/puppet/latest/custom_functions_ruby.html +# +# ---- original file header ---- +dir = File.dirname(File.expand_path(__FILE__)) +require "#{dir}/to_bool.rb" + +# +# array_true.rb +# + +# ---- original file header ---- +# +# @summary +# +# Returns true if value in array exists and is truthy +# +# +Puppet::Functions.create_function(:'array_true') do + # @param args + # The original array of arguments. Port this to individually managed params + # to get the full benefit of the modern function API. + # + # @return [Data type] + # Describe what the function returns here + # + dispatch :default_impl do + # Call the method named 'default_impl' when this is matched + # Port this to match individual params for better type safety + repeated_param 'Any', :args + end + + + def default_impl(*args) + + + unless args.length == 2 + raise Puppet::ParseError, ("array_true(): wrong number of arguments (#{args.length}; must be 2)") + end + + container = args[0] + + if (!container.is_a?(Hash)) && (!container.is_a?(Array)) + return false + end + + keys = (args[1].is_a?(Array)) ? args[1] : [args[1]] + + # If multiple values passed to check, + # all must pass truthyness check to return true + keys.each do |key| + if !container.has_key?(key) + return false + end + + if (container[key].is_a?(Hash)) || (container[key].is_a?(Array)) + if !(container[key].count > 0) + return false + end + + next + end + + if !(container[key].to_bool) + return false + end + end + + return true + + + end +end diff --git a/lib/puppet/functions/deep_merge.rb b/lib/puppet/functions/deep_merge.rb new file mode 100644 index 0000000..5765db5 --- /dev/null +++ b/lib/puppet/functions/deep_merge.rb @@ -0,0 +1,45 @@ +# This is an autogenerated function, ported from the original legacy version. +# It /should work/ as is, but will not have all the benefits of the modern +# function API. You should see the function docs to learn how to add function +# signatures for type safety and to document this function using puppet-strings. +# +# https://puppet.com/docs/puppet/latest/custom_functions_ruby.html +# +# ---- original file header ---- +require 'deep_merge' + +# ---- original file header ---- +# +# @summary +# Deep merges two hashes using Hash#deep_merge +# +# +Puppet::Functions.create_function(:'deep_merge') do + # @param args + # The original array of arguments. Port this to individually managed params + # to get the full benefit of the modern function API. + # + # @return [Data type] + # Describe what the function returns here + # + dispatch :default_impl do + # Call the method named 'default_impl' when this is matched + # Port this to match individual params for better type safety + repeated_param 'Any', :args + end + + + def default_impl(*args) + + + if args.length < 2 + raise Puppet::ParseError, ("deep_merge(): wrong number of arguments (#{args.length}; must be at least 2)") + end + + hashA = args[0] + hashB = args[1] + + return hashA.deep_merge!(hashB) + + end +end diff --git a/lib/puppet/functions/hash_eval.rb b/lib/puppet/functions/hash_eval.rb new file mode 100644 index 0000000..1302d24 --- /dev/null +++ b/lib/puppet/functions/hash_eval.rb @@ -0,0 +1,52 @@ +# This is an autogenerated function, ported from the original legacy version. +# It /should work/ as is, but will not have all the benefits of the modern +# function API. You should see the function docs to learn how to add function +# signatures for type safety and to document this function using puppet-strings. +# +# https://puppet.com/docs/puppet/latest/custom_functions_ruby.html +# +# ---- original file header ---- +# +# hash_eval.rb +# + +# ---- original file header ---- +# +# @summary +# +# Turns Hash#inspect string back to hash +# +# +Puppet::Functions.create_function(:'hash_eval') do + # @param args + # The original array of arguments. Port this to individually managed params + # to get the full benefit of the modern function API. + # + # @return [Data type] + # Describe what the function returns here + # + dispatch :default_impl do + # Call the method named 'default_impl' when this is matched + # Port this to match individual params for better type safety + repeated_param 'Any', :args + end + + + def default_impl(*args) + + + unless args.length == 1 + raise Puppet::ParseError, ("hash_eval(): wrong number of arguments (#{args.length}; must be 1)") + end + + hash_string = args[0] + + if (!hash_string.is_a?(String)) + raise Puppet::ParseError, ("hash_eval(): expects string representation of a hash)") + end + + return eval(hash_string) + + + end +end diff --git a/lib/puppet/functions/hash_key_equals.rb b/lib/puppet/functions/hash_key_equals.rb new file mode 100644 index 0000000..0d95e32 --- /dev/null +++ b/lib/puppet/functions/hash_key_equals.rb @@ -0,0 +1,63 @@ +# This is an autogenerated function, ported from the original legacy version. +# It /should work/ as is, but will not have all the benefits of the modern +# function API. You should see the function docs to learn how to add function +# signatures for type safety and to document this function using puppet-strings. +# +# https://puppet.com/docs/puppet/latest/custom_functions_ruby.html +# +# ---- original file header ---- +# +# hash_key_equals.rb +# + +# ---- original file header ---- +# +# @summary +# +# Returns true if the variable passed to this function is a hash, +# it contains the key requested, and the key matches value. +# +# +Puppet::Functions.create_function(:'hash_key_equals') do + # @param args + # The original array of arguments. Port this to individually managed params + # to get the full benefit of the modern function API. + # + # @return [Data type] + # Describe what the function returns here + # + dispatch :default_impl do + # Call the method named 'default_impl' when this is matched + # Port this to match individual params for better type safety + repeated_param 'Any', :args + end + + + def default_impl(*args) + + + unless args.length == 3 + raise Puppet::ParseError, ("hash_key_equals(): wrong number of arguments (#{args.length}; must be 3)") + end + + hashVar = args[0] + keyVar = args[1] + expectedValue = args[2] + + unless hashVar.is_a?(Hash) + return false + end + + unless hashVar.has_key?(keyVar) + return false + end + + unless hashVar[keyVar].to_i == expectedValue.to_i + return false + end + + return true + + + end +end diff --git a/lib/puppet/functions/is_dir.rb b/lib/puppet/functions/is_dir.rb new file mode 100644 index 0000000..93d63f7 --- /dev/null +++ b/lib/puppet/functions/is_dir.rb @@ -0,0 +1,52 @@ +# This is an autogenerated function, ported from the original legacy version. +# It /should work/ as is, but will not have all the benefits of the modern +# function API. You should see the function docs to learn how to add function +# signatures for type safety and to document this function using puppet-strings. +# +# https://puppet.com/docs/puppet/latest/custom_functions_ruby.html +# +# ---- original file header ---- +# +# is_dir.rb +# + +# ---- original file header ---- +# +# @summary +# +# Returns true if directory exists +# +# +Puppet::Functions.create_function(:'is_dir') do + # @param args + # The original array of arguments. Port this to individually managed params + # to get the full benefit of the modern function API. + # + # @return [Data type] + # Describe what the function returns here + # + dispatch :default_impl do + # Call the method named 'default_impl' when this is matched + # Port this to match individual params for better type safety + repeated_param 'Any', :args + end + + + def default_impl(*args) + + + unless args.length == 1 + raise Puppet::ParseError, ("is_dir(): wrong number of arguments (#{args.length}; must be 1)") + end + + value = args[0] + + if File.directory?(value) + return true + end + + return false + + + end +end diff --git a/lib/puppet/functions/merge_yaml.rb b/lib/puppet/functions/merge_yaml.rb new file mode 100644 index 0000000..8481311 --- /dev/null +++ b/lib/puppet/functions/merge_yaml.rb @@ -0,0 +1,60 @@ +# This is an autogenerated function, ported from the original legacy version. +# It /should work/ as is, but will not have all the benefits of the modern +# function API. You should see the function docs to learn how to add function +# signatures for type safety and to document this function using puppet-strings. +# +# https://puppet.com/docs/puppet/latest/custom_functions_ruby.html +# +# ---- original file header ---- +require 'yaml' +require 'deep_merge' + +# ---- original file header ---- +# +# @summary +# Deep merges two or more YAML files using Hash#deep_merge +# +# +Puppet::Functions.create_function(:'merge_yaml') do + # @param args + # The original array of arguments. Port this to individually managed params + # to get the full benefit of the modern function API. + # + # @return [Data type] + # Describe what the function returns here + # + dispatch :default_impl do + # Call the method named 'default_impl' when this is matched + # Port this to match individual params for better type safety + repeated_param 'Any', :args + end + + + def default_impl(*args) + + + if args.length < 2 + raise Puppet::ParseError, ("merge_yaml(): wrong number of arguments (#{args.length}; must be at least 2)") + end + + generatedHash = { } + + args.each do |value| + if (!value.is_a?(Array)) + if File.file?(value) + generatedHash.deep_merge!(YAML.load_file(value)) + end + else + value.each do |valueInner| + if File.file?(valueInner) + generatedHash.deep_merge!(YAML.load_file(valueInner)) + end + end + end + + end + + return generatedHash + + end +end diff --git a/lib/puppet/functions/to_string.rb b/lib/puppet/functions/to_string.rb new file mode 100644 index 0000000..b5a05c2 --- /dev/null +++ b/lib/puppet/functions/to_string.rb @@ -0,0 +1,46 @@ +# This is an autogenerated function, ported from the original legacy version. +# It /should work/ as is, but will not have all the benefits of the modern +# function API. You should see the function docs to learn how to add function +# signatures for type safety and to document this function using puppet-strings. +# +# https://puppet.com/docs/puppet/latest/custom_functions_ruby.html +# +# ---- original file header ---- +# +# to_string.rb +# + +# ---- original file header ---- +# +# @summary +# +# Casts value to string +# +# +Puppet::Functions.create_function(:'to_string') do + # @param args + # The original array of arguments. Port this to individually managed params + # to get the full benefit of the modern function API. + # + # @return [Data type] + # Describe what the function returns here + # + dispatch :default_impl do + # Call the method named 'default_impl' when this is matched + # Port this to match individual params for better type safety + repeated_param 'Any', :args + end + + + def default_impl(*args) + + + unless args.length == 1 + raise Puppet::ParseError, ("to_string(): wrong number of arguments (#{args.length}; must be 1)") + end + + return args[0].to_s + + + end +end diff --git a/lib/puppet/functions/value_true.rb b/lib/puppet/functions/value_true.rb new file mode 100644 index 0000000..ee3a6da --- /dev/null +++ b/lib/puppet/functions/value_true.rb @@ -0,0 +1,51 @@ +# This is an autogenerated function, ported from the original legacy version. +# It /should work/ as is, but will not have all the benefits of the modern +# function API. You should see the function docs to learn how to add function +# signatures for type safety and to document this function using puppet-strings. +# +# https://puppet.com/docs/puppet/latest/custom_functions_ruby.html +# +# ---- original file header ---- +dir = File.dirname(File.expand_path(__FILE__)) +require "#{dir}/to_bool.rb" + +# +# value_true.rb +# + +# ---- original file header ---- +# +# @summary +# +# Returns true if value is truthy +# +# +Puppet::Functions.create_function(:'value_true') do + # @param args + # The original array of arguments. Port this to individually managed params + # to get the full benefit of the modern function API. + # + # @return [Data type] + # Describe what the function returns here + # + dispatch :default_impl do + # Call the method named 'default_impl' when this is matched + # Port this to match individual params for better type safety + repeated_param 'Any', :args + end + + + def default_impl(*args) + + + unless args.length == 1 + raise Puppet::ParseError, ("value_true(): wrong number of arguments (#{args.length}; must be 1)") + end + + value = args[0] + + return value.to_bool + + + end +end diff --git a/lib/puppet/functions/values_no_error.rb b/lib/puppet/functions/values_no_error.rb new file mode 100644 index 0000000..07394e2 --- /dev/null +++ b/lib/puppet/functions/values_no_error.rb @@ -0,0 +1,62 @@ +# This is an autogenerated function, ported from the original legacy version. +# It /should work/ as is, but will not have all the benefits of the modern +# function API. You should see the function docs to learn how to add function +# signatures for type safety and to document this function using puppet-strings. +# +# https://puppet.com/docs/puppet/latest/custom_functions_ruby.html +# +# ---- original file header ---- +# +# values_no_error.rb +# + +# ---- original file header ---- +# +# @summary +# +#When given a hash this function will return the values of that hash. +#*Examples:* +# $hash = { +# 'a' => 1, +# 'b' => 2, +# 'c' => 3, +# } +# values_no_error($hash) +#This example would return: +# [1,2,3] +# +# +Puppet::Functions.create_function(:'values_no_error') do + # @param args + # The original array of arguments. Port this to individually managed params + # to get the full benefit of the modern function API. + # + # @return [Data type] + # Describe what the function returns here + # + dispatch :default_impl do + # Call the method named 'default_impl' when this is matched + # Port this to match individual params for better type safety + repeated_param 'Any', :args + end + + + def default_impl(*args) + + + unless args.length == 1 + raise Puppet::ParseError, ("values_no_error(): wrong number of arguments (#{args.length}; must be 1)") + end + + hash = args[0] + + unless hash.is_a?(Hash) + return false + end + + result = hash.values + + return result + + end +end diff --git a/spec/functions/_access_spec.rb b/spec/functions/_access_spec.rb new file mode 100644 index 0000000..10de26d --- /dev/null +++ b/spec/functions/_access_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe 'access' do + # without knowing details about the implementation, this is the only test + # case that we can autogenerate. You should add more examples below! + it { is_expected.not_to eq(nil) } + +################################# +# Below are some example test cases. You may uncomment and modify them to match +# your needs. Notice that they all expect the base error class of `StandardError`. +# This is because the autogenerated function uses an untyped array for parameters +# and relies on your implementation to do the validation. As you convert your +# function to proper dispatches and typed signatures, you should change the +# expected error of the argument validation examples to `ArgumentError`. +# +# Other error types you might encounter include +# +# * StandardError +# * ArgumentError +# * Puppet::ParseError +# +# Read more about writing function unit tests at https://rspec-puppet.com/documentation/functions/ +# +# it 'raises an error if called with no argument' do +# is_expected.to run.with_params.and_raise_error(StandardError) +# end +# +# it 'raises an error if there is more than 1 arguments' do +# is_expected.to run.with_params({ 'foo' => 1 }, 'bar' => 2).and_raise_error(StandardError) +# end +# +# it 'raises an error if argument is not the proper type' do +# is_expected.to run.with_params('foo').and_raise_error(StandardError) +# end +# +# it 'returns the proper output' do +# is_expected.to run.with_params(123).and_return('the expected output') +# end +################################# + +end diff --git a/spec/functions/_apache_directories_custom_fragment_spec.rb b/spec/functions/_apache_directories_custom_fragment_spec.rb new file mode 100644 index 0000000..08e7b05 --- /dev/null +++ b/spec/functions/_apache_directories_custom_fragment_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe 'apache_directories_custom_fragment' do + # without knowing details about the implementation, this is the only test + # case that we can autogenerate. You should add more examples below! + it { is_expected.not_to eq(nil) } + +################################# +# Below are some example test cases. You may uncomment and modify them to match +# your needs. Notice that they all expect the base error class of `StandardError`. +# This is because the autogenerated function uses an untyped array for parameters +# and relies on your implementation to do the validation. As you convert your +# function to proper dispatches and typed signatures, you should change the +# expected error of the argument validation examples to `ArgumentError`. +# +# Other error types you might encounter include +# +# * StandardError +# * ArgumentError +# * Puppet::ParseError +# +# Read more about writing function unit tests at https://rspec-puppet.com/documentation/functions/ +# +# it 'raises an error if called with no argument' do +# is_expected.to run.with_params.and_raise_error(StandardError) +# end +# +# it 'raises an error if there is more than 1 arguments' do +# is_expected.to run.with_params({ 'foo' => 1 }, 'bar' => 2).and_raise_error(StandardError) +# end +# +# it 'raises an error if argument is not the proper type' do +# is_expected.to run.with_params('foo').and_raise_error(StandardError) +# end +# +# it 'returns the proper output' do +# is_expected.to run.with_params(123).and_return('the expected output') +# end +################################# + +end diff --git a/spec/functions/_array_true_spec.rb b/spec/functions/_array_true_spec.rb new file mode 100644 index 0000000..f891006 --- /dev/null +++ b/spec/functions/_array_true_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe 'array_true' do + # without knowing details about the implementation, this is the only test + # case that we can autogenerate. You should add more examples below! + it { is_expected.not_to eq(nil) } + +################################# +# Below are some example test cases. You may uncomment and modify them to match +# your needs. Notice that they all expect the base error class of `StandardError`. +# This is because the autogenerated function uses an untyped array for parameters +# and relies on your implementation to do the validation. As you convert your +# function to proper dispatches and typed signatures, you should change the +# expected error of the argument validation examples to `ArgumentError`. +# +# Other error types you might encounter include +# +# * StandardError +# * ArgumentError +# * Puppet::ParseError +# +# Read more about writing function unit tests at https://rspec-puppet.com/documentation/functions/ +# +# it 'raises an error if called with no argument' do +# is_expected.to run.with_params.and_raise_error(StandardError) +# end +# +# it 'raises an error if there is more than 1 arguments' do +# is_expected.to run.with_params({ 'foo' => 1 }, 'bar' => 2).and_raise_error(StandardError) +# end +# +# it 'raises an error if argument is not the proper type' do +# is_expected.to run.with_params('foo').and_raise_error(StandardError) +# end +# +# it 'returns the proper output' do +# is_expected.to run.with_params(123).and_return('the expected output') +# end +################################# + +end diff --git a/spec/functions/_deep_merge_spec.rb b/spec/functions/_deep_merge_spec.rb new file mode 100644 index 0000000..55245b7 --- /dev/null +++ b/spec/functions/_deep_merge_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe 'deep_merge' do + # without knowing details about the implementation, this is the only test + # case that we can autogenerate. You should add more examples below! + it { is_expected.not_to eq(nil) } + +################################# +# Below are some example test cases. You may uncomment and modify them to match +# your needs. Notice that they all expect the base error class of `StandardError`. +# This is because the autogenerated function uses an untyped array for parameters +# and relies on your implementation to do the validation. As you convert your +# function to proper dispatches and typed signatures, you should change the +# expected error of the argument validation examples to `ArgumentError`. +# +# Other error types you might encounter include +# +# * StandardError +# * ArgumentError +# * Puppet::ParseError +# +# Read more about writing function unit tests at https://rspec-puppet.com/documentation/functions/ +# +# it 'raises an error if called with no argument' do +# is_expected.to run.with_params.and_raise_error(StandardError) +# end +# +# it 'raises an error if there is more than 1 arguments' do +# is_expected.to run.with_params({ 'foo' => 1 }, 'bar' => 2).and_raise_error(StandardError) +# end +# +# it 'raises an error if argument is not the proper type' do +# is_expected.to run.with_params('foo').and_raise_error(StandardError) +# end +# +# it 'returns the proper output' do +# is_expected.to run.with_params(123).and_return('the expected output') +# end +################################# + +end diff --git a/spec/functions/_hash_eval_spec.rb b/spec/functions/_hash_eval_spec.rb new file mode 100644 index 0000000..cddec42 --- /dev/null +++ b/spec/functions/_hash_eval_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe 'hash_eval' do + # without knowing details about the implementation, this is the only test + # case that we can autogenerate. You should add more examples below! + it { is_expected.not_to eq(nil) } + +################################# +# Below are some example test cases. You may uncomment and modify them to match +# your needs. Notice that they all expect the base error class of `StandardError`. +# This is because the autogenerated function uses an untyped array for parameters +# and relies on your implementation to do the validation. As you convert your +# function to proper dispatches and typed signatures, you should change the +# expected error of the argument validation examples to `ArgumentError`. +# +# Other error types you might encounter include +# +# * StandardError +# * ArgumentError +# * Puppet::ParseError +# +# Read more about writing function unit tests at https://rspec-puppet.com/documentation/functions/ +# +# it 'raises an error if called with no argument' do +# is_expected.to run.with_params.and_raise_error(StandardError) +# end +# +# it 'raises an error if there is more than 1 arguments' do +# is_expected.to run.with_params({ 'foo' => 1 }, 'bar' => 2).and_raise_error(StandardError) +# end +# +# it 'raises an error if argument is not the proper type' do +# is_expected.to run.with_params('foo').and_raise_error(StandardError) +# end +# +# it 'returns the proper output' do +# is_expected.to run.with_params(123).and_return('the expected output') +# end +################################# + +end diff --git a/spec/functions/_hash_key_equals_spec.rb b/spec/functions/_hash_key_equals_spec.rb new file mode 100644 index 0000000..6bb95a7 --- /dev/null +++ b/spec/functions/_hash_key_equals_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe 'hash_key_equals' do + # without knowing details about the implementation, this is the only test + # case that we can autogenerate. You should add more examples below! + it { is_expected.not_to eq(nil) } + +################################# +# Below are some example test cases. You may uncomment and modify them to match +# your needs. Notice that they all expect the base error class of `StandardError`. +# This is because the autogenerated function uses an untyped array for parameters +# and relies on your implementation to do the validation. As you convert your +# function to proper dispatches and typed signatures, you should change the +# expected error of the argument validation examples to `ArgumentError`. +# +# Other error types you might encounter include +# +# * StandardError +# * ArgumentError +# * Puppet::ParseError +# +# Read more about writing function unit tests at https://rspec-puppet.com/documentation/functions/ +# +# it 'raises an error if called with no argument' do +# is_expected.to run.with_params.and_raise_error(StandardError) +# end +# +# it 'raises an error if there is more than 1 arguments' do +# is_expected.to run.with_params({ 'foo' => 1 }, 'bar' => 2).and_raise_error(StandardError) +# end +# +# it 'raises an error if argument is not the proper type' do +# is_expected.to run.with_params('foo').and_raise_error(StandardError) +# end +# +# it 'returns the proper output' do +# is_expected.to run.with_params(123).and_return('the expected output') +# end +################################# + +end diff --git a/spec/functions/_is_dir_spec.rb b/spec/functions/_is_dir_spec.rb new file mode 100644 index 0000000..073144f --- /dev/null +++ b/spec/functions/_is_dir_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe 'is_dir' do + # without knowing details about the implementation, this is the only test + # case that we can autogenerate. You should add more examples below! + it { is_expected.not_to eq(nil) } + +################################# +# Below are some example test cases. You may uncomment and modify them to match +# your needs. Notice that they all expect the base error class of `StandardError`. +# This is because the autogenerated function uses an untyped array for parameters +# and relies on your implementation to do the validation. As you convert your +# function to proper dispatches and typed signatures, you should change the +# expected error of the argument validation examples to `ArgumentError`. +# +# Other error types you might encounter include +# +# * StandardError +# * ArgumentError +# * Puppet::ParseError +# +# Read more about writing function unit tests at https://rspec-puppet.com/documentation/functions/ +# +# it 'raises an error if called with no argument' do +# is_expected.to run.with_params.and_raise_error(StandardError) +# end +# +# it 'raises an error if there is more than 1 arguments' do +# is_expected.to run.with_params({ 'foo' => 1 }, 'bar' => 2).and_raise_error(StandardError) +# end +# +# it 'raises an error if argument is not the proper type' do +# is_expected.to run.with_params('foo').and_raise_error(StandardError) +# end +# +# it 'returns the proper output' do +# is_expected.to run.with_params(123).and_return('the expected output') +# end +################################# + +end diff --git a/spec/functions/_merge_yaml_spec.rb b/spec/functions/_merge_yaml_spec.rb new file mode 100644 index 0000000..004a79d --- /dev/null +++ b/spec/functions/_merge_yaml_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe 'merge_yaml' do + # without knowing details about the implementation, this is the only test + # case that we can autogenerate. You should add more examples below! + it { is_expected.not_to eq(nil) } + +################################# +# Below are some example test cases. You may uncomment and modify them to match +# your needs. Notice that they all expect the base error class of `StandardError`. +# This is because the autogenerated function uses an untyped array for parameters +# and relies on your implementation to do the validation. As you convert your +# function to proper dispatches and typed signatures, you should change the +# expected error of the argument validation examples to `ArgumentError`. +# +# Other error types you might encounter include +# +# * StandardError +# * ArgumentError +# * Puppet::ParseError +# +# Read more about writing function unit tests at https://rspec-puppet.com/documentation/functions/ +# +# it 'raises an error if called with no argument' do +# is_expected.to run.with_params.and_raise_error(StandardError) +# end +# +# it 'raises an error if there is more than 1 arguments' do +# is_expected.to run.with_params({ 'foo' => 1 }, 'bar' => 2).and_raise_error(StandardError) +# end +# +# it 'raises an error if argument is not the proper type' do +# is_expected.to run.with_params('foo').and_raise_error(StandardError) +# end +# +# it 'returns the proper output' do +# is_expected.to run.with_params(123).and_return('the expected output') +# end +################################# + +end diff --git a/spec/functions/_to_string_spec.rb b/spec/functions/_to_string_spec.rb new file mode 100644 index 0000000..e6ce523 --- /dev/null +++ b/spec/functions/_to_string_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe 'to_string' do + # without knowing details about the implementation, this is the only test + # case that we can autogenerate. You should add more examples below! + it { is_expected.not_to eq(nil) } + +################################# +# Below are some example test cases. You may uncomment and modify them to match +# your needs. Notice that they all expect the base error class of `StandardError`. +# This is because the autogenerated function uses an untyped array for parameters +# and relies on your implementation to do the validation. As you convert your +# function to proper dispatches and typed signatures, you should change the +# expected error of the argument validation examples to `ArgumentError`. +# +# Other error types you might encounter include +# +# * StandardError +# * ArgumentError +# * Puppet::ParseError +# +# Read more about writing function unit tests at https://rspec-puppet.com/documentation/functions/ +# +# it 'raises an error if called with no argument' do +# is_expected.to run.with_params.and_raise_error(StandardError) +# end +# +# it 'raises an error if there is more than 1 arguments' do +# is_expected.to run.with_params({ 'foo' => 1 }, 'bar' => 2).and_raise_error(StandardError) +# end +# +# it 'raises an error if argument is not the proper type' do +# is_expected.to run.with_params('foo').and_raise_error(StandardError) +# end +# +# it 'returns the proper output' do +# is_expected.to run.with_params(123).and_return('the expected output') +# end +################################# + +end diff --git a/spec/functions/_value_true_spec.rb b/spec/functions/_value_true_spec.rb new file mode 100644 index 0000000..37b04e2 --- /dev/null +++ b/spec/functions/_value_true_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe 'value_true' do + # without knowing details about the implementation, this is the only test + # case that we can autogenerate. You should add more examples below! + it { is_expected.not_to eq(nil) } + +################################# +# Below are some example test cases. You may uncomment and modify them to match +# your needs. Notice that they all expect the base error class of `StandardError`. +# This is because the autogenerated function uses an untyped array for parameters +# and relies on your implementation to do the validation. As you convert your +# function to proper dispatches and typed signatures, you should change the +# expected error of the argument validation examples to `ArgumentError`. +# +# Other error types you might encounter include +# +# * StandardError +# * ArgumentError +# * Puppet::ParseError +# +# Read more about writing function unit tests at https://rspec-puppet.com/documentation/functions/ +# +# it 'raises an error if called with no argument' do +# is_expected.to run.with_params.and_raise_error(StandardError) +# end +# +# it 'raises an error if there is more than 1 arguments' do +# is_expected.to run.with_params({ 'foo' => 1 }, 'bar' => 2).and_raise_error(StandardError) +# end +# +# it 'raises an error if argument is not the proper type' do +# is_expected.to run.with_params('foo').and_raise_error(StandardError) +# end +# +# it 'returns the proper output' do +# is_expected.to run.with_params(123).and_return('the expected output') +# end +################################# + +end diff --git a/spec/functions/_values_no_error_spec.rb b/spec/functions/_values_no_error_spec.rb new file mode 100644 index 0000000..c2839da --- /dev/null +++ b/spec/functions/_values_no_error_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe 'values_no_error' do + # without knowing details about the implementation, this is the only test + # case that we can autogenerate. You should add more examples below! + it { is_expected.not_to eq(nil) } + +################################# +# Below are some example test cases. You may uncomment and modify them to match +# your needs. Notice that they all expect the base error class of `StandardError`. +# This is because the autogenerated function uses an untyped array for parameters +# and relies on your implementation to do the validation. As you convert your +# function to proper dispatches and typed signatures, you should change the +# expected error of the argument validation examples to `ArgumentError`. +# +# Other error types you might encounter include +# +# * StandardError +# * ArgumentError +# * Puppet::ParseError +# +# Read more about writing function unit tests at https://rspec-puppet.com/documentation/functions/ +# +# it 'raises an error if called with no argument' do +# is_expected.to run.with_params.and_raise_error(StandardError) +# end +# +# it 'raises an error if there is more than 1 arguments' do +# is_expected.to run.with_params({ 'foo' => 1 }, 'bar' => 2).and_raise_error(StandardError) +# end +# +# it 'raises an error if argument is not the proper type' do +# is_expected.to run.with_params('foo').and_raise_error(StandardError) +# end +# +# it 'returns the proper output' do +# is_expected.to run.with_params(123).and_return('the expected output') +# end +################################# + +end