Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added units tests #38

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions tests/unit/plugins/modules/test_clickhouse_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
from __future__ import (absolute_import, division, print_function)

__metaclass__ = type

import pytest
from uuid import UUID
from decimal import Decimal
from ipaddress import IPv4Address, IPv6Address


from ansible_collections.community.clickhouse.plugins.modules.clickhouse_client import (
is_uuid,
vals_to_supported,
replace_val_in_tuple,
)


@pytest.mark.parametrize(
'input_params,result',
[
('e66c72d8-fbd2-c174-0df3-7cbfd0c3d635', True),
('qwerty123', False),
('meaningless text', False),
('d1659f3e-83fe-3845-f1be-5fada6046b67', True),
]
)
def test_is_uuid(input_params, result):
# Testing the function is_uuid
assert is_uuid(input_params) == result


@pytest.mark.parametrize(
'input_params,result',
[
(((1, 2, 3, 4), 3, 5),
(1, 2, 3, 5)
),
(((1, 2, 3, 4), 2, 5),
(1, 2, 5, 4)
),
(((1, 2, 3, 4), 1, 5),
(1, 5, 3, 4)
),
(((1, 2), 0, 5),
(5, 2)
),
]
)
def test_replace_val_in_tuple(input_params, result):
# Testing the function replace_val_in_tuple
assert replace_val_in_tuple(*input_params) == result


@pytest.mark.parametrize(
'input_params,result',
[
([
('default', UUID('e66c72d8-fbd2-c174-0df3-7cbfd0c3d635')),
('test', UUID('4bfbe653-9137-0ea6-b97d-dc391ec9a919')),
], [
('default', 'e66c72d8-fbd2-c174-0df3-7cbfd0c3d635'),
('test', '4bfbe653-9137-0ea6-b97d-dc391ec9a919'),
],),
([
('localhost', IPv4Address('127.0.0.1')),
('non_routable', IPv4Address('0.0.0.0')),
], [
('localhost', '127.0.0.1'),
('non_routable', '0.0.0.0'),
],),
([
('localhost', IPv6Address('::1')),
('non_routable', IPv6Address('::')),
], [
('localhost', '::1'),
('non_routable', '::'),
],),
([
('pi', Decimal('3.14159')),
('e', Decimal('2.71828')),
], [
('pi', 3.14159),
('e', 2.71828),
],),
]
)
def test_vals_to_supported(input_params, result):
# Testing the function vals_to_supported
assert vals_to_supported(input_params) == result
Loading