Skip to content

Commit 2dcbd78

Browse files
authored
mysql_query, mysql_user: simple refactoring of type checks (#58)
* mysql_query: simple refactoring of query type check * do the same for mysql_user * Improve integration test coverage
1 parent b2bde48 commit 2dcbd78

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
minor_changes:
2+
- mysql_query - simple refactoring of query type check (https://github.com/ansible-collections/community.mysql/pull/58).
3+
- mysql_user - simple refactoring of priv type check (https://github.com/ansible-collections/community.mysql/pull/58).

plugins/modules/mysql_query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def main():
149149
config_file = module.params['config_file']
150150
query = module.params["query"]
151151

152-
if not isinstance(query, str) and not isinstance(query, list):
152+
if not isinstance(query, (str, list)):
153153
module.fail_json(msg="the query option value must be a string or list, passed %s" % type(query))
154154

155155
if isinstance(query, str):

plugins/modules/mysql_user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,7 @@ def main():
10441044
plugin_hash_string = module.params["plugin_hash_string"]
10451045
plugin_auth_string = module.params["plugin_auth_string"]
10461046
resource_limits = module.params["resource_limits"]
1047-
if priv and not (isinstance(priv, str) or isinstance(priv, dict)):
1047+
if priv and not isinstance(priv, (str, dict)):
10481048
module.fail_json(msg="priv parameter must be str or dict but %s was passed" % type(priv))
10491049

10501050
if priv and isinstance(priv, dict):

tests/integration/targets/test_mysql_user/tasks/main.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,25 @@
192192
- "'%db' in result.stdout"
193193
- "'SELECT' in result.stdout"
194194

195+
- name: test priv type check, must fail
196+
mysql_user:
197+
<<: *mysql_params
198+
name: '{{ user_name_1 }}'
199+
priv:
200+
- unsuitable
201+
- type
202+
append_privs: yes
203+
host_all: yes
204+
password: '{{ user_password_1 }}'
205+
register: result
206+
ignore_errors: yes
207+
208+
- name: check fail message
209+
assert:
210+
that:
211+
- result is failed
212+
- result.msg is search('priv parameter must be str or dict')
213+
195214
- name: change user access to database via wildcard
196215
mysql_user:
197216
<<: *mysql_params

0 commit comments

Comments
 (0)