mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-07-22 04:40:23 -07:00
mysql_user: fixed encrypted option for MySQL 8.0 and test coverage (#79)
* mysql_user: fixed encrypted option for MySQL 8.0 and test coverage The purpose of this change was originally to expand test coverage to unblock #76, but an issue was detected with the encrypted parameter on MySQL 8.0 in the process of writing the tests. Additionally, user_password_update_test.yml had been disabled at some point, so I opted to replace it with two new files that will focus on the password and plugin auth paths. * Updated tests to cover a couple of missing branches * Skip tests that rely on sha256_password if pymysql < 0.9 * Cover the case where pymysql isn't installed for plugin tests * Added better plugin auth checking to tests and other minor changes * Fixed version detection to explicitly handle MariaDB * Removed unneeded import from previous change * Remove whitespace that was introduced by change that was removed * Added unit tests for missing coverage
This commit is contained in:
parent
2de3a57021
commit
06907715d7
12 changed files with 781 additions and 200 deletions
0
tests/unit/plugins/module_utils/__init__.py
Normal file
0
tests/unit/plugins/module_utils/__init__.py
Normal file
24
tests/unit/plugins/module_utils/test_mysql.py
Normal file
24
tests/unit/plugins/module_utils/test_mysql.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import pytest
|
||||
|
||||
from ansible_collections.community.mysql.plugins.module_utils.mysql import get_server_version
|
||||
from ..utils import dummy_cursor_class
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'cursor_return_version,cursor_return_type',
|
||||
[
|
||||
('5.7.0-mysql', 'dict'),
|
||||
('8.0.0-mysql', 'list'),
|
||||
('10.5.0-mariadb', 'dict'),
|
||||
('10.5.1-mariadb', 'list'),
|
||||
]
|
||||
)
|
||||
def test_get_server_version(cursor_return_version, cursor_return_type):
|
||||
"""
|
||||
Test that server versions are handled properly by get_server_version() whether they're returned as a list or dict.
|
||||
"""
|
||||
cursor = dummy_cursor_class(cursor_return_version, cursor_return_type)
|
||||
assert get_server_version(cursor) == cursor_return_version
|
|
@ -7,22 +7,7 @@ __metaclass__ = type
|
|||
import pytest
|
||||
|
||||
from ansible_collections.community.mysql.plugins.modules.mysql_replication import uses_replica_terminology
|
||||
|
||||
|
||||
class dummy_cursor_class():
|
||||
def __init__(self, output, ret_val_type='dict'):
|
||||
self.output = output
|
||||
self.ret_val_type = ret_val_type
|
||||
|
||||
def execute(self, query):
|
||||
pass
|
||||
|
||||
def fetchone(self):
|
||||
if self.ret_val_type == 'dict':
|
||||
return {'version': self.output}
|
||||
|
||||
elif self.ret_val_type == 'list':
|
||||
return [self.output]
|
||||
from ..utils import dummy_cursor_class
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
33
tests/unit/plugins/modules/test_mysql_user.py
Normal file
33
tests/unit/plugins/modules/test_mysql_user.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import pytest
|
||||
|
||||
from ansible_collections.community.mysql.plugins.modules.mysql_user import supports_identified_by_password
|
||||
from ..utils import dummy_cursor_class
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'function_return,cursor_output,cursor_ret_type',
|
||||
[
|
||||
(True, '5.5.1-mysql', 'list'),
|
||||
(True, '5.7.0-mysql', 'dict'),
|
||||
(True, '10.5.0-mariadb', 'dict'),
|
||||
(True, '10.5.1-mariadb', 'dict'),
|
||||
(True, '10.6.0-mariadb', 'dict'),
|
||||
(True, '11.5.1-mariadb', 'dict'),
|
||||
(False, '8.0.22-mysql', 'list'),
|
||||
(False, '8.1.2-mysql', 'dict'),
|
||||
(False, '9.0.0-mysql', 'list'),
|
||||
(False, '8.0.0-mysql', 'list'),
|
||||
(False, '8.0.11-mysql', 'dict'),
|
||||
(False, '8.0.21-mysql', 'list'),
|
||||
]
|
||||
)
|
||||
def test_supports_identified_by_password(function_return, cursor_output, cursor_ret_type):
|
||||
"""
|
||||
Tests whether 'CREATE USER %s@%s IDENTIFIED BY PASSWORD %s' is supported, which is currently supported by everything
|
||||
besides MySQL >= 8.0.
|
||||
"""
|
||||
cursor = dummy_cursor_class(cursor_output, cursor_ret_type)
|
||||
assert supports_identified_by_password(cursor) == function_return
|
19
tests/unit/plugins/utils.py
Normal file
19
tests/unit/plugins/utils.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
class dummy_cursor_class():
|
||||
"""Dummy class for returning an answer for SELECT VERSION()."""
|
||||
def __init__(self, output, ret_val_type='dict'):
|
||||
self.output = output
|
||||
self.ret_val_type = ret_val_type
|
||||
|
||||
def execute(self, query):
|
||||
pass
|
||||
|
||||
def fetchone(self):
|
||||
if self.ret_val_type == 'dict':
|
||||
return {'version': self.output}
|
||||
|
||||
elif self.ret_val_type == 'list':
|
||||
return [self.output]
|
Loading…
Add table
Add a link
Reference in a new issue