Skip to content

Commit

Permalink
Add deprecation warnings to remaining validates
Browse files Browse the repository at this point in the history
  • Loading branch information
Helen Campbell committed Sep 26, 2016
1 parent 0ec7ffa commit 055dbb6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/puppet/parser/functions/validate_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ module Puppet::Parser::Functions
ENDHEREDOC

function_deprecation([:puppet_3_type_check, '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.'])

unless args.length > 0 then
raise Puppet::ParseError, ("validate_hash(): wrong number of arguments (#{args.length}; must be > 0)")
end
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/parser/functions/validate_slength.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ module Puppet::Parser::Functions
ENDHEREDOC

function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::String[x]. 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 or args.length == 3

input, max_length, min_length = *args
Expand Down
12 changes: 12 additions & 0 deletions spec/functions/validate_hash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@
it { is_expected.not_to eq(nil) }
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }

describe 'check for deprecation warning' do
after(:context) do
ENV.delete('STDLIB_LOG_DEPRECATIONS')
end
# Checking for deprecation warning
it 'should display a single deprecation' do
ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
scope.expects(:warning).with(includes('This method is deprecated'))
is_expected.to run.with_params({'key' => 'value'})
end
end

describe 'valid inputs' do
it { is_expected.to run.with_params({}) }
it { is_expected.to run.with_params({'key' => 'value'}) }
Expand Down
11 changes: 11 additions & 0 deletions spec/functions/validate_slength_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
require 'spec_helper'

describe 'validate_slength' do
after(:context) do
ENV.delete('STDLIB_LOG_DEPRECATIONS')
end

# Checking for deprecation warning
it 'should display a single deprecation' do
ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
scope.expects(:warning).with(includes('This method is deprecated'))
is_expected.to run.with_params('1234567890', 10)
end

describe 'signature validation' do
it { is_expected.not_to eq(nil) }
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
Expand Down

0 comments on commit 055dbb6

Please sign in to comment.