Skip to content

Commit d1f1601

Browse files
committed
Merge pull request #777 from pondohva/mysql_table_exists_fix
(MODULES-2767) fix mysql_table_exists: add check for args.size, fix rspec test
2 parents 63e0768 + 27323f7 commit d1f1601

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/puppet/parser/functions/mysql_table_exists.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ module Puppet::Parser::Functions
1010
EOS
1111
) do |args|
1212

13-
return raise(Puppet::ParseError, "mysql_table_exists() accept 1 argument - table string like 'database_name.table_name'") unless match = args[0].match(/(.*)\.(.*)/)
13+
return raise(Puppet::ParseError,
14+
"mysql_table_exists() accept 1 argument - table string like 'database_name.table_name'") unless (args.size == 1 and match = args[0].match(/(.*)\.(.*)/))
1415

1516
db_name, table_name = match.captures
1617
return true if (db_name.eql?('*') or table_name.eql?('*')) ## *.* is valid table string, but we shouldn't check it for existence

spec/unit/puppet/functions/mysql_table_exists_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515
expect { scope.function_mysql_table_exists([]) }.to( raise_error(Puppet::ParseError))
1616
end
1717

18+
it 'should raise a ParserError if argument doesn\'t look like database_name.table_name' do
19+
expect { scope.function_mysql_table_exists(['foo_bar']) }.to( raise_error(Puppet::ParseError))
20+
end
21+
1822
it 'should raise a ParseError if there is more than 1 arguments' do
19-
expect { scope.function_mysql_table_exists(%w(foo bar)) }.to( raise_error(Puppet::ParseError))
23+
expect { scope.function_mysql_table_exists(%w(foo.bar foo.bar)) }.to( raise_error(Puppet::ParseError))
2024
end
2125

2226
end

0 commit comments

Comments
 (0)