mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-07-22 04:40:23 -07:00
initial commit (#1)
* initial commit * removed remaining references to community.general * enabled integration pipeline * switched from preconfigured replication topology to simple multinode install * updated version from 1.0.0 to 0.1.0
This commit is contained in:
parent
9fcbbaad81
commit
c26bc095ad
89 changed files with 8774 additions and 135 deletions
|
@ -0,0 +1,9 @@
|
|||
mysql_user: root
|
||||
mysql_password: msandbox
|
||||
mysql_primary_port: 3307
|
||||
|
||||
db_name: data
|
||||
test_db: testdb
|
||||
test_table1: test1
|
||||
test_table2: test2
|
||||
test_script_path: /tmp/test.sql
|
2
tests/integration/targets/test_mysql_query/meta/main.yml
Normal file
2
tests/integration/targets/test_mysql_query/meta/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- setup_mysql
|
|
@ -0,0 +1,2 @@
|
|||
# mysql_query module initial CI tests
|
||||
- import_tasks: mysql_query_initial.yml
|
|
@ -0,0 +1,250 @@
|
|||
# Test code for mysql_query module
|
||||
# Copyright: (c) 2020, Andrew Klychkov (@Andersson007) <aaklychkov@mail.ru>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
- vars:
|
||||
mysql_parameters: &mysql_params
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
|
||||
block:
|
||||
|
||||
- name: Create db {{ test_db }}
|
||||
mysql_query:
|
||||
<<: *mysql_params
|
||||
query: 'CREATE DATABASE {{ test_db }}'
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.executed_queries == ['CREATE DATABASE {{ test_db }}']
|
||||
|
||||
- name: Create {{ test_table1 }}
|
||||
mysql_query:
|
||||
<<: *mysql_params
|
||||
login_db: '{{ test_db }}'
|
||||
query: 'CREATE TABLE {{ test_table1 }} (id int)'
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.executed_queries == ['CREATE TABLE {{ test_table1 }} (id int)']
|
||||
|
||||
- name: Insert test data
|
||||
mysql_query:
|
||||
<<: *mysql_params
|
||||
login_db: '{{ test_db }}'
|
||||
query:
|
||||
- 'INSERT INTO {{ test_table1 }} VALUES (1), (2)'
|
||||
- 'INSERT INTO {{ test_table1 }} VALUES (3)'
|
||||
single_transaction: yes
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.rowcount == [2, 1]
|
||||
- result.executed_queries == ['INSERT INTO {{ test_table1 }} VALUES (1), (2)', 'INSERT INTO {{ test_table1 }} VALUES (3)']
|
||||
|
||||
- name: Check data in {{ test_table1 }}
|
||||
mysql_query:
|
||||
<<: *mysql_params
|
||||
login_db: '{{ test_db }}'
|
||||
query: 'SELECT * FROM {{ test_table1 }}'
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is not changed
|
||||
- result.executed_queries == ['SELECT * FROM {{ test_table1 }}']
|
||||
- result.rowcount == [3]
|
||||
- result.query_result[0][0].id == 1
|
||||
- result.query_result[0][1].id == 2
|
||||
- result.query_result[0][2].id == 3
|
||||
|
||||
- name: Check data in {{ test_table1 }} using positional args
|
||||
mysql_query:
|
||||
<<: *mysql_params
|
||||
login_db: '{{ test_db }}'
|
||||
query: 'SELECT * FROM {{ test_table1 }} WHERE id = %s'
|
||||
positional_args:
|
||||
- 1
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is not changed
|
||||
- result.executed_queries == ["SELECT * FROM {{ test_table1 }} WHERE id = 1"]
|
||||
- result.rowcount == [1]
|
||||
- result.query_result[0][0].id == 1
|
||||
|
||||
- name: Check data in {{ test_table1 }} using named args
|
||||
mysql_query:
|
||||
<<: *mysql_params
|
||||
login_db: '{{ test_db }}'
|
||||
query: 'SELECT * FROM {{ test_table1 }} WHERE id = %(some_id)s'
|
||||
named_args:
|
||||
some_id: 1
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is not changed
|
||||
- result.executed_queries == ["SELECT * FROM {{ test_table1 }} WHERE id = 1"]
|
||||
- result.rowcount == [1]
|
||||
- result.query_result[0][0].id == 1
|
||||
|
||||
- name: Update data in {{ test_table1 }}
|
||||
mysql_query:
|
||||
<<: *mysql_params
|
||||
login_db: '{{ test_db }}'
|
||||
query: 'UPDATE {{ test_table1 }} SET id = %(new_id)s WHERE id = %(current_id)s'
|
||||
named_args:
|
||||
current_id: 1
|
||||
new_id: 0
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.executed_queries == ['UPDATE {{ test_table1 }} SET id = 0 WHERE id = 1']
|
||||
- result.rowcount == [1]
|
||||
|
||||
- name: Check the prev update - row with value 1 does not exist anymore
|
||||
mysql_query:
|
||||
<<: *mysql_params
|
||||
login_db: '{{ test_db }}'
|
||||
query: 'SELECT * FROM {{ test_table1 }} WHERE id = %(some_id)s'
|
||||
named_args:
|
||||
some_id: 1
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is not changed
|
||||
- result.executed_queries == ['SELECT * FROM {{ test_table1 }} WHERE id = 1']
|
||||
- result.rowcount == [0]
|
||||
|
||||
- name: Check the prev update - row with value - exist
|
||||
mysql_query:
|
||||
<<: *mysql_params
|
||||
login_db: '{{ test_db }}'
|
||||
query: 'SELECT * FROM {{ test_table1 }} WHERE id = %(some_id)s'
|
||||
named_args:
|
||||
some_id: 0
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is not changed
|
||||
- result.executed_queries == ['SELECT * FROM {{ test_table1 }} WHERE id = 0']
|
||||
- result.rowcount == [1]
|
||||
|
||||
- name: Update data in {{ test_table1 }} again
|
||||
mysql_query:
|
||||
<<: *mysql_params
|
||||
login_db: '{{ test_db }}'
|
||||
query: 'UPDATE {{ test_table1 }} SET id = %(new_id)s WHERE id = %(current_id)s'
|
||||
named_args:
|
||||
current_id: 1
|
||||
new_id: 0
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is not changed
|
||||
- result.executed_queries == ['UPDATE {{ test_table1 }} SET id = 0 WHERE id = 1']
|
||||
- result.rowcount == [0]
|
||||
|
||||
- name: Delete data from {{ test_table1 }}
|
||||
mysql_query:
|
||||
<<: *mysql_params
|
||||
login_db: '{{ test_db }}'
|
||||
query:
|
||||
- 'DELETE FROM {{ test_table1 }} WHERE id = 0'
|
||||
- 'SELECT * FROM {{ test_table1 }} WHERE id = 0'
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.executed_queries == ['DELETE FROM {{ test_table1 }} WHERE id = 0', 'SELECT * FROM {{ test_table1 }} WHERE id = 0']
|
||||
- result.rowcount == [1, 0]
|
||||
|
||||
- name: Delete data from {{ test_table1 }} again
|
||||
mysql_query:
|
||||
<<: *mysql_params
|
||||
login_db: '{{ test_db }}'
|
||||
query: 'DELETE FROM {{ test_table1 }} WHERE id = 0'
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is not changed
|
||||
- result.executed_queries == ['DELETE FROM {{ test_table1 }} WHERE id = 0']
|
||||
- result.rowcount == [0]
|
||||
|
||||
- name: Truncate {{ test_table1 }}
|
||||
mysql_query:
|
||||
<<: *mysql_params
|
||||
login_db: '{{ test_db }}'
|
||||
query:
|
||||
- 'TRUNCATE {{ test_table1 }}'
|
||||
- 'SELECT * FROM {{ test_table1 }}'
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.executed_queries == ['TRUNCATE {{ test_table1 }}', 'SELECT * FROM {{ test_table1 }}']
|
||||
- result.rowcount == [0, 0]
|
||||
|
||||
- name: Rename {{ test_table1 }}
|
||||
mysql_query:
|
||||
<<: *mysql_params
|
||||
login_db: '{{ test_db }}'
|
||||
query: 'RENAME TABLE {{ test_table1 }} TO {{ test_table2 }}'
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.executed_queries == ['RENAME TABLE {{ test_table1 }} TO {{ test_table2 }}']
|
||||
- result.rowcount == [0]
|
||||
|
||||
- name: Check the prev rename
|
||||
mysql_query:
|
||||
<<: *mysql_params
|
||||
login_db: '{{ test_db }}'
|
||||
query: 'SELECT * FROM {{ test_table1 }}'
|
||||
register: result
|
||||
ignore_errors: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.failed == true
|
||||
|
||||
- name: Check the prev rename
|
||||
mysql_query:
|
||||
<<: *mysql_params
|
||||
login_db: '{{ test_db }}'
|
||||
query: 'SELECT * FROM {{ test_table2 }}'
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.rowcount == [0]
|
||||
|
||||
- name: Drop db {{ test_db }}
|
||||
mysql_query:
|
||||
<<: *mysql_params
|
||||
query: 'DROP DATABASE {{ test_db }}'
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.executed_queries == ['DROP DATABASE {{ test_db }}']
|
Loading…
Add table
Add a link
Reference in a new issue