mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
832dd55144
* sanity: Add future boilerplate Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com> * Module Utils Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com> * Scripts Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com> * sanity: Add future boilerplate * Tests Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com> * CI failure Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
56 lines
2.2 KiB
Python
56 lines
2.2 KiB
Python
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
__metaclass__ = type
|
|
|
|
import json
|
|
import pytest
|
|
|
|
from ansible_collections.community.general.plugins.module_utils import kubevirt as mymodule
|
|
|
|
|
|
def test_simple_merge_dicts():
|
|
dict1 = {'labels': {'label1': 'value'}}
|
|
dict2 = {'labels': {'label2': 'value'}}
|
|
dict3 = json.dumps({'labels': {'label1': 'value', 'label2': 'value'}}, sort_keys=True)
|
|
assert dict3 == json.dumps(dict(mymodule.KubeVirtRawModule.merge_dicts(dict1, dict2)), sort_keys=True)
|
|
|
|
|
|
def test_simple_multi_merge_dicts():
|
|
dict1 = {'labels': {'label1': 'value', 'label3': 'value'}}
|
|
dict2 = {'labels': {'label2': 'value'}}
|
|
dict3 = json.dumps({'labels': {'label1': 'value', 'label2': 'value', 'label3': 'value'}}, sort_keys=True)
|
|
assert dict3 == json.dumps(dict(mymodule.KubeVirtRawModule.merge_dicts(dict1, dict2)), sort_keys=True)
|
|
|
|
|
|
def test_double_nested_merge_dicts():
|
|
dict1 = {'metadata': {'labels': {'label1': 'value', 'label3': 'value'}}}
|
|
dict2 = {'metadata': {'labels': {'label2': 'value'}}}
|
|
dict3 = json.dumps({'metadata': {'labels': {'label1': 'value', 'label2': 'value', 'label3': 'value'}}}, sort_keys=True)
|
|
assert dict3 == json.dumps(dict(mymodule.KubeVirtRawModule.merge_dicts(dict1, dict2)), sort_keys=True)
|
|
|
|
|
|
@pytest.mark.parametrize("lval, operations, rval, result", [
|
|
('v1', ['<', '<='], 'v2', True),
|
|
('v1', ['>', '>=', '=='], 'v2', False),
|
|
('v1', ['>'], 'v1alpha1', True),
|
|
('v1', ['==', '<', '<='], 'v1alpha1', False),
|
|
('v1beta5', ['==', '<=', '>='], 'v1beta5', True),
|
|
('v1beta5', ['<', '>', '!='], 'v1beta5', False),
|
|
|
|
])
|
|
def test_kubeapiversion_comparisons(lval, operations, rval, result):
|
|
KubeAPIVersion = mymodule.KubeAPIVersion
|
|
for op in operations:
|
|
test = '(KubeAPIVersion("{0}") {1} KubeAPIVersion("{2}")) == {3}'.format(lval, op, rval, result)
|
|
assert eval(test)
|
|
|
|
|
|
@pytest.mark.parametrize("ver", ('nope', 'v1delta7', '1.5', 'v1beta', 'v'))
|
|
def test_kubeapiversion_unsupported_versions(ver):
|
|
threw = False
|
|
try:
|
|
mymodule.KubeAPIVersion(ver)
|
|
except ValueError:
|
|
threw = True
|
|
assert threw
|