mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-04-12 21:50:32 -07:00
Add unit tests
This commit is contained in:
parent
34bfeedeb4
commit
3d2661b927
3 changed files with 87 additions and 0 deletions
.github/workflows
tests/unit/plugins/modules
41
.github/workflows/ansible-test-plugins.yml
vendored
41
.github/workflows/ansible-test-plugins.yml
vendored
|
@ -101,3 +101,44 @@ jobs:
|
||||||
- uses: codecov/codecov-action@v1
|
- uses: codecov/codecov-action@v1
|
||||||
with:
|
with:
|
||||||
fail_ci_if_error: false
|
fail_ci_if_error: false
|
||||||
|
|
||||||
|
units:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
name: Units (Ⓐ${{ matrix.ansible }})
|
||||||
|
strategy:
|
||||||
|
# As soon as the first unit test fails,
|
||||||
|
# cancel the others to free up the CI queue
|
||||||
|
fail-fast: true
|
||||||
|
matrix:
|
||||||
|
ansible:
|
||||||
|
- stable-2.10
|
||||||
|
- devel
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Check out code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
path: ./ansible_collections/community/mysql
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: 3.8
|
||||||
|
|
||||||
|
- name: Install ansible-base (${{matrix.ansible}})
|
||||||
|
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check
|
||||||
|
|
||||||
|
# Run the unit tests
|
||||||
|
- name: Run unit test
|
||||||
|
run: ansible-test units -v --color --docker --coverage
|
||||||
|
working-directory: ./ansible_collections/community/mysql
|
||||||
|
|
||||||
|
# ansible-test support producing code coverage date
|
||||||
|
- name: Generate coverage report
|
||||||
|
run: ansible-test coverage xml -v --requirements --group-by command --group-by version
|
||||||
|
working-directory: ./ansible_collections/community/mysql
|
||||||
|
|
||||||
|
# See the reports at https://codecov.io/gh/GITHUBORG/REPONAME
|
||||||
|
- uses: codecov/codecov-action@v1
|
||||||
|
with:
|
||||||
|
fail_ci_if_error: false
|
||||||
|
|
0
tests/unit/plugins/modules/__init__.py
Normal file
0
tests/unit/plugins/modules/__init__.py
Normal file
46
tests/unit/plugins/modules/test_mysql_replication.py
Normal file
46
tests/unit/plugins/modules/test_mysql_replication.py
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright: (c) 2020, Andrew Klychkov (@Andersson007) <aaklychkov@mail.ru>
|
||||||
|
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__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]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
'f_output,c_output,c_ret_type',
|
||||||
|
[
|
||||||
|
(False, '5.5.1-mysql', 'list'),
|
||||||
|
(False, '5.7.0-mysql', 'dict'),
|
||||||
|
(False, '8.0.0-mysql', 'list'),
|
||||||
|
(False, '8.0.11-mysql', 'dict'),
|
||||||
|
(False, '8.0.21-mysql', 'list'),
|
||||||
|
(False, '10.5.0-mariadb', 'dict'),
|
||||||
|
(True, '8.0.22-mysql', 'list'),
|
||||||
|
(True, '8.1.2-mysql', 'dict'),
|
||||||
|
(True, '9.0.0-mysql', 'list'),
|
||||||
|
(True, '10.5.1-mariadb', 'dict'),
|
||||||
|
(True, '10.6.0-mariadb', 'dict'),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
def test_uses_replica_terminology(f_output, c_output, c_ret_type):
|
||||||
|
cursor = dummy_cursor_class(c_output, c_ret_type)
|
||||||
|
assert uses_replica_terminology(cursor) == f_output
|
Loading…
Add table
Reference in a new issue