diff --git a/lib/puppet/functions/stdlib/abs.rb b/lib/puppet/functions/stdlib/abs.rb new file mode 100644 index 000000000..51985beec --- /dev/null +++ b/lib/puppet/functions/stdlib/abs.rb @@ -0,0 +1,64 @@ +# 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 ---- +# +# abs.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated:** Returns the absolute value of a number +# +# For example -34.56 becomes 34.56. +# Takes a single integer or float value as an argument. +# +# > *Note:* +# **Deprected** from Puppet 6.0.0, the built-in +# ['abs'](https://puppet.com/docs/puppet/6.4/function.html#abs)function will be used instead. +# +# @return The absolute value of the given number if it was an Integer +# +# +# +Puppet::Functions.create_function(:'stdlib::abs') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "abs(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + + value = arguments[0] + + # Numbers in Puppet are often string-encoded which is troublesome ... + if value.is_a?(String) + if value =~ %r{^-?(?:\d+)(?:\.\d+){1}$} + value = value.to_f + elsif value =~ %r{^-?\d+$} + value = value.to_i + else + raise(Puppet::ParseError, 'abs(): Requires float or integer to work with') + end + end + + # We have numeric value to handle ... + result = value.abs + + result + end +end diff --git a/lib/puppet/functions/stdlib/any2array.rb b/lib/puppet/functions/stdlib/any2array.rb new file mode 100644 index 000000000..21109a153 --- /dev/null +++ b/lib/puppet/functions/stdlib/any2array.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 ---- +# +# any2array.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# This converts any object to an array containing that object. +# +# Empty argument lists are converted to an empty array. Arrays are left +# untouched. Hashes are converted to arrays of alternating keys and values. +# +# > *Note:* +# since Puppet 5.0.0 it is possible to create new data types for almost any +# datatype using the type system and the built-in +# [`Array.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-array-and-tuple) +# function is used to create a new Array.. +# +# ``` +# $hsh = {'key' => 42, 'another-key' => 100} +# notice(Array($hsh)) +# ``` +# +# Would notice `[['key', 42], ['another-key', 100]]` +# +# The Array data type also has a special mode to "create an array if not already an array" +# +# ``` +# notice(Array({'key' => 42, 'another-key' => 100}, true)) +# ``` +# +# Would notice `[{'key' => 42, 'another-key' => 100}]`, as the `true` flag prevents the hash from being +# transformed into an array. +# +# @return [Array] The new array containing the given object +# +# +Puppet::Functions.create_function(:'stdlib::any2array') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + if arguments.empty? + return [] + end + + return arguments unless arguments.length == 1 + return arguments[0] if arguments[0].is_a?(Array) + return [] if arguments == [''] + if arguments[0].is_a?(Hash) + result = [] + arguments[0].each do |key, value| + result << key << value + end + return result + end + arguments + end +end diff --git a/lib/puppet/functions/stdlib/any2bool.rb b/lib/puppet/functions/stdlib/any2bool.rb new file mode 100644 index 000000000..f78b26a18 --- /dev/null +++ b/lib/puppet/functions/stdlib/any2bool.rb @@ -0,0 +1,81 @@ +# 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 ---- +# +# any2bool.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Converts 'anything' to a boolean. +# +# In practise it does the following: +# * Strings such as Y,y,1,T,t,TRUE,yes,'true' will return true +# * Strings such as 0,F,f,N,n,FALSE,no,'false' will return false +# * Booleans will just return their original value +# * Number (or a string representation of a number) > 0 will return true, otherwise false +# * undef will return false +# * Anything else will return true +# +# Also see the built-in [`Boolean.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-boolean) +# function. +# +# @return [Boolean] The boolean value of the object that was given +# +# +Puppet::Functions.create_function(:'stdlib::any2bool') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "any2bool(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + + # If argument is already Boolean, return it + if !!arguments[0] == arguments[0] # rubocop:disable Style/DoubleNegation : Could not find a better way to check if a boolean + return arguments[0] + end + + arg = arguments[0] + + if arg.nil? + return false + end + + if arg == :undef + return false + end + + valid_float = begin + !!Float(arg) # rubocop:disable Style/DoubleNegation : Could not find a better way to check if a boolean + rescue + false + end + + if arg.is_a?(Numeric) + return function_num2bool([arguments[0]]) + end + + if arg.is_a?(String) + return function_num2bool([arguments[0]]) if valid_float + return function_str2bool([arguments[0]]) + end + + true + end +end diff --git a/lib/puppet/functions/stdlib/assert_private.rb b/lib/puppet/functions/stdlib/assert_private.rb new file mode 100644 index 000000000..014f9cf1f --- /dev/null +++ b/lib/puppet/functions/stdlib/assert_private.rb @@ -0,0 +1,55 @@ +# 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 ---- +# +# assert_private.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Sets the current class or definition as private. +# +# @return +# set the current class or definition as private. +# +# Calling the class or definition from outside the current module will fail. +# +# +Puppet::Functions.create_function(:'stdlib::assert_private') 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) + raise(Puppet::ParseError, "assert_private(): Wrong number of arguments given (#{args.size}}) for 0 or 1)") if args.size > 1 + + scope = self + return unless scope.lookupvar('module_name') != scope.lookupvar('caller_module_name') + + message = nil + if args[0] && args[0].is_a?(String) + message = args[0] + else + manifest_name = scope.source.name + manifest_type = scope.source.type + message = (manifest_type.to_s == 'hostclass') ? 'Class' : 'Definition' + message += " #{manifest_name} is private" + end + raise(Puppet::ParseError, message) + end +end diff --git a/lib/puppet/functions/stdlib/base64.rb b/lib/puppet/functions/stdlib/base64.rb new file mode 100644 index 000000000..c987207f0 --- /dev/null +++ b/lib/puppet/functions/stdlib/base64.rb @@ -0,0 +1,109 @@ +# 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 ---- +# Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. +# ---- original file header ---- +# +# @summary +# @summary +# Base64 encode or decode a string based on the command and the string submitted +# +# @example Example usage +# +# Encode and decode a string +# +# $encodestring = base64('encode', 'thestring') +# $decodestring = base64('decode', 'dGhlc3RyaW5n') +# +# Explicitly define encode/decode method: default, strict, urlsafe +# +# $method = 'default' +# $encodestring = base64('encode', 'thestring', $method) +# $decodestring = base64('decode', 'dGhlc3RyaW5n', $method) +# +# Encode a string as if it was binary +# +# $encodestring = String(Binary('thestring', '%s')) +# +# Decode a Binary assuming it is an UTF-8 String +# +# $decodestring = String(Binary("dGhlc3RyaW5n"), "%s") +# +# > **Note:* +# Since Puppet 4.8.0, the Binary data type can be used to produce base 64 encoded strings. +# See the `new()` function for the Binary and String types for documentation. Also see `binary_file()` +# function for reading a file with binary (non UTF-8) content. +# +# @return [String] The encoded/decoded value +# +# +Puppet::Functions.create_function(:'stdlib::base64') 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) + require 'base64' + + raise Puppet::ParseError, "base64(): Wrong number of arguments (#{args.length}; must be >= 2)" unless args.length >= 2 + + actions = ['encode', 'decode'] + + unless actions.include?(args[0]) + raise Puppet::ParseError, "base64(): the first argument must be one of 'encode' or 'decode'" + end + + unless args[1].is_a?(String) + raise Puppet::ParseError, 'base64(): the second argument must be a string to base64' + end + + method = ['default', 'strict', 'urlsafe'] + + chosen_method = if args.length <= 2 + 'default' + else + args[2] + end + + unless method.include?(chosen_method) + raise Puppet::ParseError, "base64(): the third argument must be one of 'default', 'strict', or 'urlsafe'" + end + + case args[0] + when 'encode' + case chosen_method + when 'default' + result = Base64.encode64(args[1]) + when 'strict' + result = Base64.strict_encode64(args[1]) + when 'urlsafe' + result = Base64.urlsafe_encode64(args[1]) + end + when 'decode' + case chosen_method + when 'default' + result = Base64.decode64(args[1]) + when 'strict' + result = Base64.strict_decode64(args[1]) + when 'urlsafe' + result = Base64.urlsafe_decode64(args[1]) + end + end + + result + end +end diff --git a/lib/puppet/functions/stdlib/basename.rb b/lib/puppet/functions/stdlib/basename.rb new file mode 100644 index 000000000..040a88d70 --- /dev/null +++ b/lib/puppet/functions/stdlib/basename.rb @@ -0,0 +1,48 @@ +# 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 ---- +# +# basename.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Strips directory (and optional suffix) from a filename +# +# @return [String] The stripped filename +# +# +Puppet::Functions.create_function(:'stdlib::basename') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, 'basename(): No arguments given') if arguments.empty? + raise(Puppet::ParseError, "basename(): Too many arguments given (#{arguments.size})") if arguments.size > 2 + raise(Puppet::ParseError, 'basename(): Requires string as first argument') unless arguments[0].is_a?(String) + + rv = File.basename(arguments[0]) if arguments.size == 1 + if arguments.size == 2 + raise(Puppet::ParseError, 'basename(): Requires string as second argument') unless arguments[1].is_a?(String) + rv = File.basename(arguments[0], arguments[1]) + end + + rv + end +end diff --git a/lib/puppet/functions/stdlib/bool2num.rb b/lib/puppet/functions/stdlib/bool2num.rb new file mode 100644 index 000000000..952d98b7e --- /dev/null +++ b/lib/puppet/functions/stdlib/bool2num.rb @@ -0,0 +1,64 @@ +# 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 ---- +# +# bool2num.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Converts a boolean to a number. +# +# Converts the values: +# ``` +# false, f, 0, n, and no to 0 +# true, t, 1, y, and yes to 1 +# ``` +# Requires a single boolean or string as an input. +# +# > *Note:* +# since Puppet 5.0.0 it is possible to create new data types for almost any +# datatype using the type system and the built-in +# [`Numeric.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-numeric), +# [`Integer.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-integer), and +# [`Float.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-float) +# function are used to convert to numeric values. +# ``` +# notice(Integer(false)) # Notices 0 +# notice(Float(true)) # Notices 1.0 +# ``` +# +# @return [Integer] The converted value as a number +# +# +Puppet::Functions.create_function(:'stdlib::bool2num') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "bool2num(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + + value = function_str2bool([arguments[0]]) + + # We have real boolean values as well ... + result = value ? 1 : 0 + + result + end +end diff --git a/lib/puppet/functions/stdlib/bool2str.rb b/lib/puppet/functions/stdlib/bool2str.rb new file mode 100644 index 000000000..69d040dd1 --- /dev/null +++ b/lib/puppet/functions/stdlib/bool2str.rb @@ -0,0 +1,84 @@ +# 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 ---- +# +# bool2str.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Converts a boolean to a string using optionally supplied arguments. +# +# The optional second and third arguments represent what true and false will be +# converted to respectively. If only one argument is given, it will be +# converted from a boolean to a string containing 'true' or 'false'. +# +# @return +# The converted value to string of the given Boolean +# +# **Examples of usage** +# +# ``` +# bool2str(true) => 'true' +# bool2str(true, 'yes', 'no') => 'yes' +# bool2str(false, 't', 'f') => 'f' +# ``` +# +# Requires a single boolean as an input. +# +# > *Note:* +# since Puppet 5.0.0 it is possible to create new data types for almost any +# datatype using the type system and the built-in +# [`String.new`](https://puppet.com/docs/puppet/latest/function.html#boolean-to-string) +# function is used to convert to String with many different format options. +# +# ``` +# notice(String(false)) # Notices 'false' +# notice(String(true)) # Notices 'true' +# notice(String(false, '%y')) # Notices 'yes' +# notice(String(true, '%y')) # Notices 'no' +# ``` +# +# +Puppet::Functions.create_function(:'stdlib::bool2str') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + unless arguments.size == 1 || arguments.size == 3 + raise(Puppet::ParseError, "bool2str(): Wrong number of arguments given (#{arguments.size} for 3)") + end + + value = arguments[0] + true_string = arguments[1] || 'true' + false_string = arguments[2] || 'false' + klass = value.class + + # We can have either true or false, and nothing else + unless [FalseClass, TrueClass].include?(klass) + raise(Puppet::ParseError, 'bool2str(): Requires a boolean to work with') + end + + unless [true_string, false_string].all? { |x| x.is_a?(String) } + raise(Puppet::ParseError, 'bool2str(): Requires strings to convert to') + end + + value ? true_string : false_string + end +end diff --git a/lib/puppet/functions/stdlib/camelcase.rb b/lib/puppet/functions/stdlib/camelcase.rb new file mode 100644 index 000000000..8d2f7c22c --- /dev/null +++ b/lib/puppet/functions/stdlib/camelcase.rb @@ -0,0 +1,61 @@ +# 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 ---- +# +# camelcase.rb +# Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated** Converts the case of a string or all strings in an array to camel case. +# +# > *Note:* +# **Deprecated** from Puppet 6.0.0, this function has been replaced with +# a built-in [`camelcase`](https://puppet.com/docs/puppet/latest/function.html#camelcase) +# function. +# +# @return [String] The converted String, if it was a String that was given +# @return [Array[String]] The converted Array, if it was a Array that was given +# +# +Puppet::Functions.create_function(:'stdlib::camelcase') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "camelcase(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + + value = arguments[0] + klass = value.class + + unless [Array, String].include?(klass) + raise(Puppet::ParseError, 'camelcase(): Requires either array or string to work with') + end + + result = if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... + value.map { |i| i.is_a?(String) ? i.split('_').map { |e| e.capitalize }.join : i } + else + value.split('_').map { |e| e.capitalize }.join + end + + result + end +end diff --git a/lib/puppet/functions/stdlib/capitalize.rb b/lib/puppet/functions/stdlib/capitalize.rb new file mode 100644 index 000000000..3e21b4a6b --- /dev/null +++ b/lib/puppet/functions/stdlib/capitalize.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 ---- +# +# capitalize.rb +# Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated** Capitalizes the first letter of a string or array of strings. +# +# Requires either a single string or an array as an input. +# +# > *Note:* +# **Deprecated** from Puppet 6.0.0, yhis function has been replaced with a +# built-in [`capitalize`](https://puppet.com/docs/puppet/latest/function.html#capitalize) +# function. +# +# @return [String] The converted String, if it was a String that was given +# @return [Array[String]] The converted Array, if it was a Array that was given +# +# +Puppet::Functions.create_function(:'stdlib::capitalize') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "capitalize(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + + value = arguments[0] + + unless value.is_a?(Array) || value.is_a?(String) + raise(Puppet::ParseError, 'capitalize(): Requires either array or string to work with') + end + + result = if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... + value.map { |i| i.is_a?(String) ? i.capitalize : i } + else + value.capitalize + end + + result + end +end diff --git a/lib/puppet/functions/stdlib/ceiling.rb b/lib/puppet/functions/stdlib/ceiling.rb new file mode 100644 index 000000000..d47d14269 --- /dev/null +++ b/lib/puppet/functions/stdlib/ceiling.rb @@ -0,0 +1,53 @@ +# 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 ---- +# +# ceiling.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated** Returns the smallest integer greater or equal to the argument. +# Takes a single numeric value as an argument. +# +# > *Note:* +# **Deprecated** from Puppet 6.0.0, this function has been replaced with a +# built-in [`ceiling`](https://puppet.com/docs/puppet/latest/function.html#ceiling) function. +# +# @return [Integer] The rounded value +# +# +Puppet::Functions.create_function(:'stdlib::ceiling') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "ceiling(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1 + + begin + arg = Float(arguments[0]) + rescue TypeError, ArgumentError => _e + raise(Puppet::ParseError, "ceiling(): Wrong argument type given (#{arguments[0]} for Numeric)") + end + + raise(Puppet::ParseError, "ceiling(): Wrong argument type given (#{arg.class} for Numeric)") if arg.is_a?(Numeric) == false + + arg.ceil + end +end diff --git a/lib/puppet/functions/stdlib/chomp.rb b/lib/puppet/functions/stdlib/chomp.rb new file mode 100644 index 000000000..24cb41156 --- /dev/null +++ b/lib/puppet/functions/stdlib/chomp.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 ---- +# +# chomp.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated** Removes the record separator from the end of a string or an array of strings. +# +# For example `hello +# ` becomes `hello`. +# Requires a single string or array as an input. +# +# > *Note:* +# **Deprecated** from Puppet 6.0.0, this function has been replaced with a +# built-in [`chomp`](https://puppet.com/docs/puppet/latest/function.html#chomp) function. +# +# @return [String] The converted String, if it was a String that was given +# @return [Array[String]] The converted Array, if it was a Array that was given +# +# +Puppet::Functions.create_function(:'stdlib::chomp') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "chomp(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + + value = arguments[0] + + unless value.is_a?(Array) || value.is_a?(String) + raise(Puppet::ParseError, 'chomp(): Requires either array or string to work with') + end + + result = if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... + value.map { |i| i.is_a?(String) ? i.chomp : i } + else + value.chomp + end + + result + end +end diff --git a/lib/puppet/functions/stdlib/chop.rb b/lib/puppet/functions/stdlib/chop.rb new file mode 100644 index 000000000..b1a62c0e9 --- /dev/null +++ b/lib/puppet/functions/stdlib/chop.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 ---- +# +# chop.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated** Returns a new string with the last character removed. +# +# If the string ends with ` +# `, both characters are removed. Applying +# chop to an empty string returns an empty string. If you wish to merely +# remove record separators then you should use the `chomp` function. +# Requires a string or array of strings as input. +# +# > *Note:* **Deprecated** from Puppet 6.0.0, this function has been replaced with a +# built-in [`chop`](https://puppet.com/docs/puppet/latest/function.html#chop) function. +# +# @return [String] The given String, sans the last character. +# +# +Puppet::Functions.create_function(:'stdlib::chop') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "chop(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + + value = arguments[0] + + unless value.is_a?(Array) || value.is_a?(String) + raise(Puppet::ParseError, 'chop(): Requires either an array or string to work with') + end + + result = if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... + value.map { |i| i.is_a?(String) ? i.chop : i } + else + value.chop + end + + result + end +end diff --git a/lib/puppet/functions/stdlib/clamp.rb b/lib/puppet/functions/stdlib/clamp.rb new file mode 100644 index 000000000..aaebe14a7 --- /dev/null +++ b/lib/puppet/functions/stdlib/clamp.rb @@ -0,0 +1,68 @@ +# 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 ---- +# +# clamp.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Keeps value within the range [Min, X, Max] by sort based on integer value +# (parameter order doesn't matter). +# +# Strings are converted and compared numerically. Arrays of values are flattened +# into a list for further handling. +# +# @example Example usage +# +# clamp('24', [575, 187])` returns 187. +# clamp(16, 88, 661)` returns 88. +# clamp([4, 3, '99'])` returns 4. +# +# > *Note:* +# From Puppet 6.0.0 this can be done with only core Puppet like this: +# `[$minval, $maxval, $value_to_clamp].sort[1]` +# +# @return [Array[Integer]] The sorted Array +# +# +Puppet::Functions.create_function(:'stdlib::clamp') 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) + args.flatten! + + raise(Puppet::ParseError, 'clamp(): Wrong number of arguments, need three to clamp') if args.size != 3 + + # check values out + args.each do |value| + case [value.class] + when [String] + raise(Puppet::ParseError, "clamp(): Required explicit numeric (#{value}:String)") unless value =~ %r{^\d+$} + when [Hash] + raise(Puppet::ParseError, "clamp(): The Hash type is not allowed (#{value})") + end + end + + # convert to numeric each element + # then sort them and get a middle value + args.map { |n| n.to_i }.sort[1] + end +end diff --git a/lib/puppet/functions/stdlib/concat.rb b/lib/puppet/functions/stdlib/concat.rb new file mode 100644 index 000000000..b7d86ca1b --- /dev/null +++ b/lib/puppet/functions/stdlib/concat.rb @@ -0,0 +1,68 @@ +# 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 ---- +# +# concat.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Appends the contents of multiple arrays into array 1. +# +# @example Example usage +# +# concat(['1','2','3'],'4') returns ['1','2','3','4'] +# concat(['1','2','3'],'4',['5','6','7']) returns ['1','2','3','4','5','6','7'] +# +# > *Note:* +# Since Puppet 4.0, you can use the `+`` operator for concatenation of arrays and +# merge of hashes, and the `<<`` operator for appending: +# +# `['1','2','3'] + ['4','5','6'] + ['7','8','9']` returns `['1','2','3','4','5','6','7','8','9']` +# `[1, 2, 3] << 4` returns `[1, 2, 3, 4]` +# `[1, 2, 3] << [4, 5]` returns `[1, 2, 3, [4, 5]]` +# +# @return [Array] The single concatenated array +# +# +Puppet::Functions.create_function(:'stdlib::concat') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + # Check that more than 2 arguments have been given ... + raise(Puppet::ParseError, "concat(): Wrong number of arguments given (#{arguments.size} for < 2)") if arguments.size < 2 + + a = arguments[0] + + # Check that the first parameter is an array + unless a.is_a?(Array) + raise(Puppet::ParseError, 'concat(): Requires array to work with') + end + + result = a + arguments.shift + + arguments.each do |x| + result += (x.is_a?(Array) ? x : [x]) + end + + result + end +end diff --git a/lib/puppet/functions/stdlib/convert_base.rb b/lib/puppet/functions/stdlib/convert_base.rb new file mode 100644 index 000000000..e25fe481b --- /dev/null +++ b/lib/puppet/functions/stdlib/convert_base.rb @@ -0,0 +1,75 @@ +# 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 ---- +# +# convert_base.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Converts a given integer or base 10 string representing an integer to a +# specified base, as a string. +# +# @return +# converted value as a string +# +# @example Example usage +# +# convert_base(5, 2)` results in: `'101'` +# convert_base('254', '16')` results in: `'fe'` +# +# > *Note:* +# Since Puppet 4.5.0 this can be done with the built-in +# [`String.new`](https://puppet.com/docs/puppet/latest/function.html#integer-to-string) +# function and its many formatting options: +# +# `$binary_repr = String(5, '%b')` return `"101"` +# `$hex_repr = String(254, "%x")` return `"fe"` +# `$hex_repr = String(254, "%#x")` return `"0xfe"` +# +# @return [String] The converted value as a String +# +# +Puppet::Functions.create_function(:'stdlib::convert_base') 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) + raise Puppet::ParseError, 'convert_base(): First argument must be either a string or an integer' unless args[0].is_a?(Integer) || args[0].is_a?(String) + raise Puppet::ParseError, 'convert_base(): Second argument must be either a string or an integer' unless args[1].is_a?(Integer) || args[1].is_a?(String) + + if args[0].is_a?(String) + raise Puppet::ParseError, 'convert_base(): First argument must be an integer or a string corresponding to an integer in base 10' unless args[0] =~ %r{^[0-9]+$} + end + + if args[1].is_a?(String) + raise Puppet::ParseError, 'convert_base(): First argument must be an integer or a string corresponding to an integer in base 10' unless args[1] =~ %r{^[0-9]+$} + end + + number_to_convert = args[0] + new_base = args[1] + + number_to_convert = number_to_convert.to_i + new_base = new_base.to_i + + raise Puppet::ParseError, 'convert_base(): base must be at least 2 and must not be greater than 36' unless new_base >= 2 && new_base <= 36 + + number_to_convert.to_s(new_base) + end +end diff --git a/lib/puppet/functions/stdlib/count.rb b/lib/puppet/functions/stdlib/count.rb new file mode 100644 index 000000000..659d2deac --- /dev/null +++ b/lib/puppet/functions/stdlib/count.rb @@ -0,0 +1,64 @@ +# 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 ---- +# +# count.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Counts the number of elements in array. +# +# Takes an array as first argument and an optional second argument. Counts the number of elements in array that is equal to the second argument. +# If called with only an array, it counts the number of elements that are not nil/undef/empty-string. +# +# > *Note:* +# equality is tested with a Ruby method and it is therefore subject to what Ruby considers +# to be equal. For strings this means that equality is case sensitive. +# +# In Puppet core, counting can be done in general by using a combination of the core functions +# filter() (since Puppet 4.0.0) and length() (since Puppet 5.5.0, before that in stdlib). +# +# Example below shows counting values that are not undef. +# +# ```notice([42, "hello", undef].filter |$x| { $x =~ NotUndef }.length)``` +# +# Would notice the value 2. +# +# @return [Integer] The amount of elements counted within the array +# +# +Puppet::Functions.create_function(:'stdlib::count') 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.size > 2 + raise(ArgumentError, "count(): Wrong number of arguments given #{args.size} for 1 or 2.") + end + + collection, item = args + + if item + collection.count item + else + collection.count { |obj| !obj.nil? && obj != :undef && obj != '' } + end + end +end diff --git a/lib/puppet/functions/stdlib/deep_merge.rb b/lib/puppet/functions/stdlib/deep_merge.rb new file mode 100644 index 000000000..190ab38b9 --- /dev/null +++ b/lib/puppet/functions/stdlib/deep_merge.rb @@ -0,0 +1,75 @@ +# 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 ---- +# +# deep_merge.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Recursively merges two or more hashes together and returns the resulting hash. +# +# @example Example usage +# +# $hash1 = {'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } } +# $hash2 = {'two' => 'dos', 'three' => { 'five' => 5 } } +# $merged_hash = deep_merge($hash1, $hash2) +# +# The resulting hash is equivalent to: +# +# $merged_hash = { 'one' => 1, 'two' => 'dos', 'three' => { 'four' => 4, 'five' => 5 } } +# +# When there is a duplicate key that is a hash, they are recursively merged. +# When there is a duplicate key that is not a hash, the key in the rightmost hash will "win." +# +# @return [Hash] The merged hash +# +# +Puppet::Functions.create_function(:'stdlib::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 + + deep_merge = proc do |hash1, hash2| + hash1.merge(hash2) do |_key, old_value, new_value| + if old_value.is_a?(Hash) && new_value.is_a?(Hash) + deep_merge.call(old_value, new_value) + else + new_value + end + end + end + + result = {} + args.each do |arg| + next if arg.is_a?(String) && arg.empty? # empty string is synonym for puppet's undef + # If the argument was not a hash, skip it. + unless arg.is_a?(Hash) + raise Puppet::ParseError, "deep_merge: unexpected argument type #{arg.class}, only expects hash arguments" + end + + result = deep_merge.call(result, arg) + end + result + end +end diff --git a/lib/puppet/functions/stdlib/defined_with_params.rb b/lib/puppet/functions/stdlib/defined_with_params.rb new file mode 100644 index 000000000..5de1f57b4 --- /dev/null +++ b/lib/puppet/functions/stdlib/defined_with_params.rb @@ -0,0 +1,87 @@ +# 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 ---- +# Test whether a given class or definition is defined +require 'puppet/parser/functions' + +# ---- original file header ---- +# +# @summary +# @summary +# Takes a resource reference and an optional hash of attributes. +# +# Returns `true` if a resource with the specified attributes has already been added +# to the catalog, and `false` otherwise. +# +# ``` +# user { 'dan': +# ensure => present, +# } +# +# if ! defined_with_params(User[dan], {'ensure' => 'present' }) { +# user { 'dan': ensure => present, } +# } +# ``` +# +# @return [Boolean] +# returns `true` or `false` +# +# +Puppet::Functions.create_function(:'stdlib::defined_with_params') do + # @param vals + # 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', :vals + end + + def default_impl(*vals) + reference, params = vals + raise(ArgumentError, 'Must specify a reference') unless reference + if !params || params == '' + params = {} + end + ret = false + + if Puppet::Util::Package.versioncmp(Puppet.version, '4.6.0') >= 0 + # Workaround for PE-20308 + if reference.is_a?(String) + type_name, title = Puppet::Resource.type_and_title(reference, nil) + type = Puppet::Pops::Evaluator::Runtime3ResourceSupport.find_resource_type_or_class(find_global_scope, type_name.downcase) + elsif reference.is_a?(Puppet::Resource) + type = reference.type + title = reference.title + else + raise(ArgumentError, "Reference is not understood: '#{reference.class}'") + end + # end workaround + else + type = reference.to_s + title = nil + end + + resource = findresource(type, title) + if resource + matches = params.map do |key, value| + # eql? avoids bugs caused by monkeypatching in puppet + resource_is_undef = resource[key].eql?(:undef) || resource[key].nil? + value_is_undef = value.eql?(:undef) || value.nil? + (resource_is_undef && value_is_undef) || (resource[key] == value) + end + ret = params.empty? || !matches.include?(false) + end + Puppet.debug("Resource #{reference} was not determined to be defined") + ret + end +end diff --git a/lib/puppet/functions/stdlib/delete.rb b/lib/puppet/functions/stdlib/delete.rb new file mode 100644 index 000000000..470501d7e --- /dev/null +++ b/lib/puppet/functions/stdlib/delete.rb @@ -0,0 +1,88 @@ +# 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 ---- +# +# delete.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Deletes all instances of a given element from an array, substring from a +# string, or key from a hash. +# +# @example Example usage +# +# delete(['a','b','c','b'], 'b') +# Would return: ['a','c'] +# +# delete({'a'=>1,'b'=>2,'c'=>3}, 'b') +# Would return: {'a'=>1,'c'=>3} +# +# delete({'a'=>1,'b'=>2,'c'=>3}, ['b','c']) +# Would return: {'a'=>1} +# +# delete('abracadabra', 'bra') +# Would return: 'acada' +# +# ['a', 'b', 'c', 'b'] - 'b' +# Would return: ['a', 'c'] +# +# {'a'=>1,'b'=>2,'c'=>3} - ['b','c']) +# Would return: {'a' => '1'} +# +# 'abracadabra'.regsubst(/bra/, '', 'G') +# Would return: 'acada' +# +# > *Note:* +# From Puppet 4.0.0 the minus (-) operator deletes values from arrays and keys from a hash +# `{'a'=>1,'b'=>2,'c'=>3} - ['b','c'])` +# > +# A global delete from a string can be performed with the +# [`regsubst`](https://puppet.com/docs/puppet/latest/function.html#regsubst) function: +# `'abracadabra'.regsubst(/bra/, '', 'G')` +# +# In general, the built-in [`filter`](https://puppet.com/docs/puppet/latest/function.html#filter) +# function can filter out entries from arrays and hashes based on keys and/or values. +# +# @return [String] The filtered String, if one was given. +# @return [Hash] The filtered Hash, if one was given. +# @return [Array] The filtered Array, if one was given. +# +# +Puppet::Functions.create_function(:'stdlib::delete') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "delete(): Wrong number of arguments given #{arguments.size} for 2") unless arguments.size == 2 + + collection = arguments[0].dup + Array(arguments[1]).each do |item| + case collection + when Array, Hash + collection.delete item + when String + collection.gsub! item, '' + else + raise(TypeError, "delete(): First argument must be an Array, String, or Hash. Given an argument of class #{collection.class}.") + end + end + collection + end +end diff --git a/lib/puppet/functions/stdlib/delete_at.rb b/lib/puppet/functions/stdlib/delete_at.rb new file mode 100644 index 000000000..d9393ab34 --- /dev/null +++ b/lib/puppet/functions/stdlib/delete_at.rb @@ -0,0 +1,83 @@ +# 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 ---- +# +# delete_at.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Deletes a determined indexed value from an array. +# +# For example +# ```delete_at(['a','b','c'], 1)``` +# +# Would return: `['a','c']` +# +# > *Note:* +# Since Puppet 4 this can be done in general with the built-in +# [`filter`](https://puppet.com/docs/puppet/latest/function.html#filter) function: +# +# ```['a', 'b', 'c'].filter |$pos, $val | { $pos != 1 }``` +# +# Or if a delete is wanted from the beginning or end of the array, by using the slice operator [ ]: +# ``` +# $array[0, -1] # the same as all the values +# $array[2, -1] # all but the first 2 elements +# $array[0, -3] # all but the last 2 elements +# $array[1, -2] # all but the first and last element +# ``` +# +# @return [Array] The given array, now missing the target value +# +# +# +Puppet::Functions.create_function(:'stdlib::delete_at') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "delete_at(): Wrong number of arguments given (#{arguments.size} for 2)") if arguments.size < 2 + + array = arguments[0] + + unless array.is_a?(Array) + raise(Puppet::ParseError, 'delete_at(): Requires array to work with') + end + + index = arguments[1] + + if index.is_a?(String) && !index.match(%r{^\d+$}) + raise(Puppet::ParseError, 'delete_at(): You must provide non-negative numeric index') + end + + result = array.clone + + # Numbers in Puppet are often string-encoded which is troublesome ... + index = index.to_i + + if index > result.size - 1 # First element is at index 0 is it not? + raise(Puppet::ParseError, 'delete_at(): Given index exceeds size of array given') + end + + result.delete_at(index) # We ignore the element that got deleted ... + + result + end +end diff --git a/lib/puppet/functions/stdlib/delete_regex.rb b/lib/puppet/functions/stdlib/delete_regex.rb new file mode 100644 index 000000000..a1ad7a633 --- /dev/null +++ b/lib/puppet/functions/stdlib/delete_regex.rb @@ -0,0 +1,73 @@ +# 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 ---- +# +# delete_regex.rb +# Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. +# +# ---- original file header ---- +# +# @summary +# @summary +# Deletes all instances of a given element that match a regular expression +# from an array or key from a hash. +# +# Multiple regular expressions are assumed to be matched as an OR. +# +# @example Example usage +# +# delete_regex(['a','b','c','b'], 'b') +# Would return: ['a','c'] +# +# delete_regex(['a','b','c','b'], ['b', 'c']) +# Would return: ['a'] +# +# delete_regex({'a'=>1,'b'=>2,'c'=>3}, 'b') +# Would return: {'a'=>1,'c'=>3} +# +# delete_regex({'a'=>1,'b'=>2,'c'=>3}, '^a$') +# Would return: {'b'=>2,'c'=>3} +# +# > *Note:* +# Since Puppet 4 this can be done in general with the built-in +# [`filter`](https://puppet.com/docs/puppet/latest/function.html#filter) function: +# ["aaa", "aba", "aca"].filter |$val| { $val !~ /b/ } +# Would return: ['aaa', 'aca'] +# +# @return [Array] The given array now missing all targeted values. +# +# +Puppet::Functions.create_function(:'stdlib::delete_regex') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "delete_regex(): Wrong number of arguments given #{arguments.size} for 2") unless arguments.size == 2 + + collection = arguments[0].dup + Array(arguments[1]).each do |item| + case collection + when Array, Hash, String + collection.reject! { |coll_item| (coll_item =~ %r{\b#{item}\b}) } + else + raise(TypeError, "delete_regex(): First argument must be an Array, Hash, or String. Given an argument of class #{collection.class}.") + end + end + collection + end +end diff --git a/lib/puppet/functions/stdlib/delete_undef_values.rb b/lib/puppet/functions/stdlib/delete_undef_values.rb new file mode 100644 index 000000000..3fa951257 --- /dev/null +++ b/lib/puppet/functions/stdlib/delete_undef_values.rb @@ -0,0 +1,65 @@ +# 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 ---- +# +# delete_undef_values.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Returns a copy of input hash or array with all undefs deleted. +# +# @example Example usage +# +# $hash = delete_undef_values({a=>'A', b=>'', c=>undef, d => false}) +# Would return: {a => 'A', b => '', d => false} +# +# While: +# $array = delete_undef_values(['A','',undef,false]) +# Would return: ['A','',false] +# +# > *Note:* +# Since Puppet 4.0.0 the equivalent can be performed with the built-in +# [`filter`](https://puppet.com/docs/puppet/latest/function.html#filter) function: +# $array.filter |$val| { $val =~ NotUndef } +# $hash.filter |$key, $val| { $val =~ NotUndef } +# +# @return [Array] The given array now issing of undefined values. +# +# +Puppet::Functions.create_function(:'stdlib::delete_undef_values') 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) + raise(Puppet::ParseError, "delete_undef_values(): Wrong number of arguments given (#{args.size})") if args.empty? + + unless args[0].is_a?(Array) || args[0].is_a?(Hash) + raise(Puppet::ParseError, "delete_undef_values(): expected an array or hash, got #{args[0]} type #{args[0].class} ") + end + result = args[0].dup + if result.is_a?(Hash) + result.delete_if { |_, val| val.equal?(:undef) || val.nil? } + elsif result.is_a?(Array) + result.delete :undef + result.delete nil + end + result + end +end diff --git a/lib/puppet/functions/stdlib/delete_values.rb b/lib/puppet/functions/stdlib/delete_values.rb new file mode 100644 index 000000000..a54ad1643 --- /dev/null +++ b/lib/puppet/functions/stdlib/delete_values.rb @@ -0,0 +1,56 @@ +# 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 ---- +# +# delete_values.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Deletes all instances of a given value from a hash. +# +# @example Example usage +# +# delete_values({'a'=>'A','b'=>'B','c'=>'C','B'=>'D'}, 'B') +# Would return: {'a'=>'A','c'=>'C','B'=>'D'} +# +# > *Note:* +# Since Puppet 4.0.0 the equivalent can be performed with the +# built-in [`filter`](https://puppet.com/docs/puppet/latest/function.html#filter) function: +# $array.filter |$val| { $val != 'B' } +# $hash.filter |$key, $val| { $val != 'B' } +# +# @return [Hash] The given hash now missing all instances of the targeted value +# +# +Puppet::Functions.create_function(:'stdlib::delete_values') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "delete_values(): Wrong number of arguments given (#{arguments.size} of 2)") if arguments.size != 2 + + hash, item = arguments + + unless hash.is_a?(Hash) + raise(TypeError, "delete_values(): First argument must be a Hash. Given an argument of class #{hash.class}.") + end + hash.dup.delete_if { |_key, val| item == val } + end +end diff --git a/lib/puppet/functions/stdlib/deprecation.rb b/lib/puppet/functions/stdlib/deprecation.rb new file mode 100644 index 000000000..17133e678 --- /dev/null +++ b/lib/puppet/functions/stdlib/deprecation.rb @@ -0,0 +1,47 @@ +# 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 ---- +# +# deprecation.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Function to print deprecation warnings (this is the 3.X version of it). +# +# The uniqueness key - can appear once. The msg is the message text including any positional +# information that is formatted by the user/caller of the method.). +# +# @return [String] +# return deprecation warnings +# +# +Puppet::Functions.create_function(:'stdlib::deprecation') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "deprecation: Wrong number of arguments given (#{arguments.size} for 2)") unless arguments.size == 2 + + key = arguments[0] + message = arguments[1] + + warning("deprecation. #{key}. #{message}") if ENV['STDLIB_LOG_DEPRECATIONS'] == 'true' + end +end diff --git a/lib/puppet/functions/stdlib/difference.rb b/lib/puppet/functions/stdlib/difference.rb new file mode 100644 index 000000000..422d60ea2 --- /dev/null +++ b/lib/puppet/functions/stdlib/difference.rb @@ -0,0 +1,65 @@ +# 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 ---- +# +# difference.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# This function returns the difference between two arrays. +# +# The returned array is a copy of the original array, removing any items that +# also appear in the second array. +# +# @example Example usage +# +# difference(["a","b","c"],["b","c","d"]) +# Would return: `["a"]` +# +# > *Note:* +# Since Puppet 4 the minus (-) operator in the Puppet language does the same thing: +# ['a', 'b', 'c'] - ['b', 'c', 'd'] +# Would return: `['a']` +# +# @return [Array] +# The difference between the two given arrays +# +# +# +Puppet::Functions.create_function(:'stdlib::difference') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + # Two arguments are required + raise(Puppet::ParseError, "difference(): Wrong number of arguments given (#{arguments.size} for 2)") if arguments.size != 2 + + first = arguments[0] + second = arguments[1] + + unless first.is_a?(Array) && second.is_a?(Array) + raise(Puppet::ParseError, 'difference(): Requires 2 arrays') + end + + result = first - second + + result + end +end diff --git a/lib/puppet/functions/stdlib/dig.rb b/lib/puppet/functions/stdlib/dig.rb new file mode 100644 index 000000000..f6de2cd09 --- /dev/null +++ b/lib/puppet/functions/stdlib/dig.rb @@ -0,0 +1,81 @@ +# 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 ---- +# +# dig.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **DEPRECATED** Retrieves a value within multiple layers of hashes and arrays via an +# array of keys containing a path. +# +# @return +# The function goes through the structure by each path component and tries to return +# the value at the end of the path. +# +# In addition to the required path argument, the function accepts the default argument. +# It is returned if the path is not correct, if no value was found, or if any other error +# has occurred. +# +# ```ruby +# $data = { +# 'a' => { +# 'b' => [ +# 'b1', +# 'b2', +# 'b3', +# ] +# } +# } +# +# $value = dig($data, ['a', 'b', 2]) +# # $value = 'b3' +# +# # with all possible options +# $value = dig($data, ['a', 'b', 2], 'not_found') +# # $value = 'b3' +# +# # using the default value +# $value = dig($data, ['a', 'b', 'c', 'd'], 'not_found') +# # $value = 'not_found' +# ``` +# +# 1. `$data` The data structure we are working with. +# 2. `['a', 'b', 2]` The path array. +# 3. `not_found` The default value. It is returned if nothing is found. +# +# > **Note:* +# **Deprecated** This function has been replaced with a built-in +# [`dig`](https://puppet.com/docs/puppet/latest/function.html#dig) function as of +# Puppet 4.5.0. Use [`dig44()`](#dig44) for backwards compatibility or use the new version. +# +# +Puppet::Functions.create_function(:'stdlib::dig') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + warning('dig() DEPRECATED: This function has been replaced in Puppet 4.5.0, please use dig44() for backwards compatibility or use the new version.') + unless Puppet::Parser::Functions.autoloader.loaded?(:dig44) + Puppet::Parser::Functions.autoloader.load(:dig44) + end + function_dig44(arguments) + end +end diff --git a/lib/puppet/functions/stdlib/dig44.rb b/lib/puppet/functions/stdlib/dig44.rb new file mode 100644 index 000000000..4583df29d --- /dev/null +++ b/lib/puppet/functions/stdlib/dig44.rb @@ -0,0 +1,90 @@ +# 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 ---- +# +# dig44.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **DEPRECATED**: Looks up into a complex structure of arrays and hashes and returns a value +# or the default value if nothing was found. +# +# Key can contain slashes to describe path components. The function will go down +# the structure and try to extract the required value. +# +# ``` +# $data = { +# 'a' => { +# 'b' => [ +# 'b1', +# 'b2', +# 'b3', +# ] +# } +# } +# +# $value = dig44($data, ['a', 'b', 2]) +# # $value = 'b3' +# +# # with all possible options +# $value = dig44($data, ['a', 'b', 2], 'not_found') +# # $value = 'b3' +# +# # using the default value +# $value = dig44($data, ['a', 'b', 'c', 'd'], 'not_found') +# # $value = 'not_found' +# ``` +# +# > **Note:* **Deprecated** This function has been replaced with a built-in +# [`dig`](https://puppet.com/docs/puppet/latest/function.html#dig) function as of +# Puppet 4.5.0. +# +# @return [String] 'not_found' will be returned if nothing is found +# @return [Any] the value that was searched for +# +# +Puppet::Functions.create_function(:'stdlib::dig44') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + # Two arguments are required + raise(Puppet::ParseError, "dig44(): Wrong number of arguments given (#{arguments.size} for at least 2)") if arguments.size < 2 + + data, path, default = *arguments + + raise(Puppet::ParseError, "dig44(): first argument must be a hash or an array, given #{data.class.name}") unless data.is_a?(Hash) || data.is_a?(Array) + raise(Puppet::ParseError, "dig44(): second argument must be an array, given #{path.class.name}") unless path.is_a? Array + + value = path.reduce(data) do |structure, key| + break unless structure.is_a?(Hash) || structure.is_a?(Array) + if structure.is_a? Array + begin + key = Integer key + rescue + break + end + end + break if structure[key].nil? || structure[key] == :undef + structure[key] + end + value.nil? ? default : value + end +end diff --git a/lib/puppet/functions/stdlib/dirname.rb b/lib/puppet/functions/stdlib/dirname.rb new file mode 100644 index 000000000..78e23a506 --- /dev/null +++ b/lib/puppet/functions/stdlib/dirname.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 ---- +# +# dirname.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Returns the dirname of a path. +# +# @return [String] the given path's dirname +# +# +Puppet::Functions.create_function(:'stdlib::dirname') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + if arguments.empty? + raise(Puppet::ParseError, 'dirname(): No arguments given') + end + if arguments.size > 1 + raise(Puppet::ParseError, "dirname(): Too many arguments given (#{arguments.size})") + end + unless arguments[0].is_a?(String) + raise(Puppet::ParseError, 'dirname(): Requires string as argument') + end + # undef is converted to an empty string '' + if arguments[0].empty? + raise(Puppet::ParseError, 'dirname(): Requires a non-empty string as argument') + end + + File.dirname(arguments[0]) + end +end diff --git a/lib/puppet/functions/stdlib/dos2unix.rb b/lib/puppet/functions/stdlib/dos2unix.rb new file mode 100644 index 000000000..9f1869610 --- /dev/null +++ b/lib/puppet/functions/stdlib/dos2unix.rb @@ -0,0 +1,42 @@ +# 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 ---- +# Custom Puppet function to convert dos to unix format +# ---- original file header ---- +# +# @summary +# @summary +# Returns the Unix version of the given string. +# +# Takes a single string argument. +# +# @return The retrieved version +# +# +Puppet::Functions.create_function(:'stdlib::dos2unix') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + unless arguments[0].is_a?(String) + raise(Puppet::ParseError, 'dos2unix(): Requires string as argument') + end + + arguments[0].gsub(%r{\r\n}, "\n") + end +end diff --git a/lib/puppet/functions/stdlib/downcase.rb b/lib/puppet/functions/stdlib/downcase.rb new file mode 100644 index 000000000..0b3ce45d5 --- /dev/null +++ b/lib/puppet/functions/stdlib/downcase.rb @@ -0,0 +1,61 @@ +# 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 ---- +# +# downcase.rb +# Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated:** Converts the case of a string or all strings in an array to lower case. +# +# > *Note:* **Deprecated** from Puppet 6.0.0, this function has been replaced with a +# built-in [`downcase`](https://puppet.com/docs/puppet/latest/function.html#downcase) function. +# > +# This function is an implementation of a Ruby class and might not be UTF8 compatible. +# To ensure compatibility, use this function with Ruby 2.4.0 or greater. +# +# @return [String] The converted String, if it was a String that was given +# @return [Array[String]] The converted Array, if it was a Array that was given +# +# +Puppet::Functions.create_function(:'stdlib::downcase') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "downcase(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + + value = arguments[0] + + unless value.is_a?(Array) || value.is_a?(String) + raise(Puppet::ParseError, 'downcase(): Requires either array or string to work with') + end + + result = if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... + value.map { |i| i.is_a?(String) ? i.downcase : i } + else + value.downcase + end + + result + end +end diff --git a/lib/puppet/functions/stdlib/empty.rb b/lib/puppet/functions/stdlib/empty.rb new file mode 100644 index 000000000..f36f56141 --- /dev/null +++ b/lib/puppet/functions/stdlib/empty.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 ---- +# +# empty.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated:** Returns true if the variable is empty. +# +# @return +# Returns `true` if the argument is an array or hash that contains no elements, +# or an empty string. Returns `false` when the argument is a numerical value. +# +# > *Note*: **Deprecated** from Puppet 5.5.0, the built-in +# [`empty`](https://puppet.com/docs/puppet/6.4/function.html#empty) function will be used instead. +# +# +Puppet::Functions.create_function(:'stdlib::empty') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "empty(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + value = arguments[0] + + unless value.is_a?(Array) || value.is_a?(Hash) || value.is_a?(String) || value.is_a?(Numeric) + raise(Puppet::ParseError, 'empty(): Requires either array, hash, string or integer to work with') + end + + return false if value.is_a?(Numeric) + result = value.empty? + result + end +end diff --git a/lib/puppet/functions/stdlib/enclose_ipv6.rb b/lib/puppet/functions/stdlib/enclose_ipv6.rb new file mode 100644 index 000000000..77127d39d --- /dev/null +++ b/lib/puppet/functions/stdlib/enclose_ipv6.rb @@ -0,0 +1,69 @@ +# 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 ---- +# +# enclose_ipv6.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Takes an array of ip addresses and encloses the ipv6 addresses with square brackets. +# +# @return +# encloses the ipv6 addresses with square brackets. +# +# +# +Puppet::Functions.create_function(:'stdlib::enclose_ipv6') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + require 'ipaddr' + + rescuable_exceptions = [ArgumentError] + if defined?(IPAddr::InvalidAddressError) + rescuable_exceptions << IPAddr::InvalidAddressError + end + + if arguments.size != 1 + raise(Puppet::ParseError, "enclose_ipv6(): Wrong number of arguments given #{arguments.size} for 1") + end + unless arguments[0].is_a?(String) || arguments[0].is_a?(Array) + raise(Puppet::ParseError, "enclose_ipv6(): Wrong argument type given #{arguments[0].class} expected String or Array") + end + + input = [arguments[0]].flatten.compact + result = [] + + input.each do |val| + unless val == '*' + begin + ip = IPAddr.new(val) + rescue *rescuable_exceptions + raise(Puppet::ParseError, "enclose_ipv6(): Wrong argument given #{val} is not an ip address.") + end + val = "[#{ip}]" if ip.ipv6? + end + result << val + end + + result.uniq + end +end diff --git a/lib/puppet/functions/stdlib/ensure_packages.rb b/lib/puppet/functions/stdlib/ensure_packages.rb new file mode 100644 index 000000000..dba88ccad --- /dev/null +++ b/lib/puppet/functions/stdlib/ensure_packages.rb @@ -0,0 +1,74 @@ +# 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 ---- +# +# ensure_packages.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Takes a list of packages and only installs them if they don't already exist. +# +# It optionally takes a hash as a second parameter that will be passed as the +# third argument to the ensure_resource() function. +# +# @return +# install the passed packages +# +# +Puppet::Functions.create_function(:'stdlib::ensure_packages') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "ensure_packages(): Wrong number of arguments given (#{arguments.size} for 1 or 2)") if arguments.size > 2 || arguments.empty? + raise(Puppet::ParseError, 'ensure_packages(): Requires second argument to be a Hash') if arguments.size == 2 && !arguments[1].is_a?(Hash) + + if arguments[0].is_a?(Hash) + if arguments[1] + defaults = { 'ensure' => 'present' }.merge(arguments[1]) + if defaults['ensure'] == 'installed' + defaults['ensure'] = 'present' + end + else + defaults = { 'ensure' => 'present' } + end + + Puppet::Parser::Functions.function(:ensure_resources) + function_ensure_resources(['package', arguments[0].dup, defaults]) + else + packages = Array(arguments[0]) + + if arguments[1] + defaults = { 'ensure' => 'present' }.merge(arguments[1]) + if defaults['ensure'] == 'installed' + defaults['ensure'] = 'present' + end + else + defaults = { 'ensure' => 'present' } + end + + Puppet::Parser::Functions.function(:ensure_resource) + packages.each do |package_name| + raise(Puppet::ParseError, 'ensure_packages(): Empty String provided for package name') if package_name.empty? + function_ensure_resource(['package', package_name, defaults]) + end + end + end +end diff --git a/lib/puppet/functions/stdlib/ensure_resource.rb b/lib/puppet/functions/stdlib/ensure_resource.rb new file mode 100644 index 000000000..27444dd38 --- /dev/null +++ b/lib/puppet/functions/stdlib/ensure_resource.rb @@ -0,0 +1,76 @@ +# 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 ---- +# Test whether a given class or definition is defined +require 'puppet/parser/functions' + +# ---- original file header ---- +# +# @summary +# @summary +# Takes a resource type, title, and a list of attributes that describe a +# resource. +# +# user { 'dan': +# ensure => present, +# } +# +# @return +# created or recreated the passed resource with the passed type and attributes +# +# @example Example usage +# +# Creates the resource if it does not already exist: +# +# ensure_resource('user', 'dan', {'ensure' => 'present' }) +# +# If the resource already exists but does not match the specified parameters, +# this function will attempt to recreate the resource leading to a duplicate +# resource definition error. +# +# An array of resources can also be passed in and each will be created with +# the type and parameters specified if it doesn't already exist. +# +# ensure_resource('user', ['dan','alex'], {'ensure' => 'present'}) +# +# +# +Puppet::Functions.create_function(:'stdlib::ensure_resource') do + # @param vals + # 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', :vals + end + + def default_impl(*vals) + type, title, params = vals + raise(ArgumentError, 'Must specify a type') unless type + raise(ArgumentError, 'Must specify a title') unless title + params ||= {} + + items = [title].flatten + + items.each do |item| + Puppet::Parser::Functions.function(:defined_with_params) + if function_defined_with_params(["#{type}[#{item}]", params]) + Puppet.debug("Resource #{type}[#{item}] with params #{params} not created because it already exists") + else + Puppet.debug("Create new resource #{type}[#{item}] with params #{params}") + Puppet::Parser::Functions.function(:create_resources) + function_create_resources([type.capitalize, { item => params }]) + end + end + end +end diff --git a/lib/puppet/functions/stdlib/ensure_resources.rb b/lib/puppet/functions/stdlib/ensure_resources.rb new file mode 100644 index 000000000..9de923981 --- /dev/null +++ b/lib/puppet/functions/stdlib/ensure_resources.rb @@ -0,0 +1,80 @@ +# 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 'puppet/parser/functions' + +# ---- original file header ---- +# +# @summary +# @summary +# Takes a resource type, title (only hash), and a list of attributes that describe a +# resource. +# +# @return +# created resources with the passed type and attributes +# +# @example Example usage +# +# user { 'dan': +# gid => 'mygroup', +# ensure => present, +# } +# +# An hash of resources should be passed in and each will be created with +# the type and parameters specified if it doesn't already exist. +# +# ensure_resources('user', {'dan' => { gid => 'mygroup', uid => '600' }, 'alex' => { gid => 'mygroup' }}, {'ensure' => 'present'}) +# +# From Hiera Backend: +# +# userlist: +# dan: +# gid: 'mygroup' +# uid: '600' +# alex: +# gid: 'mygroup' +# +# Call: +# ensure_resources('user', hiera_hash('userlist'), {'ensure' => 'present'}) +# +# +Puppet::Functions.create_function(:'stdlib::ensure_resources') do + # @param vals + # 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', :vals + end + + def default_impl(*vals) + type, title, params = vals + raise(ArgumentError, 'Must specify a type') unless type + raise(ArgumentError, 'Must specify a title') unless title + params ||= {} + + raise(Puppet::ParseError, 'ensure_resources(): Requires second argument to be a Hash') unless title.is_a?(Hash) + resource_hash = title.dup + resources = resource_hash.keys + + Puppet::Parser::Functions.function(:ensure_resource) + resources.each do |resource_name| + params_merged = if resource_hash[resource_name] + params.merge(resource_hash[resource_name]) + else + params + end + function_ensure_resource([type, resource_name, params_merged]) + end + end +end diff --git a/lib/puppet/functions/stdlib/flatten.rb b/lib/puppet/functions/stdlib/flatten.rb new file mode 100644 index 000000000..5f4f703ea --- /dev/null +++ b/lib/puppet/functions/stdlib/flatten.rb @@ -0,0 +1,57 @@ +# 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 ---- +# +# flatten.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# This function flattens any deeply nested arrays and returns a single flat array +# as a result. +# +# @return +# convert nested arrays into a single flat array +# +# @example Example usage +# +# flatten(['a', ['b', ['c']]])` returns: `['a','b','c'] +# +# > **Note:** **Deprecated** from Puppet 5.5.0, this function has been replaced with a +# built-in [`flatten`](https://puppet.com/docs/puppet/latest/function.html#flatten) function. +# +# +Puppet::Functions.create_function(:'stdlib::flatten') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "flatten(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1 + + array = arguments[0] + + unless array.is_a?(Array) + raise(Puppet::ParseError, 'flatten(): Requires array to work with') + end + + result = array.flatten + + result + end +end diff --git a/lib/puppet/functions/stdlib/floor.rb b/lib/puppet/functions/stdlib/floor.rb new file mode 100644 index 000000000..8d0911b43 --- /dev/null +++ b/lib/puppet/functions/stdlib/floor.rb @@ -0,0 +1,53 @@ +# 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 ---- +# +# floor.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Returns the largest integer less or equal to the argument. +# +# @return +# the largest integer less or equal to the argument. +# Takes a single numeric value as an argument. +# +# > **Note:** **Deprecated** from Puppet 6.0.0, this function has been replaced with +# a built-in [`floor`](https://puppet.com/docs/puppet/latest/function.html#floor) function. +# +# +Puppet::Functions.create_function(:'stdlib::floor') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "floor(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1 + + begin + arg = Float(arguments[0]) + rescue TypeError, ArgumentError => _e + raise(Puppet::ParseError, "floor(): Wrong argument type given (#{arguments[0]} for Numeric)") + end + + raise(Puppet::ParseError, "floor(): Wrong argument type given (#{arg.class} for Numeric)") if arg.is_a?(Numeric) == false + + arg.floor + end +end diff --git a/lib/puppet/functions/stdlib/fqdn_rand_string.rb b/lib/puppet/functions/stdlib/fqdn_rand_string.rb new file mode 100644 index 000000000..cabb59e79 --- /dev/null +++ b/lib/puppet/functions/stdlib/fqdn_rand_string.rb @@ -0,0 +1,66 @@ +# 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 ---- + +# ---- original file header ---- +# +# @summary +# @summary +# Generates a random alphanumeric string. Combining the `$fqdn` fact and an +# optional seed for repeatable randomness. +# +# Optionally, you can specify a character set for the function (defaults to alphanumeric). +# +# Arguments +# * An integer, specifying the length of the resulting string. +# * Optionally, a string specifying the character set. +# * Optionally, a string specifying the seed for repeatable randomness. +# +# @return [String] +# +# @example Example Usage: +# fqdn_rand_string(10) +# fqdn_rand_string(10, 'ABCDEF!@$%^') +# fqdn_rand_string(10, '', 'custom seed') +# +# +Puppet::Functions.create_function(:'stdlib::fqdn_rand_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) + raise(ArgumentError, 'fqdn_rand_string(): wrong number of arguments (0 for 1)') if args.empty? + Puppet::Parser::Functions.function('is_integer') + raise(ArgumentError, 'fqdn_rand_string(): first argument must be a positive integer') unless function_is_integer([args[0]]) && args[0].to_i > 0 + raise(ArgumentError, 'fqdn_rand_string(): second argument must be undef or a string') unless args[1].nil? || args[1].is_a?(String) + + Puppet::Parser::Functions.function('fqdn_rand') + + length = args.shift.to_i + charset = args.shift.to_s.chars.to_a + + charset = (0..9).map { |i| i.to_s } + ('A'..'Z').to_a + ('a'..'z').to_a if charset.empty? + + rand_string = '' + for current in 1..length # rubocop:disable Style/For : An each loop would not work correctly in this circumstance + rand_string << charset[function_fqdn_rand([charset.size, (args + [current.to_s]).join(':')]).to_i] + end + + rand_string + end +end diff --git a/lib/puppet/functions/stdlib/fqdn_rotate.rb b/lib/puppet/functions/stdlib/fqdn_rotate.rb new file mode 100644 index 000000000..3deeb93ba --- /dev/null +++ b/lib/puppet/functions/stdlib/fqdn_rotate.rb @@ -0,0 +1,83 @@ +# 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 ---- +# +# fqdn_rotate.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Rotates an array or string a random number of times, combining the `$fqdn` fact +# and an optional seed for repeatable randomness. +# +# @return +# rotated array or string +# +# @example Example Usage: +# fqdn_rotate(['a', 'b', 'c', 'd']) +# fqdn_rotate('abcd') +# fqdn_rotate([1, 2, 3], 'custom seed') +# +# +Puppet::Functions.create_function(:'stdlib::fqdn_rotate') 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) + raise(Puppet::ParseError, "fqdn_rotate(): Wrong number of arguments given (#{args.size} for 1)") if args.empty? + + value = args.shift + require 'digest/md5' + + unless value.is_a?(Array) || value.is_a?(String) + raise(Puppet::ParseError, 'fqdn_rotate(): Requires either array or string to work with') + end + + result = value.clone + + string = value.is_a?(String) ? true : false + + # Check whether it makes sense to rotate ... + return result if result.size <= 1 + + # We turn any string value into an array to be able to rotate ... + result = string ? result.split('') : result + + elements = result.size + + seed = Digest::MD5.hexdigest([lookupvar('::fqdn'), args].join(':')).hex + # deterministic_rand() was added in Puppet 3.2.0; reimplement if necessary + if Puppet::Util.respond_to?(:deterministic_rand) + offset = Puppet::Util.deterministic_rand(seed, elements).to_i + else + return offset = Random.new(seed).rand(elements) if defined?(Random) == 'constant' && Random.class == Class + + old_seed = srand(seed) + offset = rand(elements) + srand(old_seed) + end + offset.times do + result.push result.shift + end + + result = string ? result.join : result + + result + end +end diff --git a/lib/puppet/functions/stdlib/fqdn_uuid.rb b/lib/puppet/functions/stdlib/fqdn_uuid.rb new file mode 100644 index 000000000..cfd5e81f7 --- /dev/null +++ b/lib/puppet/functions/stdlib/fqdn_uuid.rb @@ -0,0 +1,92 @@ +# 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 'digest/sha1' +# +# fqdn_uuid.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Returns a [RFC 4122](https://tools.ietf.org/html/rfc4122) valid version 5 UUID based +# on an FQDN string under the DNS namespace +# +# @return +# Returns a [RFC 4122](https://tools.ietf.org/html/rfc4122) valid version 5 UUID +# +# @example Example Usage: +# fqdn_uuid('puppetlabs.com') # Returns '9c70320f-6815-5fc5-ab0f-debe68bf764c' +# fqdn_uuid('google.com') # Returns '64ee70a4-8cc1-5d25-abf2-dea6c79a09c8' +# +# +Puppet::Functions.create_function(:'stdlib::fqdn_uuid') 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) + raise(ArgumentError, 'fqdn_uuid: No arguments given') if args.empty? + raise(ArgumentError, "fqdn_uuid: Too many arguments given (#{args.length})") unless args.length == 1 + fqdn = args[0] + + # Code lovingly taken from + # https://github.com/puppetlabs/marionette-collective/blob/master/lib/mcollective/ssl.rb + + # This is the UUID version 5 type DNS name space which is as follows: + # + # 6ba7b810-9dad-11d1-80b4-00c04fd430c8 + # + uuid_name_space_dns = [0x6b, + 0xa7, + 0xb8, + 0x10, + 0x9d, + 0xad, + 0x11, + 0xd1, + 0x80, + 0xb4, + 0x00, + 0xc0, + 0x4f, + 0xd4, + 0x30, + 0xc8].map { |b| b.chr }.join + + sha1 = Digest::SHA1.new + sha1.update(uuid_name_space_dns) + sha1.update(fqdn) + + # first 16 bytes.. + bytes = sha1.digest[0, 16].bytes.to_a + + # version 5 adjustments + bytes[6] &= 0x0f + bytes[6] |= 0x50 + + # variant is DCE 1.1 + bytes[8] &= 0x3f + bytes[8] |= 0x80 + + bytes = [4, 2, 2, 2, 6].map do |i| + bytes.slice!(0, i).pack('C*').unpack('H*') + end + + bytes.join('-') + end +end diff --git a/lib/puppet/functions/stdlib/get_module_path.rb b/lib/puppet/functions/stdlib/get_module_path.rb new file mode 100644 index 000000000..3c1956866 --- /dev/null +++ b/lib/puppet/functions/stdlib/get_module_path.rb @@ -0,0 +1,53 @@ +# 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 ---- +# +# get_module_path.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Returns the absolute path of the specified module for the current +# environment. +# +# @return +# Returns the absolute path of the specified module for the current +# environment. +# +# @example Example Usage: +# $module_path = get_module_path('stdlib') +# +# > *Note:* +# that since Puppet 5.4.0 the built-in +# [`module_directory`](https://puppet.com/docs/puppet/latest/function.html#module_directory) +# function in Puppet does the same thing and will return the path to the first found module +# if given multiple values or an array. +# +# +Puppet::Functions.create_function(:'stdlib::get_module_path') 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) + raise(Puppet::ParseError, 'get_module_path(): Wrong number of arguments, expects one') unless args.size == 1 + module_path = Puppet::Module.find(args[0], compiler.environment.to_s) + raise(Puppet::ParseError, "Could not find module #{args[0]} in environment #{compiler.environment}") unless module_path + module_path.path + end +end diff --git a/lib/puppet/functions/stdlib/getparam.rb b/lib/puppet/functions/stdlib/getparam.rb new file mode 100644 index 000000000..8cd8be2d6 --- /dev/null +++ b/lib/puppet/functions/stdlib/getparam.rb @@ -0,0 +1,83 @@ +# 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 ---- +# Test whether a given class or definition is defined +require 'puppet/parser/functions' + +# ---- original file header ---- +# +# @summary +# @summary +# Returns the value of a resource's parameter. +# +# @return +# value of a resource's parameter. +# +# Takes a resource reference and name of the parameter and +# returns value of resource's parameter. Note that user defined +# resource types are evaluated lazily. +# +# @example Example Usage: +# +# # define a resource type with a parameter +# define example_resource($param) { +# } +# +# # declare an instance of that type +# example_resource { "example_resource_instance": +# param => "'the value we are getting in this example''" +# } +# +# # Because of order of evaluation, a second definition is needed +# # that will be evaluated after the first resource has been declared +# # +# define example_get_param { +# # This will notice the value of the parameter +# notice(getparam(Example_resource["example_resource_instance"], "param")) +# } +# +# # Declare an instance of the second resource type - this will call notice +# example_get_param { 'show_notify': } +# +# Would notice: 'the value we are getting in this example' +# +# > **Note** that since Puppet 4.0.0 it is possible to get a parameter value by using its data type +# and the [ ] operator. The example below is equivalent to a call to getparam(): +# ```Example_resource['example_resource_instance']['param']`` +# +# +# +Puppet::Functions.create_function(:'stdlib::getparam') do + # @param vals + # 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', :vals + end + + def default_impl(*vals) + reference, param = vals + raise(ArgumentError, 'Must specify a reference') unless reference + raise(ArgumentError, 'Must specify name of a parameter') unless param && param.instance_of?(String) + + return '' if param.empty? + + resource = findresource(reference.to_s) + if resource + return resource[param] unless resource[param].nil? + end + + '' + end +end diff --git a/lib/puppet/functions/stdlib/getvar.rb b/lib/puppet/functions/stdlib/getvar.rb new file mode 100644 index 000000000..a29a6d1c2 --- /dev/null +++ b/lib/puppet/functions/stdlib/getvar.rb @@ -0,0 +1,64 @@ +# 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 ---- +# +# getvar.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Lookup a variable in a given namespace. +# +# @return +# undef - if variable does not exist +# +# @example Example usage +# $foo = getvar('site::data::foo') # Equivalent to $foo = $site::data::foo +# +# @example Where namespace is stored in a string +# $datalocation = 'site::data' +# $bar = getvar("${datalocation}::bar") # Equivalent to $bar = $site::data::bar +# +# > **Note:** from Puppet 6.0.0, the compatible function with the same name in Puppet core +# will be used instead of this function. The new function also has support for +# digging into a structured value. See the built-in +# [`getvar`](https://puppet.com/docs/puppet/latest/function.html#getvar) function +# +# +Puppet::Functions.create_function(:'stdlib::getvar') 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, "getvar(): wrong number of arguments (#{args.length}; must be 1)" + end + + begin + result = nil + catch(:undefined_variable) do + result = lookupvar((args[0]).to_s) + end + + # avoid relying on inconsistent behaviour around ruby return values from catch + result + rescue Puppet::ParseError # rubocop:disable Lint/HandleExceptions : Eat the exception if strict_variables = true is set + end + end +end diff --git a/lib/puppet/functions/stdlib/glob.rb b/lib/puppet/functions/stdlib/glob.rb new file mode 100644 index 000000000..69a6e7b96 --- /dev/null +++ b/lib/puppet/functions/stdlib/glob.rb @@ -0,0 +1,54 @@ +# 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 ---- +# +# glob.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Uses same patterns as Dir#glob. +# +# @return +# Returns an Array of file entries of a directory or an Array of directories. +# +# @example Example Usage: +# $confs = glob(['/etc/**/*.conf', '/opt/**/*.conf']) +# +# +Puppet::Functions.create_function(:'stdlib::glob') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + unless arguments.size == 1 + raise(Puppet::ParseError, 'glob(): Wrong number of arguments given ' \ + "(#{arguments.size} for 1)") + end + + pattern = arguments[0] + + unless pattern.is_a?(String) || pattern.is_a?(Array) + raise(Puppet::ParseError, 'glob(): Requires either array or string ' \ + 'to work') + end + + Dir.glob(pattern) + end +end diff --git a/lib/puppet/functions/stdlib/grep.rb b/lib/puppet/functions/stdlib/grep.rb new file mode 100644 index 000000000..869a30f42 --- /dev/null +++ b/lib/puppet/functions/stdlib/grep.rb @@ -0,0 +1,54 @@ +# 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 ---- +# +# grep.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# This function searches through an array and returns any elements that match +# the provided regular expression. +# +# @return +# array of elements that match the provided regular expression. +# @example Example Usage: +# grep(['aaa','bbb','ccc','aaaddd'], 'aaa') # Returns ['aaa','aaaddd'] +# +# > **Note:** that since Puppet 4.0.0, the built-in +# [`filter`](https://puppet.com/docs/puppet/latest/function.html#filter) function does +# the "same" - as any logic can be used to filter, as opposed to just regular expressions: +# ```['aaa', 'bbb', 'ccc', 'aaaddd']. filter |$x| { $x =~ 'aaa' }``` +# +# +Puppet::Functions.create_function(:'stdlib::grep') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + if arguments.size != 2 + raise(Puppet::ParseError, "grep(): Wrong number of arguments given #{arguments.size} for 2") + end + + a = arguments[0] + pattern = Regexp.new(arguments[1]) + + a.grep(pattern) + end +end diff --git a/lib/puppet/functions/stdlib/has_interface_with.rb b/lib/puppet/functions/stdlib/has_interface_with.rb new file mode 100644 index 000000000..69a0b69f2 --- /dev/null +++ b/lib/puppet/functions/stdlib/has_interface_with.rb @@ -0,0 +1,94 @@ +# 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 ---- +# +# has_interface_with +# +# ---- original file header ---- +# +# @summary +# @summary +# Returns boolean based on kind and value. +# +# @return +# boolean values `true` or `false` +# +# Valid kinds are `macaddress`, `netmask`, `ipaddress` and `network`. +# +# @example **Usage** +# has_interface_with("macaddress", "x:x:x:x:x:x") # Returns `false` +# has_interface_with("ipaddress", "127.0.0.1") # Returns `true` +# +# @example If no "kind" is given, then the presence of the interface is checked: +# has_interface_with("lo") # Returns `true` +# +# +Puppet::Functions.create_function(:'stdlib::has_interface_with') 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) + raise(Puppet::ParseError, "has_interface_with(): Wrong number of arguments given (#{args.size} for 1 or 2)") if args.empty? || args.size > 2 + + interfaces = lookupvar('interfaces') + + # If we do not have any interfaces, then there are no requested attributes + return false if interfaces == :undefined || interfaces.nil? + + interfaces = interfaces.split(',') + + if args.size == 1 + return interfaces.member?(args[0]) + end + + kind, value = args + + # Bug with 3.7.1 - 3.7.3 when using future parser throws :undefined_variable + # https://tickets.puppetlabs.com/browse/PUP-3597 + factval = nil + begin + catch :undefined_variable do + factval = lookupvar(kind) + end + rescue Puppet::ParseError # rubocop:disable Lint/HandleExceptions : Eat the exception if strict_variables = true is set + end + if factval == value + return true + end + + result = false + interfaces.each do |iface| + iface.downcase! + factval = nil + begin + # Bug with 3.7.1 - 3.7.3 when using future parser throws :undefined_variable + # https://tickets.puppetlabs.com/browse/PUP-3597 + catch :undefined_variable do + factval = lookupvar("#{kind}_#{iface}") + end + rescue Puppet::ParseError # rubocop:disable Lint/HandleExceptions : Eat the exception if strict_variables = true is set + end + if value == factval + result = true + break + end + end + + result + end +end diff --git a/lib/puppet/functions/stdlib/has_ip_address.rb b/lib/puppet/functions/stdlib/has_ip_address.rb new file mode 100644 index 000000000..6faa645fb --- /dev/null +++ b/lib/puppet/functions/stdlib/has_ip_address.rb @@ -0,0 +1,47 @@ +# 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 ---- +# +# has_ip_address +# +# ---- original file header ---- +# +# @summary +# @summary +# Returns true if the client has the requested IP address on some interface. +# +# @return [Boolean] +# `true` or `false` +# +# This function iterates through the 'interfaces' fact and checks the +# 'ipaddress_IFACE' facts, performing a simple string comparison. +# +# +Puppet::Functions.create_function(:'stdlib::has_ip_address') 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) + raise(Puppet::ParseError, "has_ip_address(): Wrong number of arguments given (#{args.size} for 1)") if args.size != 1 + + Puppet::Parser::Functions.autoloader.load(:has_interface_with) \ + unless Puppet::Parser::Functions.autoloader.loaded?(:has_interface_with) + + function_has_interface_with(['ipaddress', args[0]]) + end +end diff --git a/lib/puppet/functions/stdlib/has_ip_network.rb b/lib/puppet/functions/stdlib/has_ip_network.rb new file mode 100644 index 000000000..74c9c2e49 --- /dev/null +++ b/lib/puppet/functions/stdlib/has_ip_network.rb @@ -0,0 +1,47 @@ +# 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 ---- +# +# has_ip_network +# +# ---- original file header ---- +# +# @summary +# @summary +# Returns true if the client has an IP address within the requested network. +# +# @return +# Boolean value, `true` if the client has an IP address within the requested network. +# +# This function iterates through the 'interfaces' fact and checks the +# 'network_IFACE' facts, performing a simple string comparision. +# +# +Puppet::Functions.create_function(:'stdlib::has_ip_network') 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) + raise(Puppet::ParseError, "has_ip_network(): Wrong number of arguments given (#{args.size} for 1)") if args.size != 1 + + Puppet::Parser::Functions.autoloader.load(:has_interface_with) \ + unless Puppet::Parser::Functions.autoloader.loaded?(:has_interface_with) + + function_has_interface_with(['network', args[0]]) + end +end diff --git a/lib/puppet/functions/stdlib/has_key.rb b/lib/puppet/functions/stdlib/has_key.rb new file mode 100644 index 000000000..0f4d5fc59 --- /dev/null +++ b/lib/puppet/functions/stdlib/has_key.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 ---- +# +# has_key.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated:** Determine if a hash has a certain key value. +# +# @return +# Boolean value +# +# @example Example Usage: +# +# $my_hash = {'key_one' => 'value_one'} +# if has_key($my_hash, 'key_two') { +# notice('we will not reach here') +# } +# if has_key($my_hash, 'key_one') { +# notice('this will be printed') +# } +# +# > **Note:** **Deprecated** since Puppet 4.0.0, this can now be achieved in the Puppet +# language with the following equivalent expression: +# $my_hash = {'key_one' => 'value_one'} +# if 'key_one' in $my_hash { +# notice('this will be printed') +# } +# +# +# +Puppet::Functions.create_function(:'stdlib::has_key') 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, "has_key(): wrong number of arguments (#{args.length}; must be 2)" + end + unless args[0].is_a?(Hash) + raise Puppet::ParseError, "has_key(): expects the first argument to be a hash, got #{args[0].inspect} which is of type #{args[0].class}" + end + args[0].key?(args[1]) + end +end diff --git a/lib/puppet/functions/stdlib/hash.rb b/lib/puppet/functions/stdlib/hash.rb new file mode 100644 index 000000000..32c31efba --- /dev/null +++ b/lib/puppet/functions/stdlib/hash.rb @@ -0,0 +1,68 @@ +# 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.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated:** This function converts an array into a hash. +# +# @return +# the converted array as a hash +# @example Example Usage: +# hash(['a',1,'b',2,'c',3]) # Returns: {'a'=>1,'b'=>2,'c'=>3} +# +# > **Note:** This function has been replaced with the built-in ability to create a new value of almost any +# data type - see the built-in [`Hash.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-hash-and-struct) function +# in Puppet. +# This example shows the equivalent expression in the Puppet language: +# ``` +# Hash(['a',1,'b',2,'c',3]) +# Hash([['a',1],['b',2],['c',3]]) +# ``` +# +# +Puppet::Functions.create_function(:'stdlib::hash') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "hash(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + + array = arguments[0] + + unless array.is_a?(Array) + raise(Puppet::ParseError, 'hash(): Requires array to work with') + end + + result = {} + + begin + # This is to make it compatible with older version of Ruby ... + array = array.flatten + result = Hash[*array] + rescue StandardError + raise(Puppet::ParseError, 'hash(): Unable to compute hash from array given') + end + + result + end +end diff --git a/lib/puppet/functions/stdlib/intersection.rb b/lib/puppet/functions/stdlib/intersection.rb new file mode 100644 index 000000000..d142778ec --- /dev/null +++ b/lib/puppet/functions/stdlib/intersection.rb @@ -0,0 +1,55 @@ +# 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 ---- +# +# intersection.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# This function returns an array of the intersection of two. +# +# @return +# an array of the intersection of two. +# +# @example Example Usage: +# intersection(["a","b","c"],["b","c","d"]) # returns ["b","c"] +# intersection(["a","b","c"],[1,2,3,4]) # returns [] (true, when evaluated as a Boolean) +# +# +Puppet::Functions.create_function(:'stdlib::intersection') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + # Two arguments are required + raise(Puppet::ParseError, "intersection(): Wrong number of arguments given (#{arguments.size} for 2)") if arguments.size != 2 + + first = arguments[0] + second = arguments[1] + + unless first.is_a?(Array) && second.is_a?(Array) + raise(Puppet::ParseError, "intersection(): Requires 2 arrays, got #{first.class} and #{second.class}") + end + + result = first & second + + result + end +end diff --git a/lib/puppet/functions/stdlib/is_absolute_path.rb b/lib/puppet/functions/stdlib/is_absolute_path.rb new file mode 100644 index 000000000..877b6b204 --- /dev/null +++ b/lib/puppet/functions/stdlib/is_absolute_path.rb @@ -0,0 +1,84 @@ +# 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_absolute_path.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated:** Returns boolean true if the string represents an absolute path in the filesystem. +# +# This function works for windows and unix style paths. +# +# @example The following values will return true: +# $my_path = 'C:/Program Files (x86)/Puppet Labs/Puppet' +# is_absolute_path($my_path) +# $my_path2 = '/var/lib/puppet' +# is_absolute_path($my_path2) +# $my_path3 = ['C:/Program Files (x86)/Puppet Labs/Puppet'] +# is_absolute_path($my_path3) +# $my_path4 = ['/var/lib/puppet'] +# is_absolute_path($my_path4) +# +# @example The following values will return false: +# is_absolute_path(true) +# is_absolute_path('../var/lib/puppet') +# is_absolute_path('var/lib/puppet') +# $undefined = undef +# is_absolute_path($undefined) +# +# @return [Boolean] +# Returns `true` or `false` +# +# > **Note:* **Deprecated** Will be removed in a future version of stdlib. See +# [`validate_legacy`](#validate_legacy). +# +# +Puppet::Functions.create_function(:'stdlib::is_absolute_path') 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) + function_deprecation([:is_absolute_path, 'This method is deprecated, please use the stdlib validate_legacy function, + with Stdlib::Compat::Absolute_path. There is further documentation for validate_legacy function in the README.']) + require 'puppet/util' + + path = args[0] + # This logic was borrowed from + # [lib/puppet/file_serving/base.rb](https://github.com/puppetlabs/puppet/blob/master/lib/puppet/file_serving/base.rb) + # Puppet 2.7 and beyond will have Puppet::Util.absolute_path? Fall back to a back-ported implementation otherwise. + if Puppet::Util.respond_to?(:absolute_path?) + value = (Puppet::Util.absolute_path?(path, :posix) || Puppet::Util.absolute_path?(path, :windows)) + else + # This code back-ported from 2.7.x's lib/puppet/util.rb Puppet::Util.absolute_path? + # Determine in a platform-specific way whether a path is absolute. This + # defaults to the local platform if none is specified. + # Escape once for the string literal, and once for the regex. + slash = '[\\\\/]' + name = '[^\\\\/]+' + regexes = { + :windows => %r{^(([A-Z]:#{slash})|(#{slash}#{slash}#{name}#{slash}#{name})|(#{slash}#{slash}\?#{slash}#{name}))}i, + :posix => %r{^/}, + } + value = !!(path =~ regexes[:posix]) || !!(path =~ regexes[:windows]) # rubocop:disable Style/DoubleNegation : No alternative known + end + value + end +end diff --git a/lib/puppet/functions/stdlib/is_array.rb b/lib/puppet/functions/stdlib/is_array.rb new file mode 100644 index 000000000..e63d96efb --- /dev/null +++ b/lib/puppet/functions/stdlib/is_array.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 ---- +# +# is_array.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated:** Returns true if the variable passed to this function is an array. +# +# @return [Boolean] +# Returns `true` or `false` +# +# > **Note:* **Deprecated** Will be removed in a future version of stdlib. See +# [`validate_legacy`](#validate_legacy). +# +# +Puppet::Functions.create_function(:'stdlib::is_array') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + function_deprecation([:is_array, 'This method is deprecated, please use the stdlib validate_legacy function, + with Stdlib::Compat::Array. There is further documentation for validate_legacy function in the README.']) + + raise(Puppet::ParseError, "is_array(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + + type = arguments[0] + + result = type.is_a?(Array) + + result + end +end diff --git a/lib/puppet/functions/stdlib/is_bool.rb b/lib/puppet/functions/stdlib/is_bool.rb new file mode 100644 index 000000000..267180cbc --- /dev/null +++ b/lib/puppet/functions/stdlib/is_bool.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 ---- +# +# is_bool.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated:** Returns true if the variable passed to this function is a boolean. +# +# @return [Boolean] +# Returns `true` or `false` +# +# > **Note:* **Deprecated** Will be removed in a future version of stdlib. See +# [`validate_legacy`](#validate_legacy). +# +# +Puppet::Functions.create_function(:'stdlib::is_bool') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + function_deprecation([:is_bool, 'This method is deprecated, please use the stdlib validate_legacy function, + with Stdlib::Compat::Bool. There is further documentation for validate_legacy function in the README.']) + + raise(Puppet::ParseError, "is_bool(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1 + + type = arguments[0] + + result = type.is_a?(TrueClass) || type.is_a?(FalseClass) + + result + end +end diff --git a/lib/puppet/functions/stdlib/is_domain_name.rb b/lib/puppet/functions/stdlib/is_domain_name.rb new file mode 100644 index 000000000..ec7245a8e --- /dev/null +++ b/lib/puppet/functions/stdlib/is_domain_name.rb @@ -0,0 +1,80 @@ +# 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_domain_name.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated:** Returns true if the string passed to this function is +# a syntactically correct domain name. +# +# @return [Boolean] +# Returns `true` or `false` +# +# > **Note:* **Deprecated** Will be removed in a future version of stdlib. See +# [`validate_legacy`](#validate_legacy). +# +# +Puppet::Functions.create_function(:'stdlib::is_domain_name') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + if arguments.size != 1 + raise(Puppet::ParseError, "is_domain_name(): Wrong number of arguments given #{arguments.size} for 1") + end + + # Only allow string types + return false unless arguments[0].is_a?(String) + + domain = arguments[0].dup + + # Limits (rfc1035, 3.1) + domain_max_length = 255 + label_min_length = 1 + label_max_length = 63 + + # Allow ".", it is the top level domain + return true if domain == '.' + + # Remove the final dot, if present. + domain.chomp!('.') + + # Check the whole domain + return false if domain.empty? + return false if domain.length > domain_max_length + + # The top level domain must be alphabetic if there are multiple labels. + # See rfc1123, 2.1 + return false if domain.include?('.') && !%r{\.[A-Za-z]+$}.match(domain) + + # Check each label in the domain + labels = domain.split('.') + vlabels = labels.each do |label| + break if label.length < label_min_length + break if label.length > label_max_length + break if label[-1..-1] == '-' + break if label[0..0] == '-' + break unless %r{^[a-z\d-]+$}i =~ label + end + vlabels == labels + end +end diff --git a/lib/puppet/functions/stdlib/is_email_address.rb b/lib/puppet/functions/stdlib/is_email_address.rb new file mode 100644 index 000000000..ba0872762 --- /dev/null +++ b/lib/puppet/functions/stdlib/is_email_address.rb @@ -0,0 +1,48 @@ +# 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_email_address.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated:** Returns true if the string passed to this function is a valid email address. +# +# @return [Boolean] +# Returns `true` or `false` +# +# > **Note:* **Deprecated** Will be removed in a future version of stdlib. See +# [`validate_legacy`](#validate_legacy). +# +# +Puppet::Functions.create_function(:'stdlib::is_email_address') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + if arguments.size != 1 + raise(Puppet::ParseError, "is_email_address(): Wrong number of arguments given #{arguments.size} for 1") + end + + # Taken from http://emailregex.com/ (simpler regex) + valid_email_regex = %r{\A([\w+\-].?)+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z} + (arguments[0] =~ valid_email_regex) == 0 # rubocop:disable Style/NumericPredicate : Changing to '.zero?' breaks the code + end +end diff --git a/lib/puppet/functions/stdlib/is_float.rb b/lib/puppet/functions/stdlib/is_float.rb new file mode 100644 index 000000000..1ec6eeb0c --- /dev/null +++ b/lib/puppet/functions/stdlib/is_float.rb @@ -0,0 +1,55 @@ +# 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_float.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated:** Returns true if the variable passed to this function is a float. +# +# @return [Boolean] +# Returns `true` or `false` +# +# > **Note:* **Deprecated** Will be removed in a future version of stdlib. See +# [`validate_legacy`](#validate_legacy). +# +# +Puppet::Functions.create_function(:'stdlib::is_float') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + function_deprecation([:is_float, 'This method is deprecated, please use the stdlib validate_legacy function, + with Stdlib::Compat::Float. There is further documentation for validate_legacy function in the README.']) + + if arguments.size != 1 + raise(Puppet::ParseError, "is_float(): Wrong number of arguments given #{arguments.size} for 1") + end + + value = arguments[0] + + # Only allow Numeric or String types + return false unless value.is_a?(Numeric) || value.is_a?(String) + + return false if value != value.to_f.to_s && !value.is_a?(Float) + true + end +end diff --git a/lib/puppet/functions/stdlib/is_function_available.rb b/lib/puppet/functions/stdlib/is_function_available.rb new file mode 100644 index 000000000..dbde71072 --- /dev/null +++ b/lib/puppet/functions/stdlib/is_function_available.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_function_available.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated:** Determines whether the Puppet runtime has access to a function by that name. +# +# This function accepts a string as an argument. +# +# @return [Boolean] +# Returns `true` or `false` +# +# > **Note:* **Deprecated** Will be removed in a future version of stdlib. See +# [`validate_legacy`](#validate_legacy). +# +# +Puppet::Functions.create_function(:'stdlib::is_function_available') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + if arguments.size != 1 + raise(Puppet::ParseError, "is_function_available?(): Wrong number of arguments given #{arguments.size} for 1") + end + + # Only allow String types + return false unless arguments[0].is_a?(String) + + function = Puppet::Parser::Functions.function(arguments[0].to_sym) + function.is_a?(String) && !function.empty? + end +end diff --git a/lib/puppet/functions/stdlib/is_hash.rb b/lib/puppet/functions/stdlib/is_hash.rb new file mode 100644 index 000000000..d6d231b55 --- /dev/null +++ b/lib/puppet/functions/stdlib/is_hash.rb @@ -0,0 +1,48 @@ +# 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_hash.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated:** Returns true if the variable passed to this function is a hash. +# +# @return [Boolean] +# Returns `true` or `false` +# +# > **Note:* **Deprecated** Will be removed in a future version of stdlib. See +# [`validate_legacy`](#validate_legacy). +# +# +Puppet::Functions.create_function(:'stdlib::is_hash') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "is_hash(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1 + + type = arguments[0] + + result = type.is_a?(Hash) + + result + end +end diff --git a/lib/puppet/functions/stdlib/is_integer.rb b/lib/puppet/functions/stdlib/is_integer.rb new file mode 100644 index 000000000..79ec43935 --- /dev/null +++ b/lib/puppet/functions/stdlib/is_integer.rb @@ -0,0 +1,72 @@ +# 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_integer.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated:** Returns true if the variable passed to this function is an Integer or +# a decimal (base 10) integer in String form. +# +# The string may start with a '-' (minus). A value of '0' is allowed, but a leading '0' +# digit may not be followed by other digits as this indicates that the value is octal (base 8). +# +# If given any other argument `false` is returned. +# +# @return [Boolean] +# Returns `true` or `false` +# +# > **Note:* **Deprecated** Will be removed in a future version of stdlib. See +# [`validate_legacy`](#validate_legacy). +# +# +Puppet::Functions.create_function(:'stdlib::is_integer') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + function_deprecation([:is_integer, 'This method is deprecated, please use the stdlib validate_legacy function, + with Stdlib::Compat::Integer. There is further documentation for validate_legacy function in the README.']) + + if arguments.size != 1 + raise(Puppet::ParseError, "is_integer(): Wrong number of arguments given #{arguments.size} for 1") + end + + value = arguments[0] + + # Regex is taken from the lexer of puppet + # puppet/pops/parser/lexer.rb but modified to match also + # negative values and disallow numbers prefixed with multiple + # 0's + # + # TODO these parameter should be a constant but I'm not sure + # if there is no risk to declare it inside of the module + # Puppet::Parser::Functions + + # Integer numbers like + # -1234568981273 + # 47291 + numeric = %r{^-?(?:(?:[1-9]\d*)|0)$} + + return true if value.is_a?(Integer) || (value.is_a?(String) && value.match(numeric)) + false + end +end diff --git a/lib/puppet/functions/stdlib/is_ip_address.rb b/lib/puppet/functions/stdlib/is_ip_address.rb new file mode 100644 index 000000000..ee38966f4 --- /dev/null +++ b/lib/puppet/functions/stdlib/is_ip_address.rb @@ -0,0 +1,58 @@ +# 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_ip_address.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated:** Returns true if the string passed to this function is a valid IP address. +# +# @return [Boolean] +# Returns `true` or `false` +# +# > **Note:* **Deprecated** Will be removed in a future version of stdlib. See +# [`validate_legacy`](#validate_legacy). +# +# +Puppet::Functions.create_function(:'stdlib::is_ip_address') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + require 'ipaddr' + + function_deprecation([:is_ip_address, 'This method is deprecated, please use the stdlib validate_legacy function, + with Stdlib::Compat::Ip_address. There is further documentation for validate_legacy function in the README.']) + + if arguments.size != 1 + raise(Puppet::ParseError, "is_ip_address(): Wrong number of arguments given #{arguments.size} for 1") + end + + begin + ip = IPAddr.new(arguments[0]) + rescue ArgumentError + return false + end + + return true if ip.ipv4? || ip.ipv6? + false + end +end diff --git a/lib/puppet/functions/stdlib/is_ipv4_address.rb b/lib/puppet/functions/stdlib/is_ipv4_address.rb new file mode 100644 index 000000000..08db5b31c --- /dev/null +++ b/lib/puppet/functions/stdlib/is_ipv4_address.rb @@ -0,0 +1,57 @@ +# 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_ipv4_address.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated:** Returns true if the string passed to this function is a valid IPv4 address. +# +# @return [Boolean] +# Returns `true` or `false` +# +# > **Note:* **Deprecated** Will be removed in a future version of stdlib. See +# [`validate_legacy`](#validate_legacy). +# +# +Puppet::Functions.create_function(:'stdlib::is_ipv4_address') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + require 'ipaddr' + + function_deprecation([:is_ipv4_address, 'This method is deprecated, please use the stdlib validate_legacy function, + with Stdlib::Compat::Ipv4. There is further documentation for validate_legacy function in the README.']) + + if arguments.size != 1 + raise(Puppet::ParseError, "is_ipv4_address(): Wrong number of arguments given #{arguments.size} for 1") + end + + begin + ip = IPAddr.new(arguments[0]) + rescue ArgumentError + return false + end + + ip.ipv4? + end +end diff --git a/lib/puppet/functions/stdlib/is_ipv6_address.rb b/lib/puppet/functions/stdlib/is_ipv6_address.rb new file mode 100644 index 000000000..244d0eba3 --- /dev/null +++ b/lib/puppet/functions/stdlib/is_ipv6_address.rb @@ -0,0 +1,57 @@ +# 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_ipv6_address.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated:** Returns true if the string passed to this function is a valid IPv6 address. +# +# @return [Boolean] +# Returns `true` or `false` +# +# > **Note:* **Deprecated** Will be removed in a future version of stdlib. See +# [`validate_legacy`](#validate_legacy). +# +# +Puppet::Functions.create_function(:'stdlib::is_ipv6_address') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + function_deprecation([:is_ipv6_address, 'This method is deprecated, please use the stdlib validate_legacy function, + with Stdlib::Compat::Ipv6. There is further documentation for validate_legacy function in the README.']) + + require 'ipaddr' + + if arguments.size != 1 + raise(Puppet::ParseError, "is_ipv6_address(): Wrong number of arguments given #{arguments.size} for 1") + end + + begin + ip = IPAddr.new(arguments[0]) + rescue ArgumentError + return false + end + + ip.ipv6? + end +end diff --git a/lib/puppet/functions/stdlib/is_mac_address.rb b/lib/puppet/functions/stdlib/is_mac_address.rb new file mode 100644 index 000000000..bc646232c --- /dev/null +++ b/lib/puppet/functions/stdlib/is_mac_address.rb @@ -0,0 +1,50 @@ +# 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_mac_address.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated:** Returns true if the string passed to this function is a valid mac address. +# +# @return [Boolean] +# Returns `true` or `false` +# +# > **Note:* **Deprecated** Will be removed in a future version of stdlib. See +# [`validate_legacy`](#validate_legacy). +# +# +Puppet::Functions.create_function(:'stdlib::is_mac_address') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + if arguments.size != 1 + raise(Puppet::ParseError, "is_mac_address(): Wrong number of arguments given #{arguments.size} for 1") + end + + mac = arguments[0] + + return true if %r{^[a-f0-9]{1,2}(:[a-f0-9]{1,2}){5}$}i =~ mac + return true if %r{^[a-f0-9]{1,2}(:[a-f0-9]{1,2}){19}$}i =~ mac + false + end +end diff --git a/lib/puppet/functions/stdlib/is_numeric.rb b/lib/puppet/functions/stdlib/is_numeric.rb new file mode 100644 index 000000000..fee027310 --- /dev/null +++ b/lib/puppet/functions/stdlib/is_numeric.rb @@ -0,0 +1,98 @@ +# 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_numeric.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated:** Returns true if the given value is numeric. +# +# Returns true if the given argument is a Numeric (Integer or Float), +# or a String containing either a valid integer in decimal base 10 form, or +# a valid floating point string representation. +# +# The function recognizes only decimal (base 10) integers and float but not +# integers in hex (base 16) or octal (base 8) form. +# +# The string representation may start with a '-' (minus). If a decimal '.' is used, +# it must be followed by at least one digit. +# +# @return [Boolean] +# Returns `true` or `false` +# +# > **Note:* **Deprecated** Will be removed in a future version of stdlib. See +# [`validate_legacy`](#validate_legacy). +# +# +Puppet::Functions.create_function(:'stdlib::is_numeric') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + function_deprecation([:is_numeric, 'This method is deprecated, please use the stdlib validate_legacy function, + with Stdlib::Compat::Numeric. There is further documentation for validate_legacy function in the README.']) + + if arguments.size != 1 + raise(Puppet::ParseError, "is_numeric(): Wrong number of arguments given #{arguments.size} for 1") + end + + value = arguments[0] + + # Regex is taken from the lexer of puppet + # puppet/pops/parser/lexer.rb but modified to match also + # negative values and disallow invalid octal numbers or + # numbers prefixed with multiple 0's (except in hex numbers) + # + # TODO these parameters should be constants but I'm not sure + # if there is no risk to declare them inside of the module + # Puppet::Parser::Functions + + # TODO: decide if this should be used + # HEX numbers like + # 0xaa230F + # 0X1234009C + # 0x0012 + # -12FcD + # numeric_hex = %r{^-?0[xX][0-9A-Fa-f]+$} + + # TODO: decide if this should be used + # OCTAL numbers like + # 01234567 + # -045372 + # numeric_oct = %r{^-?0[1-7][0-7]*$} + + # Integer/Float numbers like + # -0.1234568981273 + # 47291 + # 42.12345e-12 + numeric = %r{^-?(?:(?:[1-9]\d*)|0)(?:\.\d+)?(?:[eE]-?\d+)?$} + + if value.is_a?(Numeric) || (value.is_a?(String) && + value.match(numeric) # or + # value.match(numeric_hex) or + # value.match(numeric_oct) + ) + return true + else + return false + end + end +end diff --git a/lib/puppet/functions/stdlib/is_string.rb b/lib/puppet/functions/stdlib/is_string.rb new file mode 100644 index 000000000..49f7c6aab --- /dev/null +++ b/lib/puppet/functions/stdlib/is_string.rb @@ -0,0 +1,56 @@ +# 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_string.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated:** Returns true if the variable passed to this function is a string. +# +# @return [Boolean] +# Returns `true` or `false` +# +# > **Note:* **Deprecated** Will be removed in a future version of stdlib. See +# [`validate_legacy`](#validate_legacy). +# +# +Puppet::Functions.create_function(:'stdlib::is_string') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + function_deprecation([:is_string, 'This method is deprecated, please use the stdlib validate_legacy function, + with Stdlib::Compat::String. There is further documentation for validate_legacy function in the README.']) + + raise(Puppet::ParseError, "is_string(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + + type = arguments[0] + + # when called through the v4 API shim, undef gets translated to nil + result = type.is_a?(String) || type.nil? + + if result && (type == type.to_f.to_s || type == type.to_i.to_s) + return false + end + + result + end +end diff --git a/lib/puppet/functions/stdlib/join.rb b/lib/puppet/functions/stdlib/join.rb new file mode 100644 index 000000000..504c84f3d --- /dev/null +++ b/lib/puppet/functions/stdlib/join.rb @@ -0,0 +1,64 @@ +# 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 ---- +# +# join.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated:** This function joins an array into a string using a separator. +# +# @example Example Usage: +# join(['a','b','c'], ",") # Results in: "a,b,c" +# +# @return [String] +# The String containing each of the array values +# +# > **Note:** **Deprecated** from Puppet 5.4.0 this function has been replaced +# with a built-in [`join`](https://puppet.com/docs/puppet/latest/function.html#join) function. +# +# +Puppet::Functions.create_function(:'stdlib::join') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + # Technically we support two arguments but only first is mandatory ... + raise(Puppet::ParseError, "join(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + + array = arguments[0] + + unless array.is_a?(Array) + raise(Puppet::ParseError, 'join(): Requires array to work with') + end + + suffix = arguments[1] if arguments[1] + + if suffix + unless suffix.is_a?(String) + raise(Puppet::ParseError, 'join(): Requires string to work with') + end + end + + result = suffix ? array.join(suffix) : array.join + + result + end +end diff --git a/lib/puppet/functions/stdlib/join_keys_to_values.rb b/lib/puppet/functions/stdlib/join_keys_to_values.rb new file mode 100644 index 000000000..0d771c2c8 --- /dev/null +++ b/lib/puppet/functions/stdlib/join_keys_to_values.rb @@ -0,0 +1,79 @@ +# 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 ---- +# +# join_keys_to_values.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# This function joins each key of a hash to that key's corresponding value with a +# separator. +# +# Keys are cast to strings. If values are arrays, multiple keys +# are added for each element. The return value is an array in +# which each element is one joined key/value pair. +# +# @example Example Usage: +# join_keys_to_values({'a'=>1,'b'=>2}, " is ") # Results in: ["a is 1","b is 2"] +# join_keys_to_values({'a'=>1,'b'=>[2,3]}, " is ") # Results in: ["a is 1","b is 2","b is 3"] +# +# @return [Hash] +# The joined hash +# +# > **Note:** Since Puppet 5.0.0 - for more detailed control over the formatting (including indentations and +# line breaks, delimiters around arrays and hash entries, between key/values in hash entries, and individual +# formatting of values in the array) - see the `new` function for `String` and its formatting +# options for `Array` and `Hash`. +# +# +Puppet::Functions.create_function(:'stdlib::join_keys_to_values') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + # Validate the number of arguments. + if arguments.size != 2 + raise(Puppet::ParseError, "join_keys_to_values(): Takes exactly two arguments, but #{arguments.size} given.") + end + + # Validate the first argument. + hash = arguments[0] + unless hash.is_a?(Hash) + raise(TypeError, "join_keys_to_values(): The first argument must be a hash, but a #{hash.class} was given.") + end + + # Validate the second argument. + separator = arguments[1] + unless separator.is_a?(String) + raise(TypeError, "join_keys_to_values(): The second argument must be a string, but a #{separator.class} was given.") + end + + # Join the keys to their values. + hash.map { |k, v| + if v.is_a?(Array) + v.map { |va| String(k) + separator + String(va) } + elsif String(v) == 'undef' + String(k) + else + String(k) + separator + String(v) + end + }.flatten + end +end diff --git a/lib/puppet/functions/stdlib/keys.rb b/lib/puppet/functions/stdlib/keys.rb new file mode 100644 index 000000000..eaf6879ac --- /dev/null +++ b/lib/puppet/functions/stdlib/keys.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 ---- +# +# keys.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated:** Returns the keys of a hash as an array. +# +# @return [Array] +# An array containing each of the hashes key values. +# +# > **Note:** **Deprecated** from Puppet 5.5.0, the built-in [`keys`](https://puppet.com/docs/puppet/latest/function.html#keys) +# function will be used instead of this function. +# +# +Puppet::Functions.create_function(:'stdlib::keys') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "keys(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + + hash = arguments[0] + + unless hash.is_a?(Hash) + raise(Puppet::ParseError, 'keys(): Requires hash to work with') + end + + result = hash.keys + + result + end +end diff --git a/lib/puppet/functions/stdlib/load_module_metadata.rb b/lib/puppet/functions/stdlib/load_module_metadata.rb new file mode 100644 index 000000000..f41eee747 --- /dev/null +++ b/lib/puppet/functions/stdlib/load_module_metadata.rb @@ -0,0 +1,57 @@ +# 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 ---- +# +# load_module_metadata.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# This function loads the metadata of a given module. +# +# @example Example USage: +# $metadata = load_module_metadata('archive') +# notify { $metadata['author']: } +# +# @return +# The modules metadata +# +# +Puppet::Functions.create_function(:'stdlib::load_module_metadata') 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) + raise(Puppet::ParseError, 'load_module_metadata(): Wrong number of arguments, expects one or two') unless [1, 2].include?(args.size) + mod = args[0] + allow_empty_metadata = args[1] + module_path = function_get_module_path([mod]) + metadata_json = File.join(module_path, 'metadata.json') + + metadata_exists = File.exists?(metadata_json) # rubocop:disable Lint/DeprecatedClassMethods : Changing to .exist? breaks the code + if metadata_exists + metadata = PSON.load(File.read(metadata_json)) + else + metadata = {} + raise(Puppet::ParseError, "load_module_metadata(): No metadata.json file for module #{mod}") unless allow_empty_metadata + end + + metadata + end +end diff --git a/lib/puppet/functions/stdlib/loadjson.rb b/lib/puppet/functions/stdlib/loadjson.rb new file mode 100644 index 000000000..e3cde46bc --- /dev/null +++ b/lib/puppet/functions/stdlib/loadjson.rb @@ -0,0 +1,86 @@ +# 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 ---- +# +# loadjson.rb +# + +# ---- original file header ---- +# +# @summary +# @summary +# Load a JSON file containing an array, string, or hash, and return the data +# in the corresponding native data type. +# +# The first parameter can be a file path or a URL. +# The second parameter is the default value. It will be returned if the file +# was not found or could not be parsed. +# +# @return [Array|String|Hash] +# The data stored in the JSON file, the type depending on the type of data that was stored. +# +# @example Example Usage: +# $myhash = loadjson('/etc/puppet/data/myhash.json') +# $myhash = loadjson('https://example.local/my_hash.json') +# $myhash = loadjson('https://username:password@example.local/my_hash.json') +# $myhash = loadjson('no-file.json', {'default' => 'value'}) +# +# +Puppet::Functions.create_function(:'stdlib::loadjson') 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) + raise ArgumentError, 'Wrong number of arguments. 1 or 2 arguments should be provided.' unless args.length >= 1 + require 'open-uri' + begin + if args[0].start_with?('http://', 'https://') + username = '' + password = '' + if (match = args[0].match(%r{(http\://|https\://)(.*):(.*)@(.*)})) + # If URL is in the format of https://username:password@example.local/my_hash.yaml + protocol, username, password, path = match.captures + url = "#{protocol}#{path}" + elsif (match = args[0].match(%r{(http\:\/\/|https\:\/\/)(.*)@(.*)})) + # If URL is in the format of https://username@example.local/my_hash.yaml + protocol, username, path = match.captures + url = "#{protocol}#{path}" + else + url = args[0] + end + begin + contents = OpenURI.open_uri(url, :http_basic_authentication => [username, password]) + rescue OpenURI::HTTPError => err + res = err.io + warning("Can't load '#{url}' HTTP Error Code: '#{res.status[0]}'") + args[1] + end + PSON.load(contents) || args[1] + elsif File.exists?(args[0]) # rubocop:disable Lint/DeprecatedClassMethods : Changing to .exist? breaks the code + content = File.read(args[0]) + PSON.load(content) || args[1] + else + warning("Can't load '#{args[0]}' File does not exist!") + args[1] + end + rescue StandardError => e + raise e unless args[1] + args[1] + end + end +end diff --git a/lib/puppet/functions/stdlib/loadyaml.rb b/lib/puppet/functions/stdlib/loadyaml.rb new file mode 100644 index 000000000..28661dd52 --- /dev/null +++ b/lib/puppet/functions/stdlib/loadyaml.rb @@ -0,0 +1,85 @@ +# 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 ---- +# +# loadyaml.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Load a YAML file containing an array, string, or hash, and return the data +# in the corresponding native data type. +# +# The first parameter can be a file path or a URL. +# The second parameter is the default value. It will be returned if the file +# was not found or could not be parsed. +# +# @return [Array|String|Hash] +# The data stored in the YAML file, the type depending on the type of data that was stored. +# +# @example Example Usage: +# $myhash = loadyaml('/etc/puppet/data/myhash.yaml') +# $myhash = loadyaml('https://example.local/my_hash.yaml') +# $myhash = loadyaml('https://username:password@example.local/my_hash.yaml') +# $myhash = loadyaml('no-file.yaml', {'default' => 'value'}) +# +# +Puppet::Functions.create_function(:'stdlib::loadyaml') 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) + raise ArgumentError, 'Wrong number of arguments. 1 or 2 arguments should be provided.' unless args.length >= 1 + require 'yaml' + require 'open-uri' + begin + if args[0].start_with?('http://', 'https://') + username = '' + password = '' + if (match = args[0].match(%r{(http\://|https\://)(.*):(.*)@(.*)})) + # If URL is in the format of https://username:password@example.local/my_hash.yaml + protocol, username, password, path = match.captures + url = "#{protocol}#{path}" + elsif (match = args[0].match(%r{(http\:\/\/|https\:\/\/)(.*)@(.*)})) + # If URL is in the format of https://username@example.local/my_hash.yaml + protocol, username, path = match.captures + url = "#{protocol}#{path}" + else + url = args[0] + end + begin + contents = OpenURI.open_uri(url, :http_basic_authentication => [username, password]) + rescue OpenURI::HTTPError => err + res = err.io + warning("Can't load '#{url}' HTTP Error Code: '#{res.status[0]}'") + args[1] + end + YAML.safe_load(contents) || args[1] + elsif File.exists?(args[0]) # rubocop:disable Lint/DeprecatedClassMethods : Changing to .exist? breaks the code + YAML.load_file(args[0]) || args[1] + else + warning("Can't load '#{args[0]}' File does not exist!") + args[1] + end + rescue StandardError => e + raise e unless args[1] + args[1] + end + end +end diff --git a/lib/puppet/functions/stdlib/lstrip.rb b/lib/puppet/functions/stdlib/lstrip.rb new file mode 100644 index 000000000..61097b3fe --- /dev/null +++ b/lib/puppet/functions/stdlib/lstrip.rb @@ -0,0 +1,57 @@ +# 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 ---- +# +# lstrip.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated:** Strips leading spaces to the left of a string. +# +# @return [String] +# The stripped string +# +# > **Note:** **Deprecated** from Puppet 6.0.0, this function has been replaced with a +# built-in [`max`](https://puppet.com/docs/puppet/latest/function.html#max) function. +# +# +Puppet::Functions.create_function(:'stdlib::lstrip') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "lstrip(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + + value = arguments[0] + + unless value.is_a?(Array) || value.is_a?(String) + raise(Puppet::ParseError, 'lstrip(): Requires either array or string to work with') + end + + result = if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... + value.map { |i| i.is_a?(String) ? i.lstrip : i } + else + value.lstrip + end + + result + end +end diff --git a/lib/puppet/functions/stdlib/max.rb b/lib/puppet/functions/stdlib/max.rb new file mode 100644 index 000000000..eda36cece --- /dev/null +++ b/lib/puppet/functions/stdlib/max.rb @@ -0,0 +1,54 @@ +# 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 ---- +# +# max.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated:** Returns the highest value of all arguments. +# +# Requires at least one argument. +# +# @return +# The highest value among those passed in +# +# > **Note:** **Deprecated** from Puppet 6.0.0, this function has been replaced with a +# built-in [`lstrip`](https://puppet.com/docs/puppet/latest/function.html#lstrip) function. +# +# +Puppet::Functions.create_function(:'stdlib::max') 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) + raise(Puppet::ParseError, 'max(): Wrong number of arguments need at least one') if args.empty? + + # Sometimes we get numbers as numerics and sometimes as strings. + # We try to compare them as numbers when possible + args.max do |a, b| + if a.to_s =~ %r{\A-?\d+(.\d+)?\z} && b.to_s =~ %r{\A-?\d+(.\d+)?\z} + a.to_f <=> b.to_f + else + a.to_s <=> b.to_s + end + end + end +end diff --git a/lib/puppet/functions/stdlib/member.rb b/lib/puppet/functions/stdlib/member.rb new file mode 100644 index 000000000..945d062ef --- /dev/null +++ b/lib/puppet/functions/stdlib/member.rb @@ -0,0 +1,86 @@ +# 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 ---- +# TODO(Krzysztof Wilczynski): We need to add support for regular expression ... +# TODO(Krzysztof Wilczynski): Support for strings and hashes too ... +# +# member.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# This function determines if a variable is a member of an array. +# +# The variable can be a string, fixnum, or array. +# +# > **Note**: This function does not support nested arrays. If the first argument contains +# nested arrays, it will not recurse through them. +# +# @example **Usage** +# member(['a','b'], 'b') # Returns: true +# member(['a', 'b', 'c'], ['a', 'b']) # Returns: true +# member(['a','b'], 'c') # Returns: false +# member(['a', 'b', 'c'], ['d', 'b']) # Returns: false +# +# > *Note:* +# Since Puppet 4.0.0 the same can be performed in the Puppet language. +# For single values the operator `in` can be used: +# `'a' in ['a', 'b'] # true` +# For arrays by using operator `-` to compute a diff: +# `['d', 'b'] - ['a', 'b', 'c'] == [] # false because 'd' is not subtracted` +# `['a', 'b'] - ['a', 'b', 'c'] == [] # true because both 'a' and 'b' are subtracted` +# +# @return +# Returns whether the given value was a member of the array +# +# > **Note** that since Puppet 5.2.0, the general form to test the content of an array or +# hash is to use the built-in [`any`](https://puppet.com/docs/puppet/latest/function.html#any) +# and [`all`](https://puppet.com/docs/puppet/latest/function.html#all) functions. +# +# +Puppet::Functions.create_function(:'stdlib::member') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "member(): Wrong number of arguments given (#{arguments.size} for 2)") if arguments.size < 2 + + array = arguments[0] + + unless array.is_a?(Array) + raise(Puppet::ParseError, 'member(): Requires array to work with') + end + + unless arguments[1].is_a?(String) || arguments[1].is_a?(Integer) || arguments[1].is_a?(Array) + raise(Puppet::ParseError, 'member(): Item to search for must be a string, fixnum, or array') + end + + item = if arguments[1].is_a?(String) || arguments[1].is_a?(Integer) + [arguments[1]] + else + arguments[1] + end + + raise(Puppet::ParseError, 'member(): You must provide item to search for within array given') if item.respond_to?('empty?') && item.empty? + + result = (item - array).empty? + + result + end +end diff --git a/lib/puppet/functions/stdlib/merge.rb b/lib/puppet/functions/stdlib/merge.rb new file mode 100644 index 000000000..4cbfa80b4 --- /dev/null +++ b/lib/puppet/functions/stdlib/merge.rb @@ -0,0 +1,64 @@ +# 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 ---- +# +# merge.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Merges two or more hashes together and returns the resulting hash. +# +# @example **Usage** +# $hash1 = {'one' => 1, 'two', => 2} +# $hash2 = {'two' => 'dos', 'three', => 'tres'} +# $merged_hash = merge($hash1, $hash2) # $merged_hash = {'one' => 1, 'two' => 'dos', 'three' => 'tres'} +# +# When there is a duplicate key, the key in the rightmost hash will "win." +# +# @return [Hash] +# The merged hash +# +# Note that since Puppet 4.0.0 the same merge can be achieved with the + operator. +# `$merged_hash = $hash1 + $hash2` +# +# +Puppet::Functions.create_function(:'stdlib::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, "merge(): wrong number of arguments (#{args.length}; must be at least 2)" + end + + # The hash we accumulate into + accumulator = {} + # Merge into the accumulator hash + args.each do |arg| + next if arg.is_a?(String) && arg.empty? # empty string is synonym for puppet's undef + unless arg.is_a?(Hash) + raise Puppet::ParseError, "merge: unexpected argument type #{arg.class}, only expects hash arguments" + end + accumulator.merge!(arg) + end + # Return the fully merged hash + accumulator + end +end diff --git a/lib/puppet/functions/stdlib/min.rb b/lib/puppet/functions/stdlib/min.rb new file mode 100644 index 000000000..9a9a49943 --- /dev/null +++ b/lib/puppet/functions/stdlib/min.rb @@ -0,0 +1,54 @@ +# 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 ---- +# +# min.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated:** Returns the lowest value of all arguments. +# +# Requires at least one argument. +# +# @return +# The lowest value among the given arguments +# +# > **Note:** **Deprecated** from Puppet 6.0.0, this function has been replaced with a +# built-in [`min`](https://puppet.com/docs/puppet/latest/function.html#min) function. +# +# +Puppet::Functions.create_function(:'stdlib::min') 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) + raise(Puppet::ParseError, 'min(): Wrong number of arguments need at least one') if args.empty? + + # Sometimes we get numbers as numerics and sometimes as strings. + # We try to compare them as numbers when possible + args.min do |a, b| + if a.to_s =~ %r{\A^-?\d+(.\d+)?\z} && b.to_s =~ %r{\A-?\d+(.\d+)?\z} + a.to_f <=> b.to_f + else + a.to_s <=> b.to_s + end + end + end +end diff --git a/lib/puppet/functions/stdlib/num2bool.rb b/lib/puppet/functions/stdlib/num2bool.rb new file mode 100644 index 000000000..a574d668d --- /dev/null +++ b/lib/puppet/functions/stdlib/num2bool.rb @@ -0,0 +1,69 @@ +# 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 ---- +# +# num2bool.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# This function converts a number or a string representation of a number into a +# true boolean. +# +# > *Note:* that since Puppet 5.0.0 the same can be achieved with the Puppet Type System. +# See the new() function in Puppet for the many available type conversions. +# +# @return [Boolean] +# Boolean(0) # false for any zero or negative number +# Boolean(1) # true for any positive number +# +# +Puppet::Functions.create_function(:'stdlib::num2bool') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "num2bool(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1 + + number = arguments[0] + + case number + when Numeric # rubocop:disable Lint/EmptyWhen : Required for the module to work + # Yay, it's a number + when String + begin + number = Float(number) + rescue ArgumentError => ex + raise(Puppet::ParseError, "num2bool(): '#{number}' does not look like a number: #{ex.message}") + end + else + begin + number = number.to_s + rescue NoMethodError => ex + raise(Puppet::ParseError, "num2bool(): Unable to parse argument: #{ex.message}") + end + end + + # Truncate Floats + number = number.to_i + + # Return true for any positive number and false otherwise + number > 0 + end +end diff --git a/lib/puppet/functions/stdlib/parsejson.rb b/lib/puppet/functions/stdlib/parsejson.rb new file mode 100644 index 000000000..e9a7bd9d4 --- /dev/null +++ b/lib/puppet/functions/stdlib/parsejson.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 ---- +# +# parsejson.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# This function accepts JSON as a string and converts it into the correct +# Puppet structure. +# +# @return +# convert JSON into Puppet structure +# +# > *Note:* +# The optional second argument can be used to pass a default value that will +# be returned if the parsing of YAML string have failed. +# +# +Puppet::Functions.create_function(:'stdlib::parsejson') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise ArgumentError, 'Wrong number of arguments. 1 or 2 arguments should be provided.' unless arguments.length >= 1 + + begin + PSON.load(arguments[0]) || arguments[1] + rescue StandardError => e + raise e unless arguments[1] + arguments[1] + end + end +end diff --git a/lib/puppet/functions/stdlib/parseyaml.rb b/lib/puppet/functions/stdlib/parseyaml.rb new file mode 100644 index 000000000..81f574457 --- /dev/null +++ b/lib/puppet/functions/stdlib/parseyaml.rb @@ -0,0 +1,55 @@ +# 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 ---- +# +# parseyaml.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# This function accepts YAML as a string and converts it into the correct +# Puppet structure. +# +# @return +# converted YAML into Puppet structure +# +# > *Note:* +# The optional second argument can be used to pass a default value that will +# be returned if the parsing of YAML string have failed. +# +# +Puppet::Functions.create_function(:'stdlib::parseyaml') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise ArgumentError, 'Wrong number of arguments. 1 or 2 arguments should be provided.' unless arguments.length >= 1 + require 'yaml' + + begin + YAML.load(arguments[0]) || arguments[1] # rubocop:disable Security/YAMLLoad : using YAML.safe_load causes the code to break + # in ruby 1.9.3 Psych::SyntaxError is a RuntimeException + # this still needs to catch that and work also on rubies that + # do not have Psych available. + rescue StandardError, Psych::SyntaxError => e # rubocop:disable Lint/ShadowedException : See above + raise e unless arguments[1] + arguments[1] + end + end +end diff --git a/lib/puppet/functions/stdlib/pick.rb b/lib/puppet/functions/stdlib/pick.rb new file mode 100644 index 000000000..fb9f88a70 --- /dev/null +++ b/lib/puppet/functions/stdlib/pick.rb @@ -0,0 +1,56 @@ +# 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 ---- +# +# pick.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# This function is similar to a coalesce function in SQL in that it will return +# the first value in a list of values that is not undefined or an empty string. +# +# @return +# the first value in a list of values that is not undefined or an empty string. +# +# Typically, this function is used to check for a value in the Puppet +# Dashboard/Enterprise Console, and failover to a default value like the following: +# +# ```$real_jenkins_version = pick($::jenkins_version, '1.449')``` +# +# > *Note:* +# The value of $real_jenkins_version will first look for a top-scope variable +# called 'jenkins_version' (note that parameters set in the Puppet Dashboard/ +# Enterprise Console are brought into Puppet as top-scope variables), and, +# failing that, will use a default value of 1.449. +# +# +Puppet::Functions.create_function(:'stdlib::pick') 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) + args = args.compact + args.delete(:undef) + args.delete(:undefined) + args.delete('') + raise Puppet::ParseError, 'pick(): must receive at least one non empty value' if args[0].to_s.empty? + args[0] + end +end diff --git a/lib/puppet/functions/stdlib/pick_default.rb b/lib/puppet/functions/stdlib/pick_default.rb new file mode 100644 index 000000000..4ff7e03d1 --- /dev/null +++ b/lib/puppet/functions/stdlib/pick_default.rb @@ -0,0 +1,64 @@ +# 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 ---- +# +# pick_default.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# This function will return the first value in a list of values that is not undefined or an empty string. +# +# @return +# This function is similar to a coalesce function in SQL in that it will return +# the first value in a list of values that is not undefined or an empty string +# If no value is found, it will return the last argument. +# +# Typically, this function is used to check for a value in the Puppet +# Dashboard/Enterprise Console, and failover to a default value like the +# following: +# +# $real_jenkins_version = pick_default($::jenkins_version, '1.449') +# +# > *Note:* +# The value of $real_jenkins_version will first look for a top-scope variable +# called 'jenkins_version' (note that parameters set in the Puppet Dashboard/ +# Enterprise Console are brought into Puppet as top-scope variables), and, +# failing that, will use a default value of 1.449. +# +# Contrary to the pick() function, the pick_default does not fail if +# all arguments are empty. This allows pick_default to use an empty value as +# default. +# +# +Puppet::Functions.create_function(:'stdlib::pick_default') 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) + raise 'Must receive at least one argument.' if args.empty? + default = args.last + args = args[0..-2].compact + args.delete(:undef) + args.delete(:undefined) + args.delete('') + args << default + args[0] + end +end diff --git a/lib/puppet/functions/stdlib/prefix.rb b/lib/puppet/functions/stdlib/prefix.rb new file mode 100644 index 000000000..8169e7565 --- /dev/null +++ b/lib/puppet/functions/stdlib/prefix.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 ---- +# +# prefix.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# This function applies a prefix to all elements in an array or a hash. +# +# @example **Usage** +# +# prefix(['a','b','c'], 'p') +# Will return: ['pa','pb','pc'] +# +# > *Note:* since Puppet 4.0.0 the general way to modify values is in array is by using the map +# function in Puppet. This example does the same as the example above: +# ['a', 'b', 'c'].map |$x| { "p${x}" } +# +# @return [Hash] or [Array] The passed values now contains the passed prefix +# +# +Puppet::Functions.create_function(:'stdlib::prefix') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + # Technically we support two arguments but only first is mandatory ... + raise(Puppet::ParseError, "prefix(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + + enumerable = arguments[0] + + unless enumerable.is_a?(Array) || enumerable.is_a?(Hash) + raise Puppet::ParseError, "prefix(): expected first argument to be an Array or a Hash, got #{enumerable.inspect}" + end + + prefix = arguments[1] if arguments[1] + + if prefix + unless prefix.is_a?(String) + raise Puppet::ParseError, "prefix(): expected second argument to be a String, got #{prefix.inspect}" + end + end + + result = if enumerable.is_a?(Array) + # Turn everything into string same as join would do ... + enumerable.map do |i| + i = i.to_s + prefix ? prefix + i : i + end + else + Hash[enumerable.map do |k, v| + k = k.to_s + [prefix ? prefix + k : k, v] + end] + end + + result + end +end diff --git a/lib/puppet/functions/stdlib/private.rb b/lib/puppet/functions/stdlib/private.rb new file mode 100644 index 000000000..c1731a43b --- /dev/null +++ b/lib/puppet/functions/stdlib/private.rb @@ -0,0 +1,44 @@ +# 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 ---- +# +# private.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **Deprecated:** Sets the current class or definition as private. +# Calling the class or definition from outside the current module will fail. +# +# @return +# Sets the current class or definition as private +# +# +Puppet::Functions.create_function(:'stdlib::private') 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) + warning("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 : Cannot shorten this line + unless Puppet::Parser::Functions.autoloader.loaded?(:assert_private) + Puppet::Parser::Functions.autoloader.load(:assert_private) + end + function_assert_private([(args[0] unless args.empty?)]) + end +end diff --git a/lib/puppet/functions/stdlib/pry.rb b/lib/puppet/functions/stdlib/pry.rb new file mode 100644 index 000000000..e01b104b8 --- /dev/null +++ b/lib/puppet/functions/stdlib/pry.rb @@ -0,0 +1,59 @@ +# 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 ---- +# +# pry.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# This function invokes a pry debugging session in the current scope object. +# This is useful for debugging manifest code at specific points during a compilation. +# +# @return +# debugging information +# +# @example **Usage** +# +# `pry()` +# +# +# +Puppet::Functions.create_function(:'stdlib::pry') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + begin + require 'pry' + rescue LoadError + raise(Puppet::Error, "pry(): Requires the 'pry' rubygem to use, but it was not found") + end + # + ## Run `catalog` to see the contents currently compiling catalog + ## Run `cd catalog` and `ls` to see catalog methods and instance variables + ## Run `@resource_table` to see the current catalog resource table + # + if $stdout.isatty + binding.pry # rubocop:disable Lint/Debugger + else + Puppet.warning 'pry(): cowardly refusing to start the debugger on a daemonized master' + end + end +end diff --git a/lib/puppet/functions/stdlib/pw_hash.rb b/lib/puppet/functions/stdlib/pw_hash.rb new file mode 100644 index 000000000..b0cf0428a --- /dev/null +++ b/lib/puppet/functions/stdlib/pw_hash.rb @@ -0,0 +1,92 @@ +# 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 ---- +# Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. +# To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. +# +# ---- original file header ---- +# +# @summary +# @summary +# Hashes a password using the crypt function. Provides a hash usable +# on most POSIX systems. +# +# The first argument to this function is the password to hash. If it is +# undef or an empty string, this function returns undef. +# +# The second argument to this function is which type of hash to use. It +# will be converted into the appropriate crypt(3) hash specifier. Valid +# hash types are: +# +# |Hash type |Specifier| +# |---------------------|---------| +# |MD5 |1 | +# |SHA-256 |5 | +# |SHA-512 (recommended)|6 | +# +# The third argument to this function is the salt to use. +# +# @return [Hash] +# Provides a hash usable on most POSIX systems. +# +# > *Note:*: this uses the Puppet Master's implementation of crypt(3). If your +# environment contains several different operating systems, ensure that they +# are compatible before using this function. +# +# +Puppet::Functions.create_function(:'stdlib::pw_hash') 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) + raise ArgumentError, "pw_hash(): wrong number of arguments (#{args.size} for 3)" if args.size != 3 + args.map! do |arg| + if (defined? Puppet::Pops::Types::PSensitiveType::Sensitive) && (arg.is_a? Puppet::Pops::Types::PSensitiveType::Sensitive) + arg.unwrap + else + arg + end + end + raise ArgumentError, 'pw_hash(): first argument must be a string' unless args[0].is_a?(String) || args[0].nil? + raise ArgumentError, 'pw_hash(): second argument must be a string' unless args[1].is_a? String + hashes = { 'md5' => '1', + 'sha-256' => '5', + 'sha-512' => '6' } + hash_type = hashes[args[1].downcase] + raise ArgumentError, "pw_hash(): #{args[1]} is not a valid hash type" if hash_type.nil? + raise ArgumentError, 'pw_hash(): third argument must be a string' unless args[2].is_a? String + raise ArgumentError, 'pw_hash(): third argument must not be empty' if args[2].empty? + raise ArgumentError, 'pw_hash(): characters in salt must be in the set [a-zA-Z0-9./]' unless args[2] =~ %r{\A[a-zA-Z0-9./]+\z} + + password = args[0] + return nil if password.nil? || password.empty? + + salt = "$#{hash_type}$#{args[2]}" + + # handle weak implementations of String#crypt + if 'test'.crypt('$1$1') != '$1$1$Bp8CU9Oujr9SSEw53WV6G.' + # JRuby < 1.7.17 + # MS Windows and other systems that don't support enhanced salts + raise Puppet::ParseError, 'system does not support enhanced salts' unless RUBY_PLATFORM == 'java' + # puppetserver bundles Apache Commons Codec + org.apache.commons.codec.digest.Crypt.crypt(password.to_java_bytes, salt) + else + password.crypt(salt) + end + end +end diff --git a/lib/puppet/functions/stdlib/range.rb b/lib/puppet/functions/stdlib/range.rb new file mode 100644 index 000000000..b70b0e84e --- /dev/null +++ b/lib/puppet/functions/stdlib/range.rb @@ -0,0 +1,114 @@ +# 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 ---- +# +# range.rb +# +# TODO(Krzysztof Wilczynski): We probably need to approach numeric values differently ... +# ---- original file header ---- +# +# @summary +# @summary +# When given range in the form of (start, stop) it will extrapolate a range as +# an array. +# +# @return +# the range is extrapolated as an array +# +# @example **Usage** +# range("0", "9") +# Will return: [0,1,2,3,4,5,6,7,8,9] +# +# range("00", "09") +# Will return: [0,1,2,3,4,5,6,7,8,9] +# (Zero padded strings are converted to integers automatically) +# +# range("a", "c") +# Will return: ["a","b","c"] +# +# range("host01", "host10") +# Will return: ["host01", "host02", ..., "host09", "host10"] +# +# range("0", "9", "2") +# Will return: [0,2,4,6,8] +# +# NB Be explicit in including trailing zeros. Otherwise the underlying ruby function will fail. +# +# > *Note:* +# Passing a third argument will cause the generated range to step by that +# interval, e.g. +# +# The Puppet Language support Integer and Float ranges by using the type system. Those are suitable for +# iterating a given number of times. +# +# @see +# the step() function in Puppet for skipping values. +# +# Integer[0, 9].each |$x| { notice($x) } # notices 0, 1, 2, ... 9 +# +# +Puppet::Functions.create_function(:'stdlib::range') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, 'range(): Wrong number of arguments given (0 for 1)') if arguments.empty? + + if arguments.size > 1 + start = arguments[0] + stop = arguments[1] + step = arguments[2].nil? ? 1 : arguments[2].to_i.abs + + type = '..' # Use the simplest type of Range available in Ruby + + else # arguments.size == 1 + value = arguments[0] + + m = value.match(%r{^(\w+)(\.\.\.?|\-)(\w+)$}) + if m + start = m[1] + stop = m[3] + + type = m[2] + step = 1 + elsif value =~ %r{^.+$} + raise(Puppet::ParseError, "range(): Unable to compute range from the value: #{value}") + else + raise(Puppet::ParseError, "range(): Unknown range format: #{value}") + end + end + + # If we were given an integer, ensure we work with one + if start.to_s =~ %r{^\d+$} + start = start.to_i + stop = stop.to_i + else + start = start.to_s + stop = stop.to_s + end + + range = case type + when %r{^(..|-)$} then (start..stop) + when '...' then (start...stop) # Exclusive of last element + end + + result = range.step(step).first(1_000_000).to_a + + result + end +end diff --git a/lib/puppet/functions/stdlib/regexpescape.rb b/lib/puppet/functions/stdlib/regexpescape.rb new file mode 100644 index 000000000..9c1913a90 --- /dev/null +++ b/lib/puppet/functions/stdlib/regexpescape.rb @@ -0,0 +1,54 @@ +# 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 ---- +# +# regexpescape.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Regexp escape a string or array of strings. +# Requires either a single string or an array as an input. +# @return [String] +# A string of characters with metacharacters converted to their escaped form. +# +# +Puppet::Functions.create_function(:'stdlib::regexpescape') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "regexpescape(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + + value = arguments[0] + + unless value.is_a?(Array) || value.is_a?(String) + raise(Puppet::ParseError, 'regexpescape(): Requires either array or string to work with') + end + + result = if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... + value.map { |i| i.is_a?(String) ? Regexp.escape(i) : i } + else + Regexp.escape(value) + end + + result + end +end diff --git a/lib/puppet/functions/stdlib/reject.rb b/lib/puppet/functions/stdlib/reject.rb new file mode 100644 index 000000000..0cf32246d --- /dev/null +++ b/lib/puppet/functions/stdlib/reject.rb @@ -0,0 +1,58 @@ +# 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 ---- +# +# reject.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# This function searches through an array and rejects all elements that match +# the provided regular expression. +# +# @return +# an array containing all the elements which doesn'' match the provided regular expression +# +# @example **Usage** +# +# reject(['aaa','bbb','ccc','aaaddd'], 'aaa') +# +# Would return: ['bbb','ccc'] +# +# > *Note:* +# Since Puppet 4.0.0 the same is in general done with the filter function. Here is the equivalence of the reject() function: +# ['aaa','bbb','ccc','aaaddd'].filter |$x| { $x !~ /aaa/ } +# +# +Puppet::Functions.create_function(:'stdlib::reject') 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.size != 2 + raise Puppet::ParseError, + "reject(): Wrong number of arguments given #{args.size} for 2" + end + + ary = args[0] + pattern = Regexp.new(args[1]) + + ary.reject { |e| e =~ pattern } + end +end diff --git a/lib/puppet/functions/stdlib/reverse.rb b/lib/puppet/functions/stdlib/reverse.rb new file mode 100644 index 000000000..37e0a3f32 --- /dev/null +++ b/lib/puppet/functions/stdlib/reverse.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 ---- +# +# reverse.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Reverses the order of a string or array. +# +# @return +# reversed string or array +# +# > *Note:* that the same can be done with the reverse_each() function in Puppet. +# +# +Puppet::Functions.create_function(:'stdlib::reverse') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "reverse(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + + value = arguments[0] + + unless value.is_a?(Array) || value.is_a?(String) + raise(Puppet::ParseError, 'reverse(): Requires either array or string to work with') + end + + result = value.reverse + + result + end +end diff --git a/lib/puppet/functions/stdlib/round.rb b/lib/puppet/functions/stdlib/round.rb new file mode 100644 index 000000000..2563e75c0 --- /dev/null +++ b/lib/puppet/functions/stdlib/round.rb @@ -0,0 +1,57 @@ +# 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 ---- +# +# round.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Rounds a number to the nearest integer +# +# @return +# the rounded value as integer +# +# @example +# +# ```round(2.9)``` returns ```3``` +# +# ```round(2.4)``` returns ```2``` +# +# > *Note:* from Puppet 6.0.0, the compatible function with the same name in Puppet core +# will be used instead of this function. +# +# +Puppet::Functions.create_function(:'stdlib::round') 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) + raise Puppet::ParseError, "round(): Wrong number of arguments given #{args.size} for 1" if args.size != 1 + raise Puppet::ParseError, "round(): Expected a Numeric, got #{args[0].class}" unless args[0].is_a? Numeric + + value = args[0] + + if value >= 0 + Integer(value + 0.5) + else + Integer(value - 0.5) + end + end +end diff --git a/lib/puppet/functions/stdlib/rstrip.rb b/lib/puppet/functions/stdlib/rstrip.rb new file mode 100644 index 000000000..21f5750ee --- /dev/null +++ b/lib/puppet/functions/stdlib/rstrip.rb @@ -0,0 +1,56 @@ +# 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 ---- +# +# rstrip.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Strips leading spaces to the right of the string. +# +# @return +# the string with leading spaces removed +# +# > *Note:* from Puppet 6.0.0, the compatible function with the same name in Puppet core +# will be used instead of this function. +# +# +Puppet::Functions.create_function(:'stdlib::rstrip') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "rstrip(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + + value = arguments[0] + + unless value.is_a?(Array) || value.is_a?(String) + raise(Puppet::ParseError, 'rstrip(): Requires either array or string to work with') + end + + result = if value.is_a?(Array) + value.map { |i| i.is_a?(String) ? i.rstrip : i } + else + value.rstrip + end + + result + end +end diff --git a/lib/puppet/functions/stdlib/seeded_rand.rb b/lib/puppet/functions/stdlib/seeded_rand.rb new file mode 100644 index 000000000..c98009fcf --- /dev/null +++ b/lib/puppet/functions/stdlib/seeded_rand.rb @@ -0,0 +1,54 @@ +# 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 ---- +# +# seeded_rand.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Generates a random whole number greater than or equal to 0 and less than MAX, using the value of SEED for repeatable randomness. +# +# @return +# random number greater than or equal to 0 and less than MAX +# +# @example **Usage:** +# seeded_rand(MAX, SEED). +# MAX must be a positive integer; SEED is any string. +# +# Generates a random whole number greater than or equal to 0 and less +# than MAX, using the value of SEED for repeatable randomness. If SEED +# starts with "$fqdn:", this is behaves the same as `fqdn_rand`. +# +# +Puppet::Functions.create_function(:'stdlib::seeded_rand') 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) + require 'digest/md5' + + raise(ArgumentError, 'seeded_rand(): first argument must be a positive integer') unless function_is_integer([args[0]]) && args[0].to_i > 0 + raise(ArgumentError, 'seeded_rand(): second argument must be a string') unless args[1].is_a? String + + max = args[0].to_i + seed = Digest::MD5.hexdigest(args[1]).hex + Puppet::Util.deterministic_rand(seed, max) + end +end diff --git a/lib/puppet/functions/stdlib/shell_escape.rb b/lib/puppet/functions/stdlib/shell_escape.rb new file mode 100644 index 000000000..3850b9c21 --- /dev/null +++ b/lib/puppet/functions/stdlib/shell_escape.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 ---- +require 'shellwords' +# +# shell_escape.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Escapes a string so that it can be safely used in a Bourne shell command line. +# +# @return +# A string of characters with metacharacters converted to their escaped form. +# +# >* Note:* that the resulting string should be used unquoted and is not intended for use in double quotes nor in single +# quotes. +# +# This function behaves the same as ruby's Shellwords.shellescape() function. +# +# +Puppet::Functions.create_function(:'stdlib::shell_escape') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "shell_escape(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1 + + # explicit conversion to string is required for ruby 1.9 + string = arguments[0].to_s + + result = Shellwords.shellescape(string) + + result + end +end diff --git a/lib/puppet/functions/stdlib/shell_join.rb b/lib/puppet/functions/stdlib/shell_join.rb new file mode 100644 index 000000000..caf82b052 --- /dev/null +++ b/lib/puppet/functions/stdlib/shell_join.rb @@ -0,0 +1,53 @@ +# 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 'shellwords' +# +# shell_join.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Builds a command line string from the given array of strings. +# Each array item is escaped for Bourne shell. All items are then joined together, with a single space in between. +# This function behaves the same as ruby's Shellwords.shelljoin() function +# +# @return +# a command line string +# +# +Puppet::Functions.create_function(:'stdlib::shell_join') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "shell_join(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1 + + array = arguments[0] + + raise Puppet::ParseError, "First argument is not an Array: #{array.inspect}" unless array.is_a?(Array) + + # explicit conversion to string is required for ruby 1.9 + array = array.map { |item| item.to_s } + result = Shellwords.shelljoin(array) + + result + end +end diff --git a/lib/puppet/functions/stdlib/shell_split.rb b/lib/puppet/functions/stdlib/shell_split.rb new file mode 100644 index 000000000..7d87357a8 --- /dev/null +++ b/lib/puppet/functions/stdlib/shell_split.rb @@ -0,0 +1,48 @@ +# 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 'shellwords' +# +# shell_split.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Splits a string into an array of tokens in the same way the Bourne shell does. +# +# @return +# array of tokens +# +# This function behaves the same as ruby's Shellwords.shellsplit() function +# +# +Puppet::Functions.create_function(:'stdlib::shell_split') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "shell_split(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1 + + string = arguments[0].to_s + + result = Shellwords.shellsplit(string) + + result + end +end diff --git a/lib/puppet/functions/stdlib/shuffle.rb b/lib/puppet/functions/stdlib/shuffle.rb new file mode 100644 index 000000000..c059fbbba --- /dev/null +++ b/lib/puppet/functions/stdlib/shuffle.rb @@ -0,0 +1,67 @@ +# 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 ---- +# +# shuffle.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Randomizes the order of a string or array elements. +# +# @return +# randomized string or array +# +# +Puppet::Functions.create_function(:'stdlib::shuffle') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "shuffle(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + + value = arguments[0] + + unless value.is_a?(Array) || value.is_a?(String) + raise(Puppet::ParseError, 'shuffle(): Requires either array or string to work with') + end + + result = value.clone + + string = value.is_a?(String) ? true : false + + # Check whether it makes sense to shuffle ... + return result if result.size <= 1 + + # We turn any string value into an array to be able to shuffle ... + result = string ? result.split('') : result + + elements = result.size + + # Simple implementation of Fisher–Yates in-place shuffle ... + elements.times do |i| + j = rand(elements - i) + i + result[j], result[i] = result[i], result[j] + end + + result = string ? result.join : result + + result + end +end diff --git a/lib/puppet/functions/stdlib/size.rb b/lib/puppet/functions/stdlib/size.rb new file mode 100644 index 000000000..84165fee6 --- /dev/null +++ b/lib/puppet/functions/stdlib/size.rb @@ -0,0 +1,72 @@ +# 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 ---- +# +# size.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Returns the number of elements in a string, an array or a hash +# +# @return +# the number of elements in a string, an array or a hash +# +# > *Note:* that since Puppet 5.4.0, the length() function in Puppet is preferred over this. For versions +# of Puppet < 5.4.0 use the stdlib length() function. +# +# +Puppet::Functions.create_function(:'stdlib::size') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "size(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + + item = arguments[0] + + function_deprecation([:size, 'This method is going to be deprecated, please use the stdlib length function.']) + + if item.is_a?(String) + + begin + # + # Check whether your item is a numeric value or not ... + # This will take care about positive and/or negative numbers + # for both integer and floating-point values ... + # + # Please note that Puppet has no notion of hexadecimal + # nor octal numbers for its DSL at this point in time ... + # + Float(item) + + raise(Puppet::ParseError, 'size(): Requires either string, array or hash to work with') + rescue ArgumentError + result = item.size + end + + elsif item.is_a?(Array) || item.is_a?(Hash) + result = item.size + else + raise(Puppet::ParseError, 'size(): Unknown type given') + end + + result + end +end diff --git a/lib/puppet/functions/stdlib/sort.rb b/lib/puppet/functions/stdlib/sort.rb new file mode 100644 index 000000000..bb2fb28aa --- /dev/null +++ b/lib/puppet/functions/stdlib/sort.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 ---- +# +# sort.rb +# Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. +# +# ---- original file header ---- +# +# @summary +# @summary +# Sorts strings and arrays lexically. +# +# @return +# sorted string or array +# +# Note that from Puppet 6.0.0 the same function in Puppet will be used instead of this. +# +# +Puppet::Functions.create_function(:'stdlib::sort') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + if arguments.size != 1 + raise(Puppet::ParseError, "sort(): Wrong number of arguments given #{arguments.size} for 1") + end + + value = arguments[0] + + if value.is_a?(Array) + value.sort + elsif value.is_a?(String) + value.split('').sort.join('') + end + end +end diff --git a/lib/puppet/functions/stdlib/squeeze.rb b/lib/puppet/functions/stdlib/squeeze.rb new file mode 100644 index 000000000..bb558949d --- /dev/null +++ b/lib/puppet/functions/stdlib/squeeze.rb @@ -0,0 +1,56 @@ +# 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 ---- +# +# squeeze.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Returns a new string where runs of the same character that occur in this set are replaced by a single character. +# +# @return +# a new string where runs of the same character that occur in this set are replaced by a single character. +# +# +Puppet::Functions.create_function(:'stdlib::squeeze') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + if (arguments.size != 2) && (arguments.size != 1) + raise(Puppet::ParseError, "squeeze(): Wrong number of arguments given #{arguments.size} for 2 or 1") + end + + item = arguments[0] + squeezeval = arguments[1] + + if item.is_a?(Array) + if squeezeval + item.map { |i| i.squeeze(squeezeval) } + else + item.map { |i| i.squeeze } + end + elsif squeezeval + item.squeeze(squeezeval) + else + item.squeeze + end + end +end diff --git a/lib/puppet/functions/stdlib/str2bool.rb b/lib/puppet/functions/stdlib/str2bool.rb new file mode 100644 index 000000000..727c9106f --- /dev/null +++ b/lib/puppet/functions/stdlib/str2bool.rb @@ -0,0 +1,70 @@ +# 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 ---- +# +# str2bool.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# This converts a string to a boolean. +# +# @return +# This attempt to convert to boolean strings that contain things like: Y,y, 1, T,t, TRUE,true to 'true' and strings that contain things +# like: 0, F,f, N,n, false, FALSE, no to 'false'. +# +# > *Note:* that since Puppet 5.0.0 the Boolean data type can convert strings to a Boolean value. +# See the function new() in Puppet for details what the Boolean data type supports. +# +# +Puppet::Functions.create_function(:'stdlib::str2bool') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "str2bool(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + + string = arguments[0] + + # If string is already Boolean, return it + if !!string == string # rubocop:disable Style/DoubleNegation : No viable alternative + return string + end + + unless string.is_a?(String) + raise(Puppet::ParseError, 'str2bool(): Requires string to work with') + end + + # We consider all the yes, no, y, n and so on too ... + result = case string + # + # This is how undef looks like in Puppet ... + # We yield false in this case. + # + when %r{^$}, '' then false # Empty string will be false ... + when %r{^(1|t|y|true|yes)$}i then true + when %r{^(0|f|n|false|no)$}i then false + when %r{^(undef|undefined)$} then false # This is not likely to happen ... + else + raise(Puppet::ParseError, 'str2bool(): Unknown type of boolean given') + end + + result + end +end diff --git a/lib/puppet/functions/stdlib/str2saltedsha512.rb b/lib/puppet/functions/stdlib/str2saltedsha512.rb new file mode 100644 index 000000000..69668d54d --- /dev/null +++ b/lib/puppet/functions/stdlib/str2saltedsha512.rb @@ -0,0 +1,58 @@ +# 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 ---- +# +# str2saltedsha512.rb +# Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. +# +# ---- original file header ---- +# +# @summary +# @summary +# This converts a string to a salted-SHA512 password hash (which is used for +# OS X versions >= 10.7). +# +# @return +# converted string as a hex version of a salted-SHA512 password hash +# +# Given any simple string, you will get a hex version +# of a salted-SHA512 password hash that can be inserted into your Puppet +# manifests as a valid password attribute. +# +# +Puppet::Functions.create_function(:'stdlib::str2saltedsha512') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + require 'digest/sha2' + + raise(Puppet::ParseError, "str2saltedsha512(): Wrong number of arguments passed (#{arguments.size} but we require 1)") if arguments.size != 1 + + password = arguments[0] + + unless password.is_a?(String) + raise(Puppet::ParseError, "str2saltedsha512(): Requires a String argument, you passed: #{password.class}") + end + + seedint = rand(2**31 - 1) + seedstring = Array(seedint).pack('L') + saltedpass = Digest::SHA512.digest(seedstring + password) + (seedstring + saltedpass).unpack('H*')[0] + end +end diff --git a/lib/puppet/functions/stdlib/strftime.rb b/lib/puppet/functions/stdlib/strftime.rb new file mode 100644 index 000000000..b82550af5 --- /dev/null +++ b/lib/puppet/functions/stdlib/strftime.rb @@ -0,0 +1,129 @@ +# 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 ---- +# +# strftime.rb +# Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. +# +# ---- original file header ---- +# +# @summary +# @summary +# This function returns formatted time. +# +# @return +# converted time according to the directives in the given format string +# +# > *Note:* that since Puppet 4.8.0 the function with the same name in Puppet will be used instead of this +# function. It also supports the Timestamp and Timespan data types in the Puppet language. +# +# @example **Usage** +# +# To return the time since epoch: strftime("%s") +# To return the date: strftime("%Y-%m-%d") +# +# **Format meaning:** +# +# %a - The abbreviated weekday name (``Sun'') +# %A - The full weekday name (``Sunday'') +# %b - The abbreviated month name (``Jan'') +# %B - The full month name (``January'') +# %c - The preferred local date and time representation +# %C - Century (20 in 2009) +# %d - Day of the month (01..31) +# %D - Date (%m/%d/%y) +# %e - Day of the month, blank-padded ( 1..31) +# %F - Equivalent to %Y-%m-%d (the ISO 8601 date format) +# %h - Equivalent to %b +# %H - Hour of the day, 24-hour clock (00..23) +# %I - Hour of the day, 12-hour clock (01..12) +# %j - Day of the year (001..366) +# %k - hour, 24-hour clock, blank-padded ( 0..23) +# %l - hour, 12-hour clock, blank-padded ( 0..12) +# %L - Millisecond of the second (000..999) +# %m - Month of the year (01..12) +# %M - Minute of the hour (00..59) +# %n - Newline ( +# ) +# %N - Fractional seconds digits, default is 9 digits (nanosecond) +# %3N millisecond (3 digits) +# %6N microsecond (6 digits) +# %9N nanosecond (9 digits) +# %p - Meridian indicator (``AM'' or ``PM'') +# %P - Meridian indicator (``am'' or ``pm'') +# %r - time, 12-hour (same as %I:%M:%S %p) +# %R - time, 24-hour (%H:%M) +# %s - Number of seconds since 1970-01-01 00:00:00 UTC. +# %S - Second of the minute (00..60) +# %t - Tab character ( ) +# %T - time, 24-hour (%H:%M:%S) +# %u - Day of the week as a decimal, Monday being 1. (1..7) +# %U - Week number of the current year, +# starting with the first Sunday as the first +# day of the first week (00..53) +# %v - VMS date (%e-%b-%Y) +# %V - Week number of year according to ISO 8601 (01..53) +# %W - Week number of the current year, +# starting with the first Monday as the first +# day of the first week (00..53) +# %w - Day of the week (Sunday is 0, 0..6) +# %x - Preferred representation for the date alone, no time +# %X - Preferred representation for the time alone, no date +# %y - Year without a century (00..99) +# %Y - Year with century +# %z - Time zone as hour offset from UTC (e.g. +0900) +# %Z - Time zone name +# %% - Literal ``%'' character +# +# +Puppet::Functions.create_function(:'stdlib::strftime') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + # Technically we support two arguments but only first is mandatory ... + raise(Puppet::ParseError, "strftime(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + + format = arguments[0] + + raise(Puppet::ParseError, 'strftime(): You must provide format for evaluation') if format.empty? + + # The Time Zone argument is optional ... + time_zone = arguments[1] if arguments[1] + + time = Time.new + + # There is probably a better way to handle Time Zone ... + if time_zone && !time_zone.empty? + original_zone = ENV['TZ'] + + local_time = time.clone + local_time = local_time.utc + + ENV['TZ'] = time_zone + + time = local_time.localtime + + ENV['TZ'] = original_zone + end + + result = time.strftime(format) + + result + end +end diff --git a/lib/puppet/functions/stdlib/strip.rb b/lib/puppet/functions/stdlib/strip.rb new file mode 100644 index 000000000..52a94254e --- /dev/null +++ b/lib/puppet/functions/stdlib/strip.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 ---- +# +# strip.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# This function removes leading and trailing whitespace from a string or from +# every string inside an array. +# +# @return +# String or Array converted +# +# @example **Usage** +# +# strip(" aaa ") +# Would result in: "aaa" +# +# > *Note:*: from Puppet 6.0.0, the compatible function with the same name in Puppet core +# will be used instead of this function. +# +# +Puppet::Functions.create_function(:'stdlib::strip') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "strip(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + + value = arguments[0] + + unless value.is_a?(Array) || value.is_a?(String) + raise(Puppet::ParseError, 'strip(): Requires either array or string to work with') + end + + result = if value.is_a?(Array) + value.map { |i| i.is_a?(String) ? i.strip : i } + else + value.strip + end + + result + end +end diff --git a/lib/puppet/functions/stdlib/suffix.rb b/lib/puppet/functions/stdlib/suffix.rb new file mode 100644 index 000000000..4e8ae8f14 --- /dev/null +++ b/lib/puppet/functions/stdlib/suffix.rb @@ -0,0 +1,81 @@ +# 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 ---- +# +# suffix.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# This function applies a suffix to all elements in an array, or to the keys +# in a hash. +# +# @return +# Array or Hash with updated elements containing the passed suffix +# +# @example **Usage** +# +# suffix(['a','b','c'], 'p') +# Will return: ['ap','bp','cp'] +# +# > *Note:* that since Puppet 4.0.0 the general way to modify values is in array is by using the map +# function in Puppet. This example does the same as the example above: +# +# ```['a', 'b', 'c'].map |$x| { "${x}p" }``` +# +# +# +Puppet::Functions.create_function(:'stdlib::suffix') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + # Technically we support two arguments but only first is mandatory ... + raise(Puppet::ParseError, "suffix(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + + enumerable = arguments[0] + + unless enumerable.is_a?(Array) || enumerable.is_a?(Hash) + raise Puppet::ParseError, "suffix(): expected first argument to be an Array or a Hash, got #{enumerable.inspect}" + end + + suffix = arguments[1] if arguments[1] + + if suffix + unless suffix.is_a? String + raise Puppet::ParseError, "suffix(): expected second argument to be a String, got #{suffix.inspect}" + end + end + + result = if enumerable.is_a?(Array) + # Turn everything into string same as join would do ... + enumerable.map do |i| + i = i.to_s + suffix ? i + suffix : i + end + else + Hash[enumerable.map do |k, v| + k = k.to_s + [suffix ? k + suffix : k, v] + end] + end + + result + end +end diff --git a/lib/puppet/functions/stdlib/swapcase.rb b/lib/puppet/functions/stdlib/swapcase.rb new file mode 100644 index 000000000..fb2245789 --- /dev/null +++ b/lib/puppet/functions/stdlib/swapcase.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 ---- +# +# swapcase.rb +# Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. +# +# ---- original file header ---- +# +# @summary +# @summary +# This function will swap the existing case of a string. +# +# @return +# string with uppercase alphabetic characters converted to lowercase and lowercase characters converted to uppercase +# +# @example **Usage** +# +# swapcase("aBcD") +# Would result in: "AbCd" +# +# +Puppet::Functions.create_function(:'stdlib::swapcase') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "swapcase(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + + value = arguments[0] + + unless value.is_a?(Array) || value.is_a?(String) + raise(Puppet::ParseError, 'swapcase(): Requires either array or string to work with') + end + + result = if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... + value.map { |i| i.is_a?(String) ? i.swapcase : i } + else + value.swapcase + end + + result + end +end diff --git a/lib/puppet/functions/stdlib/time.rb b/lib/puppet/functions/stdlib/time.rb new file mode 100644 index 000000000..c11e97925 --- /dev/null +++ b/lib/puppet/functions/stdlib/time.rb @@ -0,0 +1,79 @@ +# 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 ---- +# +# time.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# This function will return the current time since epoch as an integer. +# +# @return +# the current time since epoch as an integer. +# +# @example **Usage** +# +# time() +# Will return something like: 1311972653 +# +# > *Note:* that since Puppet 4.8.0 the Puppet language has the data types Timestamp (a point in time) and +# Timespan (a duration). The following example is equivalent to calling time() without +# any arguments: +# +# ```Timestamp()``` +# +# +# +Puppet::Functions.create_function(:'stdlib::time') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + # The Time Zone argument is optional ... + time_zone = arguments[0] if arguments[0] + + if !arguments.empty? && (arguments.size != 1) + raise(Puppet::ParseError, "time(): Wrong number of arguments given #{arguments.size} for 0 or 1") + end + + time = Time.new + + # There is probably a better way to handle Time Zone ... + if time_zone && !time_zone.empty? + original_zone = ENV['TZ'] + + local_time = time.clone + local_time = local_time.utc + + ENV['TZ'] = time_zone + + result = local_time.localtime.strftime('%s') + + ENV['TZ'] = original_zone + else + result = time.localtime.strftime('%s') + end + + # Calling Time#to_i on a receiver changes it. Trust me I am the Doctor. + result = result.to_i + + result + end +end diff --git a/lib/puppet/functions/stdlib/to_bytes.rb b/lib/puppet/functions/stdlib/to_bytes.rb new file mode 100644 index 000000000..d930cd0d3 --- /dev/null +++ b/lib/puppet/functions/stdlib/to_bytes.rb @@ -0,0 +1,61 @@ +# 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_bytes.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Converts the argument into bytes, for example 4 kB becomes 4096. +# +# @return +# converted value into bytes +# +# Takes a single string value as an argument. +# These conversions reflect a layperson's understanding of +# 1 MB = 1024 KB, when in fact 1 MB = 1000 KB, and 1 MiB = 1024 KiB. +# +# +Puppet::Functions.create_function(:'stdlib::to_bytes') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "to_bytes(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1 + + arg = arguments[0] + + return arg if arg.is_a? Numeric + + value, prefix = *%r{([0-9.e+-]*)\s*([^bB]?)}.match(arg)[1, 2] + + value = value.to_f + case prefix + when '' then return value.to_i + when 'k' then return (value * (1 << 10)).to_i + when 'M' then return (value * (1 << 20)).to_i + when 'G' then return (value * (1 << 30)).to_i + when 'T' then return (value * (1 << 40)).to_i + when 'P' then return (value * (1 << 50)).to_i + when 'E' then return (value * (1 << 60)).to_i + else raise Puppet::ParseError, "to_bytes(): Unknown prefix #{prefix}" + end + end +end diff --git a/lib/puppet/functions/stdlib/try_get_value.rb b/lib/puppet/functions/stdlib/try_get_value.rb new file mode 100644 index 000000000..bc34f7e00 --- /dev/null +++ b/lib/puppet/functions/stdlib/try_get_value.rb @@ -0,0 +1,80 @@ +# 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 ---- +# +# try_get_value.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **DEPRECATED:** this function is deprecated, please use dig() instead. +# +# @return +# Looks up into a complex structure of arrays and hashes and returns a value +# or the default value if nothing was found. +# +# Key can contain slashes to describe path components. The function will go down +# the structure and try to extract the required value. +# `` +# $data = { +# 'a' => { +# 'b' => [ +# 'b1', +# 'b2', +# 'b3', +# ] +# } +# } +# +# $value = try_get_value($data, 'a/b/2', 'not_found', '/') +# => $value = 'b3' +# ``` +# ``` +# a -> first hash key +# b -> second hash key +# 2 -> array index starting with 0 +# +# not_found -> (optional) will be returned if there is no value or the path did not match. Defaults to nil. +# / -> (optional) path delimiter. Defaults to '/'. +# ``` +# +# In addition to the required "key" argument, "try_get_value" accepts default +# argument. It will be returned if no value was found or a path component is +# missing. And the fourth argument can set a variable path separator. +# +# +Puppet::Functions.create_function(:'stdlib::try_get_value') 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) + warning('try_get_value() DEPRECATED: this function is deprecated, please use dig() instead.') + data = args[0] + path = args[1] || '' + default = args[2] + + if !(data.is_a?(Hash) || data.is_a?(Array)) || path == '' + return default || data + end + + separator = args[3] || '/' + path = path.split(separator).map { |key| (key =~ %r{^\d+$}) ? key.to_i : key } + function_dig([data, path, default]) + end +end diff --git a/lib/puppet/functions/stdlib/type.rb b/lib/puppet/functions/stdlib/type.rb new file mode 100644 index 000000000..0b83c1a92 --- /dev/null +++ b/lib/puppet/functions/stdlib/type.rb @@ -0,0 +1,50 @@ +# 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 ---- +# +# type.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **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. +# +# @return the type when passed a value. Type can be one of: +# +# * string +# * array +# * hash +# * float +# * integer +# * boolean +# +# +Puppet::Functions.create_function(:'stdlib::type') 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) + warning("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 : Cannot reduce line length + unless Puppet::Parser::Functions.autoloader.loaded?(:type3x) + Puppet::Parser::Functions.autoloader.load(:type3x) + end + function_type3x(args) + end +end diff --git a/lib/puppet/functions/stdlib/type3x.rb b/lib/puppet/functions/stdlib/type3x.rb new file mode 100644 index 000000000..9bb55e9ec --- /dev/null +++ b/lib/puppet/functions/stdlib/type3x.rb @@ -0,0 +1,72 @@ +# 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 ---- +# +# type3x.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# **DEPRECATED:** This function will be removed when Puppet 3 support is dropped; please migrate to the new parser's typing system. +# +# @return the type when passed a value. Type can be one of: +# +# * string +# * array +# * hash +# * float +# * integer +# * boolean +# +# +Puppet::Functions.create_function(:'stdlib::type3x') 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) + raise(Puppet::ParseError, "type3x(): Wrong number of arguments given (#{args.size} for 1)") unless args.size == 1 + + value = args[0] + + klass = value.class + + unless [TrueClass, FalseClass, Array, Bignum, Fixnum, Float, Hash, String].include?(klass) # rubocop:disable Lint/UnifiedInteger + raise(Puppet::ParseError, 'type3x(): Unknown type') + end + + klass = klass.to_s # Ugly ... + + # We note that Integer is the parent to Bignum and Fixnum ... + result = case klass + when %r{^(?:Big|Fix)num$} then 'integer' + when %r{^(?:True|False)Class$} then 'boolean' + else klass + end + + if result == 'String' + if value == value.to_i.to_s + result = 'Integer' + elsif value == value.to_f.to_s + result = 'Float' + end + end + + result.downcase + end +end diff --git a/lib/puppet/functions/stdlib/union.rb b/lib/puppet/functions/stdlib/union.rb new file mode 100644 index 000000000..ca47ea7fd --- /dev/null +++ b/lib/puppet/functions/stdlib/union.rb @@ -0,0 +1,50 @@ +# 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 ---- +# +# union.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# This function returns a union of two or more arrays. +# +# @return +# a unionized array of two or more arrays +# @example **Usage** +# +# union(["a","b","c"],["b","c","d"]) +# Would return: ["a","b","c","d"] +# +# +Puppet::Functions.create_function(:'stdlib::union') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + # Check that 2 or more arguments have been given ... + raise(Puppet::ParseError, "union(): Wrong number of arguments given (#{arguments.size} for < 2)") if arguments.size < 2 + + arguments.each do |argument| + raise(Puppet::ParseError, 'union(): Every parameter must be an array') unless argument.is_a?(Array) + end + + arguments.reduce(:|) + end +end diff --git a/lib/puppet/functions/stdlib/unique.rb b/lib/puppet/functions/stdlib/unique.rb new file mode 100644 index 000000000..7c11bb646 --- /dev/null +++ b/lib/puppet/functions/stdlib/unique.rb @@ -0,0 +1,71 @@ +# 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 ---- +# +# unique.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# This function will remove duplicates from strings and arrays. +# +# @return +# String or array with duplicates removed +# +# @example **Usage** +# +# unique("aabbcc") +# Will return: abc +# +# You can also use this with arrays: +# +# unique(["a","a","b","b","c","c"]) +# This returns: ["a","b","c"] +# +# +# +Puppet::Functions.create_function(:'stdlib::unique') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + if Puppet::Util::Package.versioncmp(Puppet.version, '5.0.0') >= 0 + function_deprecation([:unique, 'This method is deprecated, please use the core puppet unique function. There is further documentation for the function in the release notes of Puppet 5.0.']) + end + + raise(Puppet::ParseError, "unique(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + + value = arguments[0] + + unless value.is_a?(Array) || value.is_a?(String) + raise(Puppet::ParseError, 'unique(): Requires either array or string to work with') + end + + result = value.clone + + string = value.is_a?(String) ? true : false + + # We turn any string value into an array to be able to shuffle ... + result = string ? result.split('') : result + result = result.uniq # Remove duplicates ... + result = string ? result.join : result + + result + end +end diff --git a/lib/puppet/functions/stdlib/unix2dos.rb b/lib/puppet/functions/stdlib/unix2dos.rb new file mode 100644 index 000000000..1e6c30e76 --- /dev/null +++ b/lib/puppet/functions/stdlib/unix2dos.rb @@ -0,0 +1,43 @@ +# 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 ---- +# Custom Puppet function to convert unix to dos format +# ---- original file header ---- +# +# @summary +# @summary +# Returns the DOS version of the given string. +# +# @return +# the DOS version of the given string. +# +# Takes a single string argument. +# +# +Puppet::Functions.create_function(:'stdlib::unix2dos') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + unless arguments[0].is_a?(String) + raise(Puppet::ParseError, 'unix2dos(): Requires string as argument') + end + + arguments[0].gsub(%r{\r*\n}, "\r\n") + end +end diff --git a/lib/puppet/functions/stdlib/upcase.rb b/lib/puppet/functions/stdlib/upcase.rb new file mode 100644 index 000000000..0168cb4e9 --- /dev/null +++ b/lib/puppet/functions/stdlib/upcase.rb @@ -0,0 +1,68 @@ +# 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 ---- +# +# upcase.rb +# Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. +# +# ---- original file header ---- +# +# @summary +# @summary +# Converts a string or an array of strings to uppercase. +# +# @return +# converted string ot array of strings to uppercase +# +# @example **Usage** +# +# upcase("abcd") +# Will return ABCD +# +# > *Note:* from Puppet 6.0.0, the compatible function with the same name in Puppet core +# will be used instead of this function. +# +# +Puppet::Functions.create_function(:'stdlib::upcase') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "upcase(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1 + + value = arguments[0] + + unless value.is_a?(Array) || value.is_a?(Hash) || value.respond_to?(:upcase) + raise(Puppet::ParseError, 'upcase(): Requires an array, hash or object that responds to upcase in order to work') + end + + if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... + result = value.map { |i| function_upcase([i]) } + elsif value.is_a?(Hash) + result = {} + value.each_pair do |k, v| + result[function_upcase([k])] = function_upcase([v]) + end + else + result = value.upcase + end + + result + end +end diff --git a/lib/puppet/functions/stdlib/uriescape.rb b/lib/puppet/functions/stdlib/uriescape.rb new file mode 100644 index 000000000..3151ea5fb --- /dev/null +++ b/lib/puppet/functions/stdlib/uriescape.rb @@ -0,0 +1,58 @@ +# 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 'uri' +# +# uriescape.rb +# Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. +# +# ---- original file header ---- +# +# @summary +# @summary +# Urlencodes a string or array of strings. +# Requires either a single string or an array as an input. +# +# @return [String] +# a string that contains the converted value +# +# +# +Puppet::Functions.create_function(:'stdlib::uriescape') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "uriescape(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + + value = arguments[0] + + unless value.is_a?(Array) || value.is_a?(String) + raise(Puppet::ParseError, 'uriescape(): Requires either array or string to work with') + end + + result = if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... + value.map { |i| i.is_a?(String) ? URI.escape(i) : i } + else + URI.escape(value) + end + + result + end +end diff --git a/lib/puppet/functions/stdlib/validate_absolute_path.rb b/lib/puppet/functions/stdlib/validate_absolute_path.rb new file mode 100644 index 000000000..cc80ad397 --- /dev/null +++ b/lib/puppet/functions/stdlib/validate_absolute_path.rb @@ -0,0 +1,83 @@ +# 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 ---- +# +# validate_absolute_path.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Validate the string represents an absolute path in the filesystem. This function works +# for windows and unix style paths. +# +# @return +# passes when the string is an absolute path or raise an error when it is not and fails compilation +# +# @example **Usage** +# +# The following values will pass: +# +# $my_path = 'C:/Program Files (x86)/Puppet Labs/Puppet' +# validate_absolute_path($my_path) +# $my_path2 = '/var/lib/puppet' +# validate_absolute_path($my_path2) +# $my_path3 = ['C:/Program Files (x86)/Puppet Labs/Puppet','C:/Program Files/Puppet Labs/Puppet'] +# validate_absolute_path($my_path3) +# $my_path4 = ['/var/lib/puppet','/usr/share/puppet'] +# validate_absolute_path($my_path4) +# +# The following values will fail, causing compilation to abort: +# +# validate_absolute_path(true) +# validate_absolute_path('../var/lib/puppet') +# validate_absolute_path('var/lib/puppet') +# validate_absolute_path([ 'var/lib/puppet', '/var/foo' ]) +# validate_absolute_path([ '/var/lib/puppet', 'var/foo' ]) +# $undefined = undef +# validate_absolute_path($undefined) +# +# +Puppet::Functions.create_function(:'stdlib::validate_absolute_path') 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) + require 'puppet/util' + + if args.empty? + raise Puppet::ParseError, "validate_absolute_path(): wrong number of arguments (#{args.length}; must be > 0)" + end + + args.each do |arg| + # put arg to candidate var to be able to replace it + candidates = arg + # if arg is just a string with a path to test, convert it to an array + # to avoid test code duplication + unless arg.is_a?(Array) + candidates = Array.new(1, arg) + end + # iterate over all paths within the candidates array + candidates.each do |path| + unless function_is_absolute_path([path]) + raise Puppet::ParseError, "#{path.inspect} is not an absolute path." + end + end + end + end +end diff --git a/lib/puppet/functions/stdlib/validate_array.rb b/lib/puppet/functions/stdlib/validate_array.rb new file mode 100644 index 000000000..6825f573a --- /dev/null +++ b/lib/puppet/functions/stdlib/validate_array.rb @@ -0,0 +1,64 @@ +# 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 ---- +# +# validate_array.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Validate that all passed values are array data structures. Abort catalog +# compilation if any value fails this check. +# +# @return +# validate array +# +# @example **Usage** +# The following values will pass: +# +# $my_array = [ 'one', 'two' ] +# validate_array($my_array) +# +# The following values will fail, causing compilation to abort: +# +# validate_array(true) +# validate_array('some_string') +# $undefined = undef +# validate_array($undefined) +# +# +Puppet::Functions.create_function(:'stdlib::validate_array') 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) + function_deprecation([:validate_array, 'This method is deprecated, please use the stdlib validate_legacy function, + with Stdlib::Compat::Array. There is further documentation for validate_legacy function in the README.']) + + if args.empty? + raise Puppet::ParseError, "validate_array(): wrong number of arguments (#{args.length}; must be > 0)" + end + + args.each do |arg| + unless arg.is_a?(Array) + raise Puppet::ParseError, "#{arg.inspect} is not an Array. It looks to be a #{arg.class}" + end + end + end +end diff --git a/lib/puppet/functions/stdlib/validate_augeas.rb b/lib/puppet/functions/stdlib/validate_augeas.rb new file mode 100644 index 000000000..d80ca07f1 --- /dev/null +++ b/lib/puppet/functions/stdlib/validate_augeas.rb @@ -0,0 +1,118 @@ +# 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 'tempfile' + +# +# validate_augaes.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Perform validation of a string using an Augeas lens +# +# The first argument of this function should be a string to +# test, and the second argument should be the name of the Augeas lens to use. +# If Augeas fails to parse the string with the lens, the compilation will +# abort with a parse error. +# +# A third argument can be specified, listing paths which should +# not be found in the file. The `$file` variable points to the location +# of the temporary file being tested in the Augeas tree. +# +# @return +# validate string using an Augeas lens +# +# @example **Usage** +# +# If you want to make sure your passwd content never contains +# a user `foo`, you could write: +# +# validate_augeas($passwdcontent, 'Passwd.lns', ['$file/foo']) +# +# If you wanted to ensure that no users used the '/bin/barsh' shell, +# you could use: +# +# validate_augeas($passwdcontent, 'Passwd.lns', ['$file/*[shell="/bin/barsh"]'] +# +# If a fourth argument is specified, this will be the error message raised and +# seen by the user. +# +# A helpful error message can be returned like this: +# +# validate_augeas($sudoerscontent, 'Sudoers.lns', [], 'Failed to validate sudoers content with Augeas') +# +# +# +Puppet::Functions.create_function(:'stdlib::validate_augeas') 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 Puppet.features.augeas? + raise Puppet::ParseError, 'validate_augeas(): this function requires the augeas feature. See http://docs.puppetlabs.com/guides/augeas.html#pre-requisites for how to activate it.' + end + + if (args.length < 2) || (args.length > 4) + raise Puppet::ParseError, "validate_augeas(): wrong number of arguments (#{args.length}; must be 2, 3, or 4)" + end + + msg = args[3] || "validate_augeas(): Failed to validate content against #{args[1].inspect}" + + require 'augeas' + aug = Augeas.open(nil, nil, Augeas::NO_MODL_AUTOLOAD) + begin + content = args[0] + + # Test content in a temporary file + tmpfile = Tempfile.new('validate_augeas') + begin + tmpfile.write(content) + ensure + tmpfile.close + end + + # Check for syntax + lens = args[1] + aug.transform( + :lens => lens, + :name => 'Validate_augeas', + :incl => tmpfile.path, + ) + aug.load! + + unless aug.match("/augeas/files#{tmpfile.path}//error").empty? + error = aug.get("/augeas/files#{tmpfile.path}//error/message") + msg += " with error: #{error}" + raise Puppet::ParseError, msg + end + + # Launch unit tests + tests = args[2] || [] + aug.defvar('file', "/files#{tmpfile.path}") + tests.each do |t| + msg += " testing path #{t}" + raise Puppet::ParseError, msg unless aug.match(t).empty? + end + ensure + aug.close + tmpfile.unlink + end + end +end diff --git a/lib/puppet/functions/stdlib/validate_bool.rb b/lib/puppet/functions/stdlib/validate_bool.rb new file mode 100644 index 000000000..cd5e4a621 --- /dev/null +++ b/lib/puppet/functions/stdlib/validate_bool.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 ---- +# +# validate_bool.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Validate that all passed values are either true or false. Abort catalog +# compilation if any value fails this check. +# +# @return +# validate boolean +# +# @example **Usage** +# +# The following values will pass: +# +# $iamtrue = true +# validate_bool(true) +# validate_bool(true, true, false, $iamtrue) +# +# The following values will fail, causing compilation to abort: +# +# $some_array = [ true ] +# validate_bool("false") +# validate_bool("true") +# validate_bool($some_array) +# +# +Puppet::Functions.create_function(:'stdlib::validate_bool') 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.empty? + raise Puppet::ParseError, "validate_bool(): wrong number of arguments (#{args.length}; must be > 0)" + end + + args.each do |arg| + unless function_is_bool([arg]) + raise Puppet::ParseError, "#{arg.inspect} is not a boolean. It looks to be a #{arg.class}" + end + end + end +end diff --git a/lib/puppet/functions/stdlib/validate_cmd.rb b/lib/puppet/functions/stdlib/validate_cmd.rb new file mode 100644 index 000000000..666f3bd91 --- /dev/null +++ b/lib/puppet/functions/stdlib/validate_cmd.rb @@ -0,0 +1,95 @@ +# 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 'puppet/util/execution' +require 'tempfile' + +# +# validate_cmd.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Perform validation of a string with an external command. +# +# The first argument of this function should be a string to +# test, and the second argument should be a path to a test command +# taking a % as a placeholder for the file path (will default to the end). +# If the command, launched against a tempfile containing the passed string, +# returns a non-null value, compilation will abort with a parse error. +# If a third argument is specified, this will be the error message raised and +# seen by the user. +# +# @return +# validate of a string with an external command +# +# A helpful error message can be returned like this: +# +# @example **Usage** +# +# Defaults to end of path +# validate_cmd($sudoerscontent, '/usr/sbin/visudo -c -f', 'Visudo failed to validate sudoers content') +# +# % as file location +# validate_cmd($haproxycontent, '/usr/sbin/haproxy -f % -c', 'Haproxy failed to validate config content') +# +# +# +Puppet::Functions.create_function(:'stdlib::validate_cmd') 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) || (args.length > 3) + raise Puppet::ParseError, "validate_cmd(): wrong number of arguments (#{args.length}; must be 2 or 3)" + end + + msg = args[2] || "validate_cmd(): failed to validate content with command #{args[1].inspect}" + + content = args[0] + checkscript = args[1] + + # Test content in a temporary file + tmpfile = Tempfile.new('validate_cmd') + begin + tmpfile.write(content) + tmpfile.close + + check_with_correct_location = if checkscript =~ %r{\s%(\s|$)} + checkscript.gsub(%r{%}, tmpfile.path) + else + "#{checkscript} #{tmpfile.path}" + end + + if Puppet::Util::Execution.respond_to?('execute') + Puppet::Util::Execution.execute(check_with_correct_location) + else + Puppet::Util.execute(check_with_correct_location) + end + rescue Puppet::ExecutionFailure => detail + msg += "\n#{detail}" + raise Puppet::ParseError, msg + rescue StandardError => detail + msg += "\n#{detail.class.name} #{detail}" + raise Puppet::ParseError, msg + ensure + tmpfile.unlink + end + end +end diff --git a/lib/puppet/functions/stdlib/validate_domain_name.rb b/lib/puppet/functions/stdlib/validate_domain_name.rb new file mode 100644 index 000000000..a9625e44e --- /dev/null +++ b/lib/puppet/functions/stdlib/validate_domain_name.rb @@ -0,0 +1,70 @@ +# 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 ---- +# +# validate_domain_name.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Validate that all values passed are syntactically correct domain names. +# Fail compilation if any value fails this check. +# +# @return +# passes when the given values are syntactically correct domain names or raise an error when they are not and fails compilation +# +# @example **Usage** +# +# The following values will pass: +# +# $my_domain_name = 'server.domain.tld' +# validate_domain_name($my_domain_name) +# validate_domain_name('domain.tld', 'puppet.com', $my_domain_name) +# +# The following values will fail, causing compilation to abort: +# +# validate_domain_name(1) +# validate_domain_name(true) +# validate_domain_name('invalid domain') +# validate_domain_name('-foo.example.com') +# validate_domain_name('www.example.2com') +# +# +Puppet::Functions.create_function(:'stdlib::validate_domain_name') 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) + rescuable_exceptions = [ArgumentError] + + if args.empty? + raise Puppet::ParseError, "validate_domain_name(): wrong number of arguments (#{args.length}; must be > 0)" + end + + args.each do |arg| + raise Puppet::ParseError, "#{arg.inspect} is not a string." unless arg.is_a?(String) + + begin + raise Puppet::ParseError, "#{arg.inspect} is not a syntactically correct domain name" unless function_is_domain_name([arg]) + rescue *rescuable_exceptions + raise Puppet::ParseError, "#{arg.inspect} is not a syntactically correct domain name" + end + end + end +end diff --git a/lib/puppet/functions/stdlib/validate_email_address.rb b/lib/puppet/functions/stdlib/validate_email_address.rb new file mode 100644 index 000000000..d287c6805 --- /dev/null +++ b/lib/puppet/functions/stdlib/validate_email_address.rb @@ -0,0 +1,67 @@ +# 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 ---- +# +# validate_email_address.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Validate that all values passed are valid email addresses. +# Fail compilation if any value fails this check. +# +# @return +# Fail compilation if any value fails this check. +# +# @example **Usage** +# +# The following values will pass: +# +# $my_email = "waldo@gmail.com" +# validate_email_address($my_email) +# validate_email_address("bob@gmail.com", "alice@gmail.com", $my_email) +# +# The following values will fail, causing compilation to abort: +# +# $some_array = [ 'bad_email@/d/efdf.com' ] +# validate_email_address($some_array) +# +# +Puppet::Functions.create_function(:'stdlib::validate_email_address') 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) + rescuable_exceptions = [ArgumentError] + + if args.empty? + raise Puppet::ParseError, "validate_email_address(): wrong number of arguments (#{args.length}; must be > 0)" + end + + args.each do |arg| + raise Puppet::ParseError, "#{arg.inspect} is not a string." unless arg.is_a?(String) + + begin + raise Puppet::ParseError, "#{arg.inspect} is not a valid email address" unless function_is_email_address([arg]) + rescue *rescuable_exceptions + raise Puppet::ParseError, "#{arg.inspect} is not a valid email address" + end + end + end +end diff --git a/lib/puppet/functions/stdlib/validate_hash.rb b/lib/puppet/functions/stdlib/validate_hash.rb new file mode 100644 index 000000000..95fa9138a --- /dev/null +++ b/lib/puppet/functions/stdlib/validate_hash.rb @@ -0,0 +1,65 @@ +# 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 ---- +# +# validate_hash.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Validate that all passed values are hash data structures. Abort catalog +# compilation if any value fails this check. +# +# @return +# validate hash +# +# @example **Usage** +# +# The following values will pass: +# +# $my_hash = { 'one' => 'two' } +# validate_hash($my_hash) +# +# The following values will fail, causing compilation to abort: +# +# validate_hash(true) +# validate_hash('some_string') +# $undefined = undef +# validate_hash($undefined) +# +# +Puppet::Functions.create_function(:'stdlib::validate_hash') 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) + function_deprecation([:validate_hash, 'This method is deprecated, please use the stdlib validate_legacy function, + with Stdlib::Compat::Hash. There is further documentation for validate_legacy function in the README.']) + + if args.empty? + raise Puppet::ParseError, "validate_hash(): wrong number of arguments (#{args.length}; must be > 0)" + end + + args.each do |arg| + unless arg.is_a?(Hash) + raise Puppet::ParseError, "#{arg.inspect} is not a Hash. It looks to be a #{arg.class}" + end + end + end +end diff --git a/lib/puppet/functions/stdlib/validate_integer.rb b/lib/puppet/functions/stdlib/validate_integer.rb new file mode 100644 index 000000000..290c6450e --- /dev/null +++ b/lib/puppet/functions/stdlib/validate_integer.rb @@ -0,0 +1,165 @@ +# 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 ---- +# +# validate_interger.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Validate that the first argument is an integer (or an array of integers). Abort catalog compilation if any of the checks fail. +# +# The second argument is optional and passes a maximum. (All elements of) the first argument has to be less or equal to this max. +# The third argument is optional and passes a minimum. (All elements of) the first argument has to be greater or equal to this min. +# If, and only if, a minimum is given, the second argument may be an empty string or undef, which will be handled to just check +# if (all elements of) the first argument are greater or equal to the given minimum. +# It will fail if the first argument is not an integer or array of integers, and if arg 2 and arg 3 are not convertable to an integer. +# +# @return +# Validate that the first argument is an integer (or an array of integers). Fail compilation if any of the checks fail. +# +# @example **Usage** +# +# The following values will pass: +# +# validate_integer(1) +# validate_integer(1, 2) +# validate_integer(1, 1) +# validate_integer(1, 2, 0) +# validate_integer(2, 2, 2) +# validate_integer(2, '', 0) +# validate_integer(2, undef, 0) +# $foo = undef +# validate_integer(2, $foo, 0) +# validate_integer([1,2,3,4,5], 6) +# validate_integer([1,2,3,4,5], 6, 0) +# +# Plus all of the above, but any combination of values passed as strings ('1' or "1"). +# Plus all of the above, but with (correct) combinations of negative integer values. +# +# The following values will not: +# +# validate_integer(true) +# validate_integer(false) +# validate_integer(7.0) +# validate_integer({ 1 => 2 }) +# $foo = undef +# validate_integer($foo) +# validate_integer($foobaridontexist) +# +# validate_integer(1, 0) +# validate_integer(1, true) +# validate_integer(1, '') +# validate_integer(1, undef) +# validate_integer(1, , 0) +# validate_integer(1, 2, 3) +# validate_integer(1, 3, 2) +# validate_integer(1, 3, true) +# +# Plus all of the above, but any combination of values passed as strings ('false' or "false"). +# Plus all of the above, but with incorrect combinations of negative integer values. +# Plus all of the above, but with non-integer items in arrays or maximum / minimum argument. +# +# +# +Puppet::Functions.create_function(:'stdlib::validate_integer') 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) + function_deprecation([:validate_integer, 'This method is deprecated, please use the stdlib validate_legacy function, + with Stdlib::Compat::Integer. There is further documentation for validate_legacy function in the README.']) + + # tell the user we need at least one, and optionally up to two other parameters + raise Puppet::ParseError, "validate_integer(): Wrong number of arguments; must be 1, 2 or 3, got #{args.length}" unless !args.empty? && args.length < 4 + + input, max, min = *args + + # check maximum parameter + if args.length > 1 + max = max.to_s + # allow max to be empty (or undefined) if we have a minimum set + if args.length > 2 && max == '' + max = nil + else + begin + max = Integer(max) + rescue TypeError, ArgumentError + raise Puppet::ParseError, "validate_integer(): Expected second argument to be unset or an Integer, got #{max}:#{max.class}" + end + end + else + max = nil + end + + # check minimum parameter + if args.length > 2 + begin + min = Integer(min.to_s) + rescue TypeError, ArgumentError + raise Puppet::ParseError, "validate_integer(): Expected third argument to be unset or an Integer, got #{min}:#{min.class}" + end + else + min = nil + end + + # ensure that min < max + if min && max && min > max + raise Puppet::ParseError, "validate_integer(): Expected second argument to be larger than third argument, got #{max} < #{min}" + end + + # create lamba validator function + validator = ->(num) do + # check input < max + if max && num > max + raise Puppet::ParseError, "validate_integer(): Expected #{input.inspect} to be smaller or equal to #{max}, got #{input.inspect}." + end + # check input > min (this will only be checked if no exception has been raised before) + if min && num < min + raise Puppet::ParseError, "validate_integer(): Expected #{input.inspect} to be greater or equal to #{min}, got #{input.inspect}." + end + end + + # if this is an array, handle it. + case input + when Array + # check every element of the array + input.each_with_index do |arg, pos| + begin + raise TypeError if arg.is_a?(Hash) + arg = Integer(arg.to_s) + validator.call(arg) + rescue TypeError, ArgumentError + raise Puppet::ParseError, "validate_integer(): Expected element at array position #{pos} to be an Integer, got #{arg.class}" + end + end + # for the sake of compatibility with ruby 1.8, we need extra handling of hashes + when Hash + raise Puppet::ParseError, "validate_integer(): Expected first argument to be an Integer or Array, got #{input.class}" + # check the input. this will also fail any stuff other than pure, shiny integers + else + begin + input = Integer(input.to_s) + validator.call(input) + rescue TypeError, ArgumentError + raise Puppet::ParseError, "validate_integer(): Expected first argument to be an Integer or Array, got #{input.class}" + end + end + end +end diff --git a/lib/puppet/functions/stdlib/validate_ip_address.rb b/lib/puppet/functions/stdlib/validate_ip_address.rb new file mode 100644 index 000000000..75f046730 --- /dev/null +++ b/lib/puppet/functions/stdlib/validate_ip_address.rb @@ -0,0 +1,84 @@ +# 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 ---- +# +# validate_ip_address.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Validate that all values passed are valid IP addresses, +# regardless they are IPv4 or IPv6 +# Fail compilation if any value fails this check. +# +# @return +# passes when the given values are valid IP addresses or raise an error when they are not and fails compilation +# +# @example **Usage** +# The following values will pass: +# +# $my_ip = "1.2.3.4" +# validate_ip_address($my_ip) +# validate_ip_address("8.8.8.8", "172.16.0.1", $my_ip) +# +# $my_ip = "3ffe:505:2" +# validate_ip_address(1) +# validate_ip_address($my_ip) +# validate_ip_address("fe80::baf6:b1ff:fe19:7507", $my_ip) +# +# The following values will fail, causing compilation to abort: +# +# $some_array = [ 1, true, false, "garbage string", "3ffe:505:2" ] +# validate_ip_address($some_array) +# +# +Puppet::Functions.create_function(:'stdlib::validate_ip_address') 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) + require 'ipaddr' + rescuable_exceptions = [ArgumentError] + + function_deprecation([:validate_ip_address, 'This method is deprecated, please use the stdlib validate_legacy function, + with Stdlib::Compat::Ip_address. There is further documentation for validate_legacy function in the README.']) + + if defined?(IPAddr::InvalidAddressError) + rescuable_exceptions << IPAddr::InvalidAddressError + end + + if args.empty? + raise Puppet::ParseError, "validate_ip_address(): wrong number of arguments (#{args.length}; must be > 0)" + end + + args.each do |arg| + unless arg.is_a?(String) + raise Puppet::ParseError, "#{arg.inspect} is not a string." + end + + begin + unless IPAddr.new(arg).ipv4? || IPAddr.new(arg).ipv6? + raise Puppet::ParseError, "#{arg.inspect} is not a valid IP address." + end + rescue *rescuable_exceptions + raise Puppet::ParseError, "#{arg.inspect} is not a valid IP address." + end + end + end +end diff --git a/lib/puppet/functions/stdlib/validate_ipv4_address.rb b/lib/puppet/functions/stdlib/validate_ipv4_address.rb new file mode 100644 index 000000000..a1cb0b3f6 --- /dev/null +++ b/lib/puppet/functions/stdlib/validate_ipv4_address.rb @@ -0,0 +1,78 @@ +# 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 ---- +# +# validate_ipv4_address.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Validate that all values passed are valid IPv4 addresses. +# Fail compilation if any value fails this check. +# +# @return +# passes when the given values are valid IPv4 addresses or raise an error when they are not and fails compilation +# +# @example **Usage** +# The following values will pass: +# +# $my_ip = "1.2.3.4" +# validate_ipv4_address($my_ip) +# validate_ipv4_address("8.8.8.8", "172.16.0.1", $my_ip) +# +# The following values will fail, causing compilation to abort: +# +# $some_array = [ 1, true, false, "garbage string", "3ffe:505:2" ] +# validate_ipv4_address($some_array) +# +# +Puppet::Functions.create_function(:'stdlib::validate_ipv4_address') 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) + function_deprecation([:validate_ipv4_address, 'This method is deprecated, please use the stdlib validate_legacy function, + with Stdlib::Compat::Ipv4. There is further documentation for validate_legacy function in the README.']) + + require 'ipaddr' + rescuable_exceptions = [ArgumentError] + + if defined?(IPAddr::InvalidAddressError) + rescuable_exceptions << IPAddr::InvalidAddressError + end + + if args.empty? + raise Puppet::ParseError, "validate_ipv4_address(): wrong number of arguments (#{args.length}; must be > 0)" + end + + args.each do |arg| + unless arg.is_a?(String) + raise Puppet::ParseError, "#{arg.inspect} is not a string." + end + + begin + unless IPAddr.new(arg).ipv4? + raise Puppet::ParseError, "#{arg.inspect} is not a valid IPv4 address." + end + rescue *rescuable_exceptions + raise Puppet::ParseError, "#{arg.inspect} is not a valid IPv4 address." + end + end + end +end diff --git a/lib/puppet/functions/stdlib/validate_ipv6_address.rb b/lib/puppet/functions/stdlib/validate_ipv6_address.rb new file mode 100644 index 000000000..d6f900b34 --- /dev/null +++ b/lib/puppet/functions/stdlib/validate_ipv6_address.rb @@ -0,0 +1,80 @@ +# 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 ---- +# +# validate_ipv7_address.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Validate that all values passed are valid IPv6 addresses. +# Fail compilation if any value fails this check. +# +# @return +# passes when the given values are valid IPv6 addresses or raise an error when they are not and fails compilation +# +# @example **Usage** +# The following values will pass: +# +# $my_ip = "3ffe:505:2" +# validate_ipv6_address(1) +# validate_ipv6_address($my_ip) +# validate_bool("fe80::baf6:b1ff:fe19:7507", $my_ip) +# +# The following values will fail, causing compilation to abort: +# +# $some_array = [ true, false, "garbage string", "1.2.3.4" ] +# validate_ipv6_address($some_array) +# +# +# +Puppet::Functions.create_function(:'stdlib::validate_ipv6_address') 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) + function_deprecation([:validate_ipv6_address, 'This method is deprecated, please use the stdlib validate_legacy function, + with Stdlib::Compat::Ipv6. There is further documentation for validate_legacy function in the README.']) + + require 'ipaddr' + rescuable_exceptions = [ArgumentError] + + if defined?(IPAddr::InvalidAddressError) + rescuable_exceptions << IPAddr::InvalidAddressError + end + + if args.empty? + raise Puppet::ParseError, "validate_ipv6_address(): wrong number of arguments (#{args.length}; must be > 0)" + end + + args.each do |arg| + unless arg.is_a?(String) + raise Puppet::ParseError, "#{arg.inspect} is not a string." + end + + begin + unless IPAddr.new(arg).ipv6? + raise Puppet::ParseError, "#{arg.inspect} is not a valid IPv6 address." + end + rescue *rescuable_exceptions + raise Puppet::ParseError, "#{arg.inspect} is not a valid IPv6 address." + end + end + end +end diff --git a/lib/puppet/functions/stdlib/validate_numeric.rb b/lib/puppet/functions/stdlib/validate_numeric.rb new file mode 100644 index 000000000..a21504735 --- /dev/null +++ b/lib/puppet/functions/stdlib/validate_numeric.rb @@ -0,0 +1,125 @@ +# 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 ---- +# +# validate_numeric.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Validate that the first argument is a numeric value (or an array of numeric values). Abort catalog compilation if any of the checks fail. +# +# The second argument is optional and passes a maximum. (All elements of) the first argument has to be less or equal to this max. +# The third argument is optional and passes a minimum. (All elements of) the first argument has to be greater or equal to this min. +# If, and only if, a minimum is given, the second argument may be an empty string or undef, which will be handled to just check +# if (all elements of) the first argument are greater or equal to the given minimum. +# It will fail if the first argument is not a numeric (Integer or Float) or array of numerics, and if arg 2 and arg 3 are not convertable to a numeric. +# +# @return +# Validate that the first argument is a numeric value (or an array of numeric values). Fail compilation if any of the checks fail. +# +# For passing and failing usage, see `validate_integer()`. It is all the same for validate_numeric, yet now floating point values are allowed, too. +# +# +# +Puppet::Functions.create_function(:'stdlib::validate_numeric') 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) + function_deprecation([:validate_numeric, 'This method is deprecated, please use the stdlib validate_legacy function, + with Stdlib::Compat::Numeric. There is further documentation for validate_legacy function in the README.']) + + # tell the user we need at least one, and optionally up to two other parameters + raise Puppet::ParseError, "validate_numeric(): Wrong number of arguments; must be 1, 2 or 3, got #{args.length}" unless !args.empty? && args.length < 4 + + input, max, min = *args + + # check maximum parameter + if args.length > 1 + max = max.to_s + # allow max to be empty (or undefined) if we have a minimum set + if args.length > 2 && max == '' + max = nil + else + begin + max = Float(max) + rescue TypeError, ArgumentError + raise Puppet::ParseError, "validate_numeric(): Expected second argument to be unset or a Numeric, got #{max}:#{max.class}" + end + end + else + max = nil + end + + # check minimum parameter + if args.length > 2 + begin + min = Float(min.to_s) + rescue TypeError, ArgumentError + raise Puppet::ParseError, "validate_numeric(): Expected third argument to be unset or a Numeric, got #{min}:#{min.class}" + end + else + min = nil + end + + # ensure that min < max + if min && max && min > max + raise Puppet::ParseError, "validate_numeric(): Expected second argument to be larger than third argument, got #{max} < #{min}" + end + + # create lamba validator function + validator = ->(num) do + # check input < max + if max && num > max + raise Puppet::ParseError, "validate_numeric(): Expected #{input.inspect} to be smaller or equal to #{max}, got #{input.inspect}." + end + # check input > min (this will only be checked if no exception has been raised before) + if min && num < min + raise Puppet::ParseError, "validate_numeric(): Expected #{input.inspect} to be greater or equal to #{min}, got #{input.inspect}." + end + end + + # if this is an array, handle it. + case input + when Array + # check every element of the array + input.each_with_index do |arg, pos| + begin + raise TypeError if arg.is_a?(Hash) + arg = Float(arg.to_s) + validator.call(arg) + rescue TypeError, ArgumentError + raise Puppet::ParseError, "validate_numeric(): Expected element at array position #{pos} to be a Numeric, got #{arg.class}" + end + end + # for the sake of compatibility with ruby 1.8, we need extra handling of hashes + when Hash + raise Puppet::ParseError, "validate_integer(): Expected first argument to be a Numeric or Array, got #{input.class}" + # check the input. this will also fail any stuff other than pure, shiny integers + else + begin + input = Float(input.to_s) + validator.call(input) + rescue TypeError, ArgumentError + raise Puppet::ParseError, "validate_numeric(): Expected first argument to be a Numeric or Array, got #{input.class}" + end + end + end +end diff --git a/lib/puppet/functions/stdlib/validate_re.rb b/lib/puppet/functions/stdlib/validate_re.rb new file mode 100644 index 000000000..19a90a889 --- /dev/null +++ b/lib/puppet/functions/stdlib/validate_re.rb @@ -0,0 +1,82 @@ +# 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 ---- +# +# validate.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Perform simple validation of a string against one or more regular +# expressions. +# +# The first argument of this function should be a string to +# test, and the second argument should be a stringified regular expression +# (without the // delimiters) or an array of regular expressions. If none +# of the regular expressions match the string passed in, compilation will +# abort with a parse error. +# If a third argument is specified, this will be the error message raised and +# seen by the user. +# +# @return +# validation of a string against one or more regular expressions. +# +# @example **Usage** +# The following strings will validate against the regular expressions: +# +# validate_re('one', '^one$') +# validate_re('one', [ '^one', '^two' ]) +# +# The following strings will fail to validate, causing compilation to abort: +# +# validate_re('one', [ '^two', '^three' ]) +# +# A helpful error message can be returned like this: +# +# validate_re($::puppetversion, '^2.7', 'The $puppetversion fact value does not match 2.7') +# +# > *Note:* +# Compilation will also abort, if the first argument is not a String. Always use +# quotes to force stringification: +# validate_re("${::operatingsystemmajrelease}", '^[57]$') +# +# +Puppet::Functions.create_function(:'stdlib::validate_re') 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) + function_deprecation([:validate_re, 'This method is deprecated, please use the stdlib validate_legacy function, + with Stdlib::Compat::Re. There is further documentation for validate_legacy function in the README.']) + + if (args.length < 2) || (args.length > 3) + raise Puppet::ParseError, "validate_re(): wrong number of arguments (#{args.length}; must be 2 or 3)" + end + + raise Puppet::ParseError, "validate_re(): input needs to be a String, not a #{args[0].class}" unless args[0].is_a? String + + msg = args[2] || "validate_re(): #{args[0].inspect} does not match #{args[1].inspect}" + + # We're using a flattened array here because we can't call String#any? in + # Ruby 1.9 like we can in Ruby 1.8 + raise Puppet::ParseError, msg unless [args[1]].flatten.any? do |re_str| + args[0] =~ Regexp.compile(re_str) + end + end +end diff --git a/lib/puppet/functions/stdlib/validate_slength.rb b/lib/puppet/functions/stdlib/validate_slength.rb new file mode 100644 index 000000000..a6a70a968 --- /dev/null +++ b/lib/puppet/functions/stdlib/validate_slength.rb @@ -0,0 +1,97 @@ +# 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 ---- +# +# validate_slength.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Validate that the first argument is a string (or an array of strings), and less/equal to than the length of the second argument. +# An optional third parameter can be given the minimum length. It fails if the first argument is not a string or array of strings, +# and if arg 2 and arg 3 are not convertable to a number. +# +# @return +# validate that the first argument is a string (or an array of strings), and less/equal to than the length of the second argument. Fail compilation if any of the checks fail. +# +# @example **Usage** +# The following values will pass: +# +# validate_slength("discombobulate",17) +# validate_slength(["discombobulate","moo"],17) +# validate_slength(["discombobulate","moo"],17,3) +# +# The following valueis will not: +# +# validate_slength("discombobulate",1) +# validate_slength(["discombobulate","thermometer"],5) +# validate_slength(["discombobulate","moo"],17,10) +# +# +Puppet::Functions.create_function(:'stdlib::validate_slength') 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) + function_deprecation([:validate_slength, 'This method is deprecated, please use the stdlib validate_legacy function, + with String[]. There is further documentation for validate_legacy function in the README.']) + + raise Puppet::ParseError, "validate_slength(): Wrong number of arguments (#{args.length}; must be 2 or 3)" unless args.length == 2 || args.length == 3 + + input, max_length, min_length = *args + + begin + max_length = Integer(max_length) + raise ArgumentError if max_length <= 0 + rescue ArgumentError, TypeError + raise Puppet::ParseError, "validate_slength(): Expected second argument to be a positive Numeric, got #{max_length}:#{max_length.class}" + end + + if min_length + begin + min_length = Integer(min_length) + raise ArgumentError if min_length < 0 + rescue ArgumentError, TypeError + raise Puppet::ParseError, "validate_slength(): Expected third argument to be unset or a positive Numeric, got #{min_length}:#{min_length.class}" + end + else + min_length = 0 + end + + raise Puppet::ParseError, 'validate_slength(): Expected second argument to be equal to or larger than third argument' unless max_length >= min_length + + validator = ->(str) do + unless str.length <= max_length && str.length >= min_length + raise Puppet::ParseError, "validate_slength(): Expected length of #{input.inspect} to be between #{min_length} and #{max_length}, was #{input.length}" + end + end + + case input + when String + validator.call(input) + when Array + input.each_with_index do |arg, pos| + raise Puppet::ParseError, "validate_slength(): Expected element at array position #{pos} to be a String, got #{arg.class}" unless arg.is_a? String + validator.call(arg) + end + else + raise Puppet::ParseError, "validate_slength(): Expected first argument to be a String or Array, got #{input.class}" + end + end +end diff --git a/lib/puppet/functions/stdlib/validate_string.rb b/lib/puppet/functions/stdlib/validate_string.rb new file mode 100644 index 000000000..2969f9af8 --- /dev/null +++ b/lib/puppet/functions/stdlib/validate_string.rb @@ -0,0 +1,71 @@ +# 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 ---- +# +# validate_String.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Validate that all passed values are string data structures +# +# @return +# Validate that all passed values are string data structures. Failed +# compilation if any value fails this check. +# +# @example **Usage** +# The following values will pass: +# +# $my_string = "one two" +# validate_string($my_string, 'three') +# +# The following values will fail, causing compilation to abort: +# +# validate_string(true) +# validate_string([ 'some', 'array' ]) +# > *Note:* +# Validate_string(undef) will not fail in this version of the +# functions API (incl. current and future parser). Instead, use: +# ``` +# if $var == undef { +# fail('...') +# } +# ``` +# +# +Puppet::Functions.create_function(:'stdlib::validate_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) + function_deprecation([:validate_string, 'This method is deprecated, please use the stdlib validate_legacy function, + with Stdlib::Compat::String. There is further documentation for validate_legacy function in the README.']) + + if args.empty? + raise Puppet::ParseError, "validate_string(): wrong number of arguments (#{args.length}; must be > 0)" + end + + args.each do |arg| + # when called through the v4 API shim, undef gets translated to nil + unless arg.is_a?(String) || arg.nil? + raise Puppet::ParseError, "#{arg.inspect} is not a string. It looks to be a #{arg.class}" + end + end + end +end diff --git a/lib/puppet/functions/stdlib/values.rb b/lib/puppet/functions/stdlib/values.rb new file mode 100644 index 000000000..9d63b6e4b --- /dev/null +++ b/lib/puppet/functions/stdlib/values.rb @@ -0,0 +1,64 @@ +# 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.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# When given a hash this function will return the values of that hash. +# +# @return +# array of values +# +# @example **Usage** +# $hash = { +# 'a' => 1, +# 'b' => 2, +# 'c' => 3, +# } +# values($hash) +# +# This example would return: ```[1,2,3]``` +# +# > *Note:* +# From Puppet 5.5.0, the compatible function with the same name in Puppet core +# will be used instead of this function. +# +# +# +Puppet::Functions.create_function(:'stdlib::values') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "values(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? + + hash = arguments[0] + + unless hash.is_a?(Hash) + raise(Puppet::ParseError, 'values(): Requires hash to work with') + end + + result = hash.values + + result + end +end diff --git a/lib/puppet/functions/stdlib/values_at.rb b/lib/puppet/functions/stdlib/values_at.rb new file mode 100644 index 000000000..87c7196dc --- /dev/null +++ b/lib/puppet/functions/stdlib/values_at.rb @@ -0,0 +1,120 @@ +# 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_at.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Finds value inside an array based on location. +# +# The first argument is the array you want to analyze, and the second element can +# be a combination of: +# +# * A single numeric index +# * A range in the form of 'start-stop' (eg. 4-9) +# * An array combining the above +# +# @return +# an array of values identified by location +# +# @example **Usage** +# +# values_at(['a','b','c'], 2) +# Would return ['c'] +# +# values_at(['a','b','c'], ["0-1"]) +# Would return ['a','b'] +# +# values_at(['a','b','c','d','e'], [0, "2-3"]) +# Would return ['a','c','d'] +# +# > *Note:* +# Since Puppet 4.0.0 it is possible to slice an array with index and count directly in the language. +# A negative value is taken to be "from the end" of the array: +# +# `['a', 'b', 'c', 'd'][1, 2]` results in `['b', 'c']` +# `['a', 'b', 'c', 'd'][2, -1]` results in `['c', 'd']` +# `['a', 'b', 'c', 'd'][1, -2]` results in `['b', 'c']` +# +# +# +Puppet::Functions.create_function(:'stdlib::values_at') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + raise(Puppet::ParseError, "values_at(): Wrong number of arguments given (#{arguments.size} for 2)") if arguments.size < 2 + + array = arguments.shift + + unless array.is_a?(Array) + raise(Puppet::ParseError, 'values_at(): Requires array to work with') + end + + indices = [arguments.shift].flatten # Get them all ... Pokemon ... + + if !indices || indices.empty? + raise(Puppet::ParseError, 'values_at(): You must provide at least one positive index to collect') + end + + indices_list = [] + + indices.each do |i| + i = i.to_s + m = i.match(%r{^(\d+)(\.\.\.?|\-)(\d+)$}) + if m + start = m[1].to_i + stop = m[3].to_i + + type = m[2] + + raise(Puppet::ParseError, 'values_at(): Stop index in given indices range is smaller than the start index') if start > stop + raise(Puppet::ParseError, 'values_at(): Stop index in given indices range exceeds array size') if stop > array.size - 1 # First element is at index 0 is it not? + + range = case type + when %r{^(\.\.|\-)$} then (start..stop) + when %r{^(\.\.\.)$} then (start...stop) # Exclusive of last element ... + end + + range.each { |i| indices_list << i.to_i } # rubocop:disable Lint/ShadowingOuterLocalVariable : Value is meant to be shadowed + else + # Only positive numbers allowed in this case ... + unless i =~ %r{^\d+$} + raise(Puppet::ParseError, 'values_at(): Unknown format of given index') + end + + # In Puppet numbers are often string-encoded ... + i = i.to_i + + if i > array.size - 1 # Same story. First element is at index 0 ... + raise(Puppet::ParseError, 'values_at(): Given index exceeds array size') + end + + indices_list << i + end + end + + # We remove nil values as they make no sense in Puppet DSL ... + result = indices_list.map { |i| array[i] }.compact + + result + end +end diff --git a/lib/puppet/functions/stdlib/zip.rb b/lib/puppet/functions/stdlib/zip.rb new file mode 100644 index 000000000..a5a73a47b --- /dev/null +++ b/lib/puppet/functions/stdlib/zip.rb @@ -0,0 +1,58 @@ +# 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 ---- +# +# zip.rb +# +# ---- original file header ---- +# +# @summary +# @summary +# Takes one element from first array and merges corresponding elements from second array. +# +# @return +# This generates a sequence of n-element arrays, where n is one more than the count of arguments. +# +# @example +# zip(['1','2','3'],['4','5','6']) +# Would result in: ["1", "4"], ["2", "5"], ["3", "6"] +# +# +Puppet::Functions.create_function(:'stdlib::zip') do + # @param arguments + # 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', :arguments + end + + def default_impl(*arguments) + # Technically we support three arguments but only first is mandatory ... + raise(Puppet::ParseError, "zip(): Wrong number of arguments given (#{arguments.size} for 2)") if arguments.size < 2 + + a = arguments[0] + b = arguments[1] + + unless a.is_a?(Array) && b.is_a?(Array) + raise(Puppet::ParseError, 'zip(): Requires array to work with') + end + + flatten = function_str2bool([arguments[2]]) if arguments[2] + + result = a.zip(b) + result = flatten ? result.flatten : result + + result + end +end diff --git a/spec/functions/stdlib_abs_spec.rb b/spec/functions/stdlib_abs_spec.rb new file mode 100644 index 000000000..9a9abfc5d --- /dev/null +++ b/spec/functions/stdlib_abs_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::abs' 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/stdlib_any2array_spec.rb b/spec/functions/stdlib_any2array_spec.rb new file mode 100644 index 000000000..6540c79a2 --- /dev/null +++ b/spec/functions/stdlib_any2array_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::any2array' 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/stdlib_any2bool_spec.rb b/spec/functions/stdlib_any2bool_spec.rb new file mode 100644 index 000000000..850eee6e6 --- /dev/null +++ b/spec/functions/stdlib_any2bool_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::any2bool' 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/stdlib_assert_private_spec.rb b/spec/functions/stdlib_assert_private_spec.rb new file mode 100644 index 000000000..7dc6d00c3 --- /dev/null +++ b/spec/functions/stdlib_assert_private_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::assert_private' 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/stdlib_base64_spec.rb b/spec/functions/stdlib_base64_spec.rb new file mode 100644 index 000000000..b7de07101 --- /dev/null +++ b/spec/functions/stdlib_base64_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::base64' 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/stdlib_basename_spec.rb b/spec/functions/stdlib_basename_spec.rb new file mode 100644 index 000000000..65ebbd02d --- /dev/null +++ b/spec/functions/stdlib_basename_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::basename' 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/stdlib_bool2num_spec.rb b/spec/functions/stdlib_bool2num_spec.rb new file mode 100644 index 000000000..55f07e0a9 --- /dev/null +++ b/spec/functions/stdlib_bool2num_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::bool2num' 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/stdlib_bool2str_spec.rb b/spec/functions/stdlib_bool2str_spec.rb new file mode 100644 index 000000000..a7c08d7da --- /dev/null +++ b/spec/functions/stdlib_bool2str_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::bool2str' 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/stdlib_camelcase_spec.rb b/spec/functions/stdlib_camelcase_spec.rb new file mode 100644 index 000000000..858f75a77 --- /dev/null +++ b/spec/functions/stdlib_camelcase_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::camelcase' 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/stdlib_capitalize_spec.rb b/spec/functions/stdlib_capitalize_spec.rb new file mode 100644 index 000000000..0ed7a7d5a --- /dev/null +++ b/spec/functions/stdlib_capitalize_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::capitalize' 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/stdlib_ceiling_spec.rb b/spec/functions/stdlib_ceiling_spec.rb new file mode 100644 index 000000000..74e422bcb --- /dev/null +++ b/spec/functions/stdlib_ceiling_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::ceiling' 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/stdlib_chomp_spec.rb b/spec/functions/stdlib_chomp_spec.rb new file mode 100644 index 000000000..d02c8704c --- /dev/null +++ b/spec/functions/stdlib_chomp_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::chomp' 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/stdlib_chop_spec.rb b/spec/functions/stdlib_chop_spec.rb new file mode 100644 index 000000000..fbb58b44e --- /dev/null +++ b/spec/functions/stdlib_chop_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::chop' 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/stdlib_clamp_spec.rb b/spec/functions/stdlib_clamp_spec.rb new file mode 100644 index 000000000..62463bd6c --- /dev/null +++ b/spec/functions/stdlib_clamp_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::clamp' 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/stdlib_concat_spec.rb b/spec/functions/stdlib_concat_spec.rb new file mode 100644 index 000000000..890b1674c --- /dev/null +++ b/spec/functions/stdlib_concat_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::concat' 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/stdlib_convert_base_spec.rb b/spec/functions/stdlib_convert_base_spec.rb new file mode 100644 index 000000000..2a2cd61d0 --- /dev/null +++ b/spec/functions/stdlib_convert_base_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::convert_base' 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/stdlib_count_spec.rb b/spec/functions/stdlib_count_spec.rb new file mode 100644 index 000000000..853072bfe --- /dev/null +++ b/spec/functions/stdlib_count_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::count' 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/stdlib_deep_merge_spec.rb b/spec/functions/stdlib_deep_merge_spec.rb new file mode 100644 index 000000000..eded8fa89 --- /dev/null +++ b/spec/functions/stdlib_deep_merge_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::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/stdlib_defined_with_params_spec.rb b/spec/functions/stdlib_defined_with_params_spec.rb new file mode 100644 index 000000000..d16ab621f --- /dev/null +++ b/spec/functions/stdlib_defined_with_params_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::defined_with_params' 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/stdlib_delete_at_spec.rb b/spec/functions/stdlib_delete_at_spec.rb new file mode 100644 index 000000000..496405c25 --- /dev/null +++ b/spec/functions/stdlib_delete_at_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::delete_at' 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/stdlib_delete_regex_spec.rb b/spec/functions/stdlib_delete_regex_spec.rb new file mode 100644 index 000000000..61503bebf --- /dev/null +++ b/spec/functions/stdlib_delete_regex_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::delete_regex' 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/stdlib_delete_spec.rb b/spec/functions/stdlib_delete_spec.rb new file mode 100644 index 000000000..fcf77c506 --- /dev/null +++ b/spec/functions/stdlib_delete_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::delete' 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/stdlib_delete_undef_values_spec.rb b/spec/functions/stdlib_delete_undef_values_spec.rb new file mode 100644 index 000000000..d0a89a005 --- /dev/null +++ b/spec/functions/stdlib_delete_undef_values_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::delete_undef_values' 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/stdlib_delete_values_spec.rb b/spec/functions/stdlib_delete_values_spec.rb new file mode 100644 index 000000000..6db07d8b5 --- /dev/null +++ b/spec/functions/stdlib_delete_values_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::delete_values' 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/stdlib_deprecation_spec.rb b/spec/functions/stdlib_deprecation_spec.rb new file mode 100644 index 000000000..cfc981e9e --- /dev/null +++ b/spec/functions/stdlib_deprecation_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::deprecation' 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/stdlib_difference_spec.rb b/spec/functions/stdlib_difference_spec.rb new file mode 100644 index 000000000..108467aee --- /dev/null +++ b/spec/functions/stdlib_difference_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::difference' 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/stdlib_dig44_spec.rb b/spec/functions/stdlib_dig44_spec.rb new file mode 100644 index 000000000..9a727dbed --- /dev/null +++ b/spec/functions/stdlib_dig44_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::dig44' 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/stdlib_dig_spec.rb b/spec/functions/stdlib_dig_spec.rb new file mode 100644 index 000000000..c5e507832 --- /dev/null +++ b/spec/functions/stdlib_dig_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::dig' 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/stdlib_dirname_spec.rb b/spec/functions/stdlib_dirname_spec.rb new file mode 100644 index 000000000..5ceb39c7a --- /dev/null +++ b/spec/functions/stdlib_dirname_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::dirname' 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/stdlib_dos2unix_spec.rb b/spec/functions/stdlib_dos2unix_spec.rb new file mode 100644 index 000000000..d217f7295 --- /dev/null +++ b/spec/functions/stdlib_dos2unix_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::dos2unix' 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/stdlib_downcase_spec.rb b/spec/functions/stdlib_downcase_spec.rb new file mode 100644 index 000000000..271e3e5e9 --- /dev/null +++ b/spec/functions/stdlib_downcase_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::downcase' 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/stdlib_empty_spec.rb b/spec/functions/stdlib_empty_spec.rb new file mode 100644 index 000000000..3b58c5016 --- /dev/null +++ b/spec/functions/stdlib_empty_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::empty' 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/stdlib_enclose_ipv6_spec.rb b/spec/functions/stdlib_enclose_ipv6_spec.rb new file mode 100644 index 000000000..99f726d31 --- /dev/null +++ b/spec/functions/stdlib_enclose_ipv6_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::enclose_ipv6' 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/stdlib_ensure_packages_spec.rb b/spec/functions/stdlib_ensure_packages_spec.rb new file mode 100644 index 000000000..1af15ff11 --- /dev/null +++ b/spec/functions/stdlib_ensure_packages_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::ensure_packages' 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/stdlib_ensure_resource_spec.rb b/spec/functions/stdlib_ensure_resource_spec.rb new file mode 100644 index 000000000..dfa0a9d28 --- /dev/null +++ b/spec/functions/stdlib_ensure_resource_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::ensure_resource' 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/stdlib_ensure_resources_spec.rb b/spec/functions/stdlib_ensure_resources_spec.rb new file mode 100644 index 000000000..2fef36973 --- /dev/null +++ b/spec/functions/stdlib_ensure_resources_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::ensure_resources' 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/stdlib_flatten_spec.rb b/spec/functions/stdlib_flatten_spec.rb new file mode 100644 index 000000000..738b7d024 --- /dev/null +++ b/spec/functions/stdlib_flatten_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::flatten' 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/stdlib_floor_spec.rb b/spec/functions/stdlib_floor_spec.rb new file mode 100644 index 000000000..4212fbf29 --- /dev/null +++ b/spec/functions/stdlib_floor_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::floor' 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/stdlib_fqdn_rand_string_spec.rb b/spec/functions/stdlib_fqdn_rand_string_spec.rb new file mode 100644 index 000000000..9dbb88ebd --- /dev/null +++ b/spec/functions/stdlib_fqdn_rand_string_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::fqdn_rand_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/stdlib_fqdn_rotate_spec.rb b/spec/functions/stdlib_fqdn_rotate_spec.rb new file mode 100644 index 000000000..9dd928a06 --- /dev/null +++ b/spec/functions/stdlib_fqdn_rotate_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::fqdn_rotate' 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/stdlib_fqdn_uuid_spec.rb b/spec/functions/stdlib_fqdn_uuid_spec.rb new file mode 100644 index 000000000..eb7d6e66c --- /dev/null +++ b/spec/functions/stdlib_fqdn_uuid_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::fqdn_uuid' 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/stdlib_get_module_path_spec.rb b/spec/functions/stdlib_get_module_path_spec.rb new file mode 100644 index 000000000..7e3fdc339 --- /dev/null +++ b/spec/functions/stdlib_get_module_path_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::get_module_path' 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/stdlib_getparam_spec.rb b/spec/functions/stdlib_getparam_spec.rb new file mode 100644 index 000000000..2150a5d76 --- /dev/null +++ b/spec/functions/stdlib_getparam_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::getparam' 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/stdlib_getvar_spec.rb b/spec/functions/stdlib_getvar_spec.rb new file mode 100644 index 000000000..0ad4a7aa4 --- /dev/null +++ b/spec/functions/stdlib_getvar_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::getvar' 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/stdlib_glob_spec.rb b/spec/functions/stdlib_glob_spec.rb new file mode 100644 index 000000000..9672b49b3 --- /dev/null +++ b/spec/functions/stdlib_glob_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::glob' 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/stdlib_grep_spec.rb b/spec/functions/stdlib_grep_spec.rb new file mode 100644 index 000000000..21e484c68 --- /dev/null +++ b/spec/functions/stdlib_grep_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::grep' 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/stdlib_has_interface_with_spec.rb b/spec/functions/stdlib_has_interface_with_spec.rb new file mode 100644 index 000000000..cdaea877c --- /dev/null +++ b/spec/functions/stdlib_has_interface_with_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::has_interface_with' 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/stdlib_has_ip_address_spec.rb b/spec/functions/stdlib_has_ip_address_spec.rb new file mode 100644 index 000000000..bbf761e9e --- /dev/null +++ b/spec/functions/stdlib_has_ip_address_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::has_ip_address' 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/stdlib_has_ip_network_spec.rb b/spec/functions/stdlib_has_ip_network_spec.rb new file mode 100644 index 000000000..82e41bd83 --- /dev/null +++ b/spec/functions/stdlib_has_ip_network_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::has_ip_network' 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/stdlib_has_key_spec.rb b/spec/functions/stdlib_has_key_spec.rb new file mode 100644 index 000000000..dab28f9c3 --- /dev/null +++ b/spec/functions/stdlib_has_key_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::has_key' 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/stdlib_hash_spec.rb b/spec/functions/stdlib_hash_spec.rb new file mode 100644 index 000000000..3e3c7afa8 --- /dev/null +++ b/spec/functions/stdlib_hash_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::hash' 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/stdlib_intersection_spec.rb b/spec/functions/stdlib_intersection_spec.rb new file mode 100644 index 000000000..f7ddb9efa --- /dev/null +++ b/spec/functions/stdlib_intersection_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::intersection' 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/stdlib_is_absolute_path_spec.rb b/spec/functions/stdlib_is_absolute_path_spec.rb new file mode 100644 index 000000000..381e5c1b0 --- /dev/null +++ b/spec/functions/stdlib_is_absolute_path_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::is_absolute_path' 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/stdlib_is_array_spec.rb b/spec/functions/stdlib_is_array_spec.rb new file mode 100644 index 000000000..2fe601e62 --- /dev/null +++ b/spec/functions/stdlib_is_array_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::is_array' 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/stdlib_is_bool_spec.rb b/spec/functions/stdlib_is_bool_spec.rb new file mode 100644 index 000000000..4b3b4d063 --- /dev/null +++ b/spec/functions/stdlib_is_bool_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::is_bool' 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/stdlib_is_domain_name_spec.rb b/spec/functions/stdlib_is_domain_name_spec.rb new file mode 100644 index 000000000..8361fa42a --- /dev/null +++ b/spec/functions/stdlib_is_domain_name_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::is_domain_name' 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/stdlib_is_email_address_spec.rb b/spec/functions/stdlib_is_email_address_spec.rb new file mode 100644 index 000000000..0f68190b0 --- /dev/null +++ b/spec/functions/stdlib_is_email_address_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::is_email_address' 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/stdlib_is_float_spec.rb b/spec/functions/stdlib_is_float_spec.rb new file mode 100644 index 000000000..78519a65a --- /dev/null +++ b/spec/functions/stdlib_is_float_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::is_float' 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/stdlib_is_function_available_spec.rb b/spec/functions/stdlib_is_function_available_spec.rb new file mode 100644 index 000000000..581944834 --- /dev/null +++ b/spec/functions/stdlib_is_function_available_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::is_function_available' 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/stdlib_is_hash_spec.rb b/spec/functions/stdlib_is_hash_spec.rb new file mode 100644 index 000000000..563611e03 --- /dev/null +++ b/spec/functions/stdlib_is_hash_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::is_hash' 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/stdlib_is_integer_spec.rb b/spec/functions/stdlib_is_integer_spec.rb new file mode 100644 index 000000000..2e1424b2c --- /dev/null +++ b/spec/functions/stdlib_is_integer_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::is_integer' 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/stdlib_is_ip_address_spec.rb b/spec/functions/stdlib_is_ip_address_spec.rb new file mode 100644 index 000000000..b3635011e --- /dev/null +++ b/spec/functions/stdlib_is_ip_address_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::is_ip_address' 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/stdlib_is_ipv4_address_spec.rb b/spec/functions/stdlib_is_ipv4_address_spec.rb new file mode 100644 index 000000000..790502475 --- /dev/null +++ b/spec/functions/stdlib_is_ipv4_address_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::is_ipv4_address' 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/stdlib_is_ipv6_address_spec.rb b/spec/functions/stdlib_is_ipv6_address_spec.rb new file mode 100644 index 000000000..bebb8190a --- /dev/null +++ b/spec/functions/stdlib_is_ipv6_address_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::is_ipv6_address' 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/stdlib_is_mac_address_spec.rb b/spec/functions/stdlib_is_mac_address_spec.rb new file mode 100644 index 000000000..33da22d8a --- /dev/null +++ b/spec/functions/stdlib_is_mac_address_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::is_mac_address' 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/stdlib_is_numeric_spec.rb b/spec/functions/stdlib_is_numeric_spec.rb new file mode 100644 index 000000000..e6e07a9f8 --- /dev/null +++ b/spec/functions/stdlib_is_numeric_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::is_numeric' 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/stdlib_is_string_spec.rb b/spec/functions/stdlib_is_string_spec.rb new file mode 100644 index 000000000..c51c1f6bc --- /dev/null +++ b/spec/functions/stdlib_is_string_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::is_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/stdlib_join_keys_to_values_spec.rb b/spec/functions/stdlib_join_keys_to_values_spec.rb new file mode 100644 index 000000000..64225afda --- /dev/null +++ b/spec/functions/stdlib_join_keys_to_values_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::join_keys_to_values' 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/stdlib_join_spec.rb b/spec/functions/stdlib_join_spec.rb new file mode 100644 index 000000000..5c6630d9a --- /dev/null +++ b/spec/functions/stdlib_join_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::join' 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/stdlib_keys_spec.rb b/spec/functions/stdlib_keys_spec.rb new file mode 100644 index 000000000..79b990ba4 --- /dev/null +++ b/spec/functions/stdlib_keys_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::keys' 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/stdlib_load_module_metadata_spec.rb b/spec/functions/stdlib_load_module_metadata_spec.rb new file mode 100644 index 000000000..4c863ae8b --- /dev/null +++ b/spec/functions/stdlib_load_module_metadata_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::load_module_metadata' 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/stdlib_loadjson_spec.rb b/spec/functions/stdlib_loadjson_spec.rb new file mode 100644 index 000000000..c3c26cee8 --- /dev/null +++ b/spec/functions/stdlib_loadjson_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::loadjson' 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/stdlib_loadyaml_spec.rb b/spec/functions/stdlib_loadyaml_spec.rb new file mode 100644 index 000000000..5525366a4 --- /dev/null +++ b/spec/functions/stdlib_loadyaml_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::loadyaml' 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/stdlib_lstrip_spec.rb b/spec/functions/stdlib_lstrip_spec.rb new file mode 100644 index 000000000..769c5a0c2 --- /dev/null +++ b/spec/functions/stdlib_lstrip_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::lstrip' 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/stdlib_max_spec.rb b/spec/functions/stdlib_max_spec.rb new file mode 100644 index 000000000..2ea80d7e6 --- /dev/null +++ b/spec/functions/stdlib_max_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::max' 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/stdlib_member_spec.rb b/spec/functions/stdlib_member_spec.rb new file mode 100644 index 000000000..12ac3b0ef --- /dev/null +++ b/spec/functions/stdlib_member_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::member' 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/stdlib_merge_spec.rb b/spec/functions/stdlib_merge_spec.rb new file mode 100644 index 000000000..8c73d364c --- /dev/null +++ b/spec/functions/stdlib_merge_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::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/stdlib_min_spec.rb b/spec/functions/stdlib_min_spec.rb new file mode 100644 index 000000000..659c34cf1 --- /dev/null +++ b/spec/functions/stdlib_min_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::min' 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/stdlib_num2bool_spec.rb b/spec/functions/stdlib_num2bool_spec.rb new file mode 100644 index 000000000..01223395b --- /dev/null +++ b/spec/functions/stdlib_num2bool_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::num2bool' 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/stdlib_parsejson_spec.rb b/spec/functions/stdlib_parsejson_spec.rb new file mode 100644 index 000000000..c486bf834 --- /dev/null +++ b/spec/functions/stdlib_parsejson_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::parsejson' 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/stdlib_parseyaml_spec.rb b/spec/functions/stdlib_parseyaml_spec.rb new file mode 100644 index 000000000..b07334d66 --- /dev/null +++ b/spec/functions/stdlib_parseyaml_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::parseyaml' 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/stdlib_pick_default_spec.rb b/spec/functions/stdlib_pick_default_spec.rb new file mode 100644 index 000000000..2073c0fb8 --- /dev/null +++ b/spec/functions/stdlib_pick_default_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::pick_default' 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/stdlib_pick_spec.rb b/spec/functions/stdlib_pick_spec.rb new file mode 100644 index 000000000..93bd1da5a --- /dev/null +++ b/spec/functions/stdlib_pick_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::pick' 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/stdlib_prefix_spec.rb b/spec/functions/stdlib_prefix_spec.rb new file mode 100644 index 000000000..0883f43fe --- /dev/null +++ b/spec/functions/stdlib_prefix_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::prefix' 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/stdlib_private_spec.rb b/spec/functions/stdlib_private_spec.rb new file mode 100644 index 000000000..dca47c4ce --- /dev/null +++ b/spec/functions/stdlib_private_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::private' 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/stdlib_pry_spec.rb b/spec/functions/stdlib_pry_spec.rb new file mode 100644 index 000000000..d1dcebaec --- /dev/null +++ b/spec/functions/stdlib_pry_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::pry' 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/stdlib_pw_hash_spec.rb b/spec/functions/stdlib_pw_hash_spec.rb new file mode 100644 index 000000000..f84de020a --- /dev/null +++ b/spec/functions/stdlib_pw_hash_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::pw_hash' 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/stdlib_range_spec.rb b/spec/functions/stdlib_range_spec.rb new file mode 100644 index 000000000..b81702e61 --- /dev/null +++ b/spec/functions/stdlib_range_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::range' 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/stdlib_regexpescape_spec.rb b/spec/functions/stdlib_regexpescape_spec.rb new file mode 100644 index 000000000..d9ef94f25 --- /dev/null +++ b/spec/functions/stdlib_regexpescape_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::regexpescape' 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/stdlib_reject_spec.rb b/spec/functions/stdlib_reject_spec.rb new file mode 100644 index 000000000..645a3bd7c --- /dev/null +++ b/spec/functions/stdlib_reject_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::reject' 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/stdlib_reverse_spec.rb b/spec/functions/stdlib_reverse_spec.rb new file mode 100644 index 000000000..62089fe9f --- /dev/null +++ b/spec/functions/stdlib_reverse_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::reverse' 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/stdlib_round_spec.rb b/spec/functions/stdlib_round_spec.rb new file mode 100644 index 000000000..fb0c07f6b --- /dev/null +++ b/spec/functions/stdlib_round_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::round' 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/stdlib_rstrip_spec.rb b/spec/functions/stdlib_rstrip_spec.rb new file mode 100644 index 000000000..ad8f92b93 --- /dev/null +++ b/spec/functions/stdlib_rstrip_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::rstrip' 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/stdlib_seeded_rand_spec.rb b/spec/functions/stdlib_seeded_rand_spec.rb new file mode 100644 index 000000000..f00539d87 --- /dev/null +++ b/spec/functions/stdlib_seeded_rand_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::seeded_rand' 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/stdlib_shell_escape_spec.rb b/spec/functions/stdlib_shell_escape_spec.rb new file mode 100644 index 000000000..7eab76f75 --- /dev/null +++ b/spec/functions/stdlib_shell_escape_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::shell_escape' 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/stdlib_shell_join_spec.rb b/spec/functions/stdlib_shell_join_spec.rb new file mode 100644 index 000000000..c9415afe4 --- /dev/null +++ b/spec/functions/stdlib_shell_join_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::shell_join' 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/stdlib_shell_split_spec.rb b/spec/functions/stdlib_shell_split_spec.rb new file mode 100644 index 000000000..b8e201e44 --- /dev/null +++ b/spec/functions/stdlib_shell_split_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::shell_split' 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/stdlib_shuffle_spec.rb b/spec/functions/stdlib_shuffle_spec.rb new file mode 100644 index 000000000..d001ae05b --- /dev/null +++ b/spec/functions/stdlib_shuffle_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::shuffle' 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/stdlib_size_spec.rb b/spec/functions/stdlib_size_spec.rb new file mode 100644 index 000000000..9bc03b11b --- /dev/null +++ b/spec/functions/stdlib_size_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::size' 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/stdlib_sort_spec.rb b/spec/functions/stdlib_sort_spec.rb new file mode 100644 index 000000000..5f16c527e --- /dev/null +++ b/spec/functions/stdlib_sort_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::sort' 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/stdlib_squeeze_spec.rb b/spec/functions/stdlib_squeeze_spec.rb new file mode 100644 index 000000000..23b96ab2c --- /dev/null +++ b/spec/functions/stdlib_squeeze_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::squeeze' 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/stdlib_str2bool_spec.rb b/spec/functions/stdlib_str2bool_spec.rb new file mode 100644 index 000000000..cde02c887 --- /dev/null +++ b/spec/functions/stdlib_str2bool_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::str2bool' 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/stdlib_str2saltedsha512_spec.rb b/spec/functions/stdlib_str2saltedsha512_spec.rb new file mode 100644 index 000000000..8c8402778 --- /dev/null +++ b/spec/functions/stdlib_str2saltedsha512_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::str2saltedsha512' 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/stdlib_strftime_spec.rb b/spec/functions/stdlib_strftime_spec.rb new file mode 100644 index 000000000..f0da03e7f --- /dev/null +++ b/spec/functions/stdlib_strftime_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::strftime' 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/stdlib_strip_spec.rb b/spec/functions/stdlib_strip_spec.rb new file mode 100644 index 000000000..2ea50f8be --- /dev/null +++ b/spec/functions/stdlib_strip_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::strip' 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/stdlib_suffix_spec.rb b/spec/functions/stdlib_suffix_spec.rb new file mode 100644 index 000000000..6a664444f --- /dev/null +++ b/spec/functions/stdlib_suffix_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::suffix' 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/stdlib_swapcase_spec.rb b/spec/functions/stdlib_swapcase_spec.rb new file mode 100644 index 000000000..fbece45e8 --- /dev/null +++ b/spec/functions/stdlib_swapcase_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::swapcase' 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/stdlib_time_spec.rb b/spec/functions/stdlib_time_spec.rb new file mode 100644 index 000000000..deb91704d --- /dev/null +++ b/spec/functions/stdlib_time_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::time' 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/stdlib_to_bytes_spec.rb b/spec/functions/stdlib_to_bytes_spec.rb new file mode 100644 index 000000000..20b52dcf5 --- /dev/null +++ b/spec/functions/stdlib_to_bytes_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::to_bytes' 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/stdlib_try_get_value_spec.rb b/spec/functions/stdlib_try_get_value_spec.rb new file mode 100644 index 000000000..2dca43c6d --- /dev/null +++ b/spec/functions/stdlib_try_get_value_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::try_get_value' 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/stdlib_type3x_spec.rb b/spec/functions/stdlib_type3x_spec.rb new file mode 100644 index 000000000..9be3acb3c --- /dev/null +++ b/spec/functions/stdlib_type3x_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::type3x' 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/stdlib_type_spec.rb b/spec/functions/stdlib_type_spec.rb new file mode 100644 index 000000000..e3f3d4115 --- /dev/null +++ b/spec/functions/stdlib_type_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::type' 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/stdlib_union_spec.rb b/spec/functions/stdlib_union_spec.rb new file mode 100644 index 000000000..b7792f6e4 --- /dev/null +++ b/spec/functions/stdlib_union_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::union' 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/stdlib_unique_spec.rb b/spec/functions/stdlib_unique_spec.rb new file mode 100644 index 000000000..ae6e0f0a9 --- /dev/null +++ b/spec/functions/stdlib_unique_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::unique' 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/stdlib_unix2dos_spec.rb b/spec/functions/stdlib_unix2dos_spec.rb new file mode 100644 index 000000000..956b26389 --- /dev/null +++ b/spec/functions/stdlib_unix2dos_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::unix2dos' 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/stdlib_upcase_spec.rb b/spec/functions/stdlib_upcase_spec.rb new file mode 100644 index 000000000..405b74e62 --- /dev/null +++ b/spec/functions/stdlib_upcase_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::upcase' 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/stdlib_uriescape_spec.rb b/spec/functions/stdlib_uriescape_spec.rb new file mode 100644 index 000000000..3fc569184 --- /dev/null +++ b/spec/functions/stdlib_uriescape_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::uriescape' 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/stdlib_validate_absolute_path_spec.rb b/spec/functions/stdlib_validate_absolute_path_spec.rb new file mode 100644 index 000000000..5d37cef61 --- /dev/null +++ b/spec/functions/stdlib_validate_absolute_path_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::validate_absolute_path' 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/stdlib_validate_array_spec.rb b/spec/functions/stdlib_validate_array_spec.rb new file mode 100644 index 000000000..984b897b2 --- /dev/null +++ b/spec/functions/stdlib_validate_array_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::validate_array' 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/stdlib_validate_augeas_spec.rb b/spec/functions/stdlib_validate_augeas_spec.rb new file mode 100644 index 000000000..337cb8c78 --- /dev/null +++ b/spec/functions/stdlib_validate_augeas_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::validate_augeas' 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/stdlib_validate_bool_spec.rb b/spec/functions/stdlib_validate_bool_spec.rb new file mode 100644 index 000000000..999ccd582 --- /dev/null +++ b/spec/functions/stdlib_validate_bool_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::validate_bool' 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/stdlib_validate_cmd_spec.rb b/spec/functions/stdlib_validate_cmd_spec.rb new file mode 100644 index 000000000..81d34e556 --- /dev/null +++ b/spec/functions/stdlib_validate_cmd_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::validate_cmd' 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/stdlib_validate_domain_name_spec.rb b/spec/functions/stdlib_validate_domain_name_spec.rb new file mode 100644 index 000000000..69794c46d --- /dev/null +++ b/spec/functions/stdlib_validate_domain_name_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::validate_domain_name' 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/stdlib_validate_email_address_spec.rb b/spec/functions/stdlib_validate_email_address_spec.rb new file mode 100644 index 000000000..a012125b2 --- /dev/null +++ b/spec/functions/stdlib_validate_email_address_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::validate_email_address' 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/stdlib_validate_hash_spec.rb b/spec/functions/stdlib_validate_hash_spec.rb new file mode 100644 index 000000000..a49e27cac --- /dev/null +++ b/spec/functions/stdlib_validate_hash_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::validate_hash' 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/stdlib_validate_integer_spec.rb b/spec/functions/stdlib_validate_integer_spec.rb new file mode 100644 index 000000000..ef79518db --- /dev/null +++ b/spec/functions/stdlib_validate_integer_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::validate_integer' 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/stdlib_validate_ip_address_spec.rb b/spec/functions/stdlib_validate_ip_address_spec.rb new file mode 100644 index 000000000..a08f776f4 --- /dev/null +++ b/spec/functions/stdlib_validate_ip_address_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::validate_ip_address' 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/stdlib_validate_ipv4_address_spec.rb b/spec/functions/stdlib_validate_ipv4_address_spec.rb new file mode 100644 index 000000000..489fc4b3b --- /dev/null +++ b/spec/functions/stdlib_validate_ipv4_address_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::validate_ipv4_address' 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/stdlib_validate_ipv6_address_spec.rb b/spec/functions/stdlib_validate_ipv6_address_spec.rb new file mode 100644 index 000000000..a89086fa8 --- /dev/null +++ b/spec/functions/stdlib_validate_ipv6_address_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::validate_ipv6_address' 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/stdlib_validate_numeric_spec.rb b/spec/functions/stdlib_validate_numeric_spec.rb new file mode 100644 index 000000000..ba9c191dd --- /dev/null +++ b/spec/functions/stdlib_validate_numeric_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::validate_numeric' 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/stdlib_validate_re_spec.rb b/spec/functions/stdlib_validate_re_spec.rb new file mode 100644 index 000000000..1542e06be --- /dev/null +++ b/spec/functions/stdlib_validate_re_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::validate_re' 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/stdlib_validate_slength_spec.rb b/spec/functions/stdlib_validate_slength_spec.rb new file mode 100644 index 000000000..6f1c92889 --- /dev/null +++ b/spec/functions/stdlib_validate_slength_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::validate_slength' 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/stdlib_validate_string_spec.rb b/spec/functions/stdlib_validate_string_spec.rb new file mode 100644 index 000000000..2976d6d1b --- /dev/null +++ b/spec/functions/stdlib_validate_string_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::validate_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/stdlib_values_at_spec.rb b/spec/functions/stdlib_values_at_spec.rb new file mode 100644 index 000000000..85002013a --- /dev/null +++ b/spec/functions/stdlib_values_at_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::values_at' 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/stdlib_values_spec.rb b/spec/functions/stdlib_values_spec.rb new file mode 100644 index 000000000..ad4699da5 --- /dev/null +++ b/spec/functions/stdlib_values_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::values' 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/stdlib_zip_spec.rb b/spec/functions/stdlib_zip_spec.rb new file mode 100644 index 000000000..59c23d3b9 --- /dev/null +++ b/spec/functions/stdlib_zip_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'stdlib::zip' 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