Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SoledaD208 committed Oct 31, 2024
1 parent a086778 commit 24bf639
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
42 changes: 21 additions & 21 deletions tests/integration/targets/test_mysql_user/tasks/issue-671.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

block:
- name: Issue-671| test setup | drop database
mysql_db:
community.mysql.mysql_db:
<<: *mysql_params
name: "{{ item }}"
state: absent
Expand All @@ -26,7 +26,7 @@
- bar

- name: Issue-671| test setup | create database
mysql_db:
community.mysql.mysql_db:
<<: *mysql_params
name: "{{ item }}"
state: present
Expand All @@ -35,47 +35,49 @@
- bar

- name: Issue-671| test setup | get value of GLOBAL.sql_mode
mysql_query:
community.mysql.mysql_query:
<<: *mysql_params
query: 'select @@GLOBAL.sql_mode AS sql_mode'
register: sql_mode_orig

- name: Issue-671| Assert sql_mode_orig
assert:
ansible.builtin.assert:
that:
- sql_mode_orig.query_result[0][0].sql_mode != None

- name: Issue-671| enable sql_mode ANSI_QUOTES
mysql_variables:
community.mysql.mysql_variables:
<<: *mysql_params
variable: sql_mode
value: '{{ sql_mode_orig.query_result[0][0].sql_mode }},ANSI_QUOTES'
mode: "{% if db_engine == 'mariadb' %}global{% else %}persist{% endif %}"

- name: Issue-671| Copy SQL scripts to remote
copy:
ansible.builtin.copy:
src: "{{ item }}"
dest: "{{ remote_tmp_dir }}/{{ item | basename }}"
with_items:
loop:
- create-function.sql
- create-procedure.sql

- name: Issue-671| Create function for test
shell: "{{ mysql_command }} < {{ remote_tmp_dir }}/create-function.sql"
ansible.builtin.shell:
cmd: "{{ mysql_command }} < {{ remote_tmp_dir }}/create-function.sql"

- name: Issue-671| Create procedure for test
shell: "{{ mysql_command }} < {{ remote_tmp_dir }}/create-procedure.sql"
ansible.builtin.shell:
cmd: "{{ mysql_command }} < {{ remote_tmp_dir }}/create-procedure.sql"

- name: Issue-671| Create user with FUNCTION and PROCEDURE privileges
mysql_user:
community.mysql.mysql_user:
<<: *mysql_params
name: '{{ user_name_2 }}'
password: '{{ user_password_2 }}'
state: present
priv: 'FUNCTION foo.function:EXECUTE/foo.*:SELECT/PROCEDURE bar.procedure:EXECUTE'

- name: Issue-671| Grant the privileges again, remove ANSI_QUOTES from the session variable
mysql_user:
community.mysql.mysql_user:
<<: *mysql_params
session_vars:
sql_mode: ""
Expand All @@ -84,15 +86,11 @@
state: present
priv: 'FUNCTION foo.function:EXECUTE/foo.*:SELECT/PROCEDURE bar.procedure:EXECUTE'
register: result

- name: Issue-671| Assert Create user with FUNCTION and PROCEDURE privileges
assert:
that:
- result is success
- result is not changed
failed_when:
- result is failed or result is changed

- name: Issue-671| Test teardown | cleanup databases
mysql_db:
community.mysql.mysql_db:
<<: *mysql_params
name: "{{ item }}"
state: absent
Expand All @@ -101,12 +99,14 @@
- bar

- name: Issue-671| set sql_mode back to original value
mysql_variables:
community.mysql.mysql_variables:
<<: *mysql_params
variable: sql_mode
value: '{{ sql_mode_orig.query_result[0][0].sql_mode }}'
mode: "{% if db_engine == 'mariadb' %}global{% else %}persist{% endif %}"

- include_tasks: utils/remove_user.yml
- name: Issue-671| Teardown user_name_2
ansible.builtin.include_tasks:
file: utils/remove_user.yml
vars:
user_name: "{{ user_name_2 }}"
user_name: "{{ user_name_2 }}"
6 changes: 4 additions & 2 deletions tests/integration/targets/test_mysql_user/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,11 @@
tags:
- issue-64560

- import_tasks: issue-671.yaml
- name: Test ANSI_QUOTES
ansible.builtin.import_tasks:
file: issue-671.yaml
tags:
- issue-671
- issue-671

# Test that mysql_user still works with force_context enabled (database set to "mysql")
# (https://github.com/ansible-collections/community.mysql/issues/265)
Expand Down

0 comments on commit 24bf639

Please sign in to comment.