(MODULES-2767) fix mysql_table_exists: add check for args.size, fix rspec test

This commit is contained in:
Artur Gadelshin 2015-11-09 15:49:50 +03:00
parent 63e0768775
commit 27323f74e6
2 changed files with 7 additions and 2 deletions

View file

@ -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

View file

@ -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