From 24bf6397c9f986f66fa5be366164cd99c0a38e1c Mon Sep 17 00:00:00 2001 From: SoledaD208 Date: Thu, 31 Oct 2024 22:35:42 +0700 Subject: [PATCH] improve tests --- .../test_mysql_user/tasks/issue-671.yaml | 42 +++++++++---------- .../targets/test_mysql_user/tasks/main.yml | 6 ++- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/tests/integration/targets/test_mysql_user/tasks/issue-671.yaml b/tests/integration/targets/test_mysql_user/tasks/issue-671.yaml index fa3d3213..3696cf00 100644 --- a/tests/integration/targets/test_mysql_user/tasks/issue-671.yaml +++ b/tests/integration/targets/test_mysql_user/tasks/issue-671.yaml @@ -17,7 +17,7 @@ block: - name: Issue-671| test setup | drop database - mysql_db: + community.mysql.mysql_db: <<: *mysql_params name: "{{ item }}" state: absent @@ -26,7 +26,7 @@ - bar - name: Issue-671| test setup | create database - mysql_db: + community.mysql.mysql_db: <<: *mysql_params name: "{{ item }}" state: present @@ -35,39 +35,41 @@ - 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 }}' @@ -75,7 +77,7 @@ 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: "" @@ -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 @@ -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 }}" \ No newline at end of file diff --git a/tests/integration/targets/test_mysql_user/tasks/main.yml b/tests/integration/targets/test_mysql_user/tasks/main.yml index 4e9046f3..9244570f 100644 --- a/tests/integration/targets/test_mysql_user/tasks/main.yml +++ b/tests/integration/targets/test_mysql_user/tasks/main.yml @@ -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)