mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-08-04 05:04:23 -07:00
fix more tests
This commit is contained in:
parent
1a7b06b14d
commit
7c376590e7
2 changed files with 8 additions and 20 deletions
|
@ -41,10 +41,10 @@ def test_uses_replica_terminology(f_output, c_output, c_ret_type):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
'user,password,expected_query',
|
'user,password,expected_query',
|
||||||
[
|
[
|
||||||
(None, None, "START GROUP_REPLICATION"),
|
(None, None, "START GROUP_REPLICATION "),
|
||||||
("repl_user", None, "START GROUP_REPLICATION USER='repl_user'"),
|
("repl_user", None, "START GROUP_REPLICATION USER='repl_user'"),
|
||||||
(None, "repl_pass", "START GROUP_REPLICATION"),
|
(None, "repl_pass", "START GROUP_REPLICATION PASSWORD='repl_pass'"),
|
||||||
("repl_user", "repl_pass", "START GROUP_REPLICATION USER='repl_user' PASSWORD='repl_pass'"),
|
("repl_user", "repl_pass", "START GROUP_REPLICATION USER='repl_user', PASSWORD='repl_pass'"),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
def test_start_group_replication(user, password, expected_query):
|
def test_start_group_replication(user, password, expected_query):
|
||||||
|
@ -66,7 +66,6 @@ def test_start_group_replication(user, password, expected_query):
|
||||||
|
|
||||||
assert result is True
|
assert result is True
|
||||||
assert cursor.executed_queries[0] == expected_query
|
assert cursor.executed_queries[0] == expected_query
|
||||||
assert cursor.executed_queries[1] == "SHOW STATUS LIKE 'group_replication_status';"
|
|
||||||
|
|
||||||
|
|
||||||
def test_stop_group_replication():
|
def test_stop_group_replication():
|
||||||
|
@ -82,7 +81,6 @@ def test_stop_group_replication():
|
||||||
|
|
||||||
assert result is True
|
assert result is True
|
||||||
assert cursor.executed_queries[0] == "STOP GROUP_REPLICATION"
|
assert cursor.executed_queries[0] == "STOP GROUP_REPLICATION"
|
||||||
assert cursor.executed_queries[1] == "SHOW STATUS LIKE 'group_replication_status';"
|
|
||||||
|
|
||||||
|
|
||||||
def test_start_group_replication_fail():
|
def test_start_group_replication_fail():
|
||||||
|
|
|
@ -45,10 +45,10 @@ def test_uses_replica_terminology(f_output, c_output, c_ret_type):
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
'user,password,expected_query',
|
'user,password,expected_query',
|
||||||
[
|
[
|
||||||
(None, None, "START GROUP_REPLICATION"),
|
(None, None, "START GROUP_REPLICATION "),
|
||||||
("repl_user", None, "START GROUP_REPLICATION USER='repl_user'"),
|
("repl_user", None, "START GROUP_REPLICATION USER='repl_user'"),
|
||||||
(None, "repl_pass", "START GROUP_REPLICATION"),
|
(None, "repl_pass", "START GROUP_REPLICATION PASSWORD='repl_pass'"),
|
||||||
("repl_user", "repl_pass", "START GROUP_REPLICATION USER='repl_user' PASSWORD='repl_pass'"),
|
("repl_user", "repl_pass", "START GROUP_REPLICATION USER='repl_user', PASSWORD='repl_pass'"),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
def test_start_group_replication(user, password, expected_query):
|
def test_start_group_replication(user, password, expected_query):
|
||||||
|
@ -62,15 +62,14 @@ def test_start_group_replication(user, password, expected_query):
|
||||||
|
|
||||||
chm = []
|
chm = []
|
||||||
if user:
|
if user:
|
||||||
chm.append(" USER='%s'" % user)
|
chm.append("USER='%s'" % user)
|
||||||
if password:
|
if password:
|
||||||
chm.append(" PASSWORD='%s'" % password)
|
chm.append("PASSWORD='%s'" % password)
|
||||||
|
|
||||||
result = startgroupreplication(module, cursor, chm, False)
|
result = startgroupreplication(module, cursor, chm, False)
|
||||||
|
|
||||||
assert result is True
|
assert result is True
|
||||||
assert cursor.executed_queries[0] == expected_query
|
assert cursor.executed_queries[0] == expected_query
|
||||||
assert cursor.executed_queries[1] == "SHOW STATUS LIKE 'group_replication_status';"
|
|
||||||
|
|
||||||
|
|
||||||
def test_stop_group_replication():
|
def test_stop_group_replication():
|
||||||
|
@ -86,22 +85,17 @@ def test_stop_group_replication():
|
||||||
|
|
||||||
assert result is True
|
assert result is True
|
||||||
assert cursor.executed_queries[0] == "STOP GROUP_REPLICATION"
|
assert cursor.executed_queries[0] == "STOP GROUP_REPLICATION"
|
||||||
assert cursor.executed_queries[1] == "SHOW STATUS LIKE 'group_replication_status';"
|
|
||||||
|
|
||||||
|
|
||||||
def test_start_group_replication_fail():
|
def test_start_group_replication_fail():
|
||||||
"""Test startgroupreplication function with failure."""
|
"""Test startgroupreplication function with failure."""
|
||||||
from ansible_collections.community.mysql.plugins.modules.mysql_replication import startgroupreplication
|
from ansible_collections.community.mysql.plugins.modules.mysql_replication import startgroupreplication
|
||||||
import pymysql
|
|
||||||
|
|
||||||
cursor = MockCursor(status="ERROR")
|
cursor = MockCursor(status="ERROR")
|
||||||
module = type('obj', (object,), {
|
module = type('obj', (object,), {
|
||||||
'fail_json': lambda msg: None,
|
'fail_json': lambda msg: None,
|
||||||
})
|
})
|
||||||
|
|
||||||
# Mock the Warning exception
|
|
||||||
pymysql.Warning = Exception
|
|
||||||
|
|
||||||
result = startgroupreplication(module, cursor, [], True)
|
result = startgroupreplication(module, cursor, [], True)
|
||||||
|
|
||||||
assert result is False
|
assert result is False
|
||||||
|
@ -110,16 +104,12 @@ def test_start_group_replication_fail():
|
||||||
def test_stop_group_replication_fail():
|
def test_stop_group_replication_fail():
|
||||||
"""Test stopgroupreplication function with failure."""
|
"""Test stopgroupreplication function with failure."""
|
||||||
from ansible_collections.community.mysql.plugins.modules.mysql_replication import stopgroupreplication
|
from ansible_collections.community.mysql.plugins.modules.mysql_replication import stopgroupreplication
|
||||||
import pymysql
|
|
||||||
|
|
||||||
cursor = MockCursor(status="ERROR")
|
cursor = MockCursor(status="ERROR")
|
||||||
module = type('obj', (object,), {
|
module = type('obj', (object,), {
|
||||||
'fail_json': lambda msg: None,
|
'fail_json': lambda msg: None,
|
||||||
})
|
})
|
||||||
|
|
||||||
# Mock the Warning exception
|
|
||||||
pymysql.Warning = Exception
|
|
||||||
|
|
||||||
result = stopgroupreplication(module, cursor, True)
|
result = stopgroupreplication(module, cursor, True)
|
||||||
|
|
||||||
assert result is False
|
assert result is False
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue