From 27323f74e69a5b1a74538df986ffa7284e46fb45 Mon Sep 17 00:00:00 2001 From: Artur Gadelshin Date: Mon, 9 Nov 2015 15:49:50 +0300 Subject: [PATCH] (MODULES-2767) fix mysql_table_exists: add check for args.size, fix rspec test --- lib/puppet/parser/functions/mysql_table_exists.rb | 3 ++- spec/unit/puppet/functions/mysql_table_exists_spec.rb | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/puppet/parser/functions/mysql_table_exists.rb b/lib/puppet/parser/functions/mysql_table_exists.rb index 9500eea..ff089d8 100644 --- a/lib/puppet/parser/functions/mysql_table_exists.rb +++ b/lib/puppet/parser/functions/mysql_table_exists.rb @@ -10,7 +10,8 @@ module Puppet::Parser::Functions EOS ) do |args| - return raise(Puppet::ParseError, "mysql_table_exists() accept 1 argument - table string like 'database_name.table_name'") unless match = args[0].match(/(.*)\.(.*)/) + return raise(Puppet::ParseError, + "mysql_table_exists() accept 1 argument - table string like 'database_name.table_name'") unless (args.size == 1 and match = args[0].match(/(.*)\.(.*)/)) db_name, table_name = match.captures return true if (db_name.eql?('*') or table_name.eql?('*')) ## *.* is valid table string, but we shouldn't check it for existence diff --git a/spec/unit/puppet/functions/mysql_table_exists_spec.rb b/spec/unit/puppet/functions/mysql_table_exists_spec.rb index 1c5eac3..03fb1cb 100644 --- a/spec/unit/puppet/functions/mysql_table_exists_spec.rb +++ b/spec/unit/puppet/functions/mysql_table_exists_spec.rb @@ -15,8 +15,12 @@ describe 'the mysql_table_exists function' do expect { scope.function_mysql_table_exists([]) }.to( raise_error(Puppet::ParseError)) end + it 'should raise a ParserError if argument doesn\'t look like database_name.table_name' do + expect { scope.function_mysql_table_exists(['foo_bar']) }.to( raise_error(Puppet::ParseError)) + end + it 'should raise a ParseError if there is more than 1 arguments' do - expect { scope.function_mysql_table_exists(%w(foo bar)) }.to( raise_error(Puppet::ParseError)) + expect { scope.function_mysql_table_exists(%w(foo.bar foo.bar)) }.to( raise_error(Puppet::ParseError)) end end \ No newline at end of file