Improve documentation and tests

This commit is contained in:
Andrew Klychkov 2020-11-01 21:42:02 +03:00
parent 639b729ec7
commit a4c87570b9
2 changed files with 15 additions and 1 deletions

View file

@ -20,6 +20,7 @@ options:
query:
description:
- SQL query to run. Multiple queries can be passed using YAML list syntax.
- Must be a string or YAML list.
type: raw
required: yes
positional_args:
@ -146,6 +147,10 @@ def main():
check_hostname = module.params['check_hostname']
config_file = module.params['config_file']
query = module.params["query"]
if not isinstance(query, str) and not isinstance(query, list):
module.fail_json("the query option value must be string or list, passed %s" % type(query))
if module.params["single_transaction"]:
autocommit = False
else:

View file

@ -243,7 +243,12 @@
<<: *mysql_params
login_db: '{{ test_db }}'
query: 'CREATE TABLE {{ test_table3 }} (id int, story text)'
register: result
- name: Add data to {{ test_table3 }}
mysql_query:
<<: *mysql_params
login_db: '{{ test_db }}'
query: "INSERT INTO {{ test_table3 }} (id, story) VALUES (1, 'first'), (2, 'second')"
- name: Select from {{ test_table3 }}
mysql_query:
@ -252,6 +257,10 @@
query: 'SELECT id, story FROM {{ test_table3 }}'
register: result
- assert:
that:
- result.rowcount == [2]
- name: Drop db {{ test_db }}
mysql_query:
<<: *mysql_params