This commit is contained in:
Luca Bilke 2025-01-18 19:17:59 +01:00
parent 762c02d0ed
commit 5181a38569
Signed by: luca
GPG key ID: C9E851809C1A5BDE
3 changed files with 1 additions and 137 deletions
requirements-dev.txttest.json
tests/units/plugins/module_utils

View file

@ -1,4 +0,0 @@
# vim: ft=requirements
ansible-core==2.17.*
pytest
PyYAML

View file

@ -56,16 +56,7 @@
"docker_volume_backupper": {
"environment": {
"BACKUP_CRON_EXPRESSION": "0 6 * * *",
"BACKUP_RETENTION_DAYS": "7",
"EXEC_FORWARD_OUTPUT": true,
"GPG_PASSPHRASE": "UYi9wgpWKgZBep",
"GZIP_PARALLELISM": "2",
"NOTIFICATION_URLS": "smtp://root%40snaile.de:RzBNcz@5iq5gGw@tripoli.snaile.de:465/?FromAddress=root@snaile.de&ToAddresses=luca@bil.ke&Encryption=ImplicitTLS",
"SSH_HOST_NAME": "u374707.your-storagebox.de",
"SSH_PASSWORD": "8WHePPymUsPUaXeS",
"SSH_PORT": "23",
"SSH_REMOTE_PATH": "/home/docker-backups",
"SSH_USER": "u374707-sub1"
"BACKUP_RETENTION_DAYS": "7"
},
"image": "offen/docker-volume-backup:v2.43.0"
},

View file

@ -1,123 +0,0 @@
# Copyright: (c) 2025, Luca Bilke <luca@bil.ke>
# MIT License (see LICENSE)
from typing import Any
from unittest import TestCase
import pytest
from ansible_collections.snailed.ez_compose.plugins.module_utils import common
@pytest.mark.parametrize(
("test_input", "expected"),
[ # pyright: ignore[reportUnknownArgumentType]
# Basic nested update (using existing test variables)
(
(
{"one": {"one": "keep", "two": "rewrite"}},
{"one": {"two": "new"}},
),
{"one": {"one": "keep", "two": "new"}},
),
# Deep nested update
(
(
{"a": {"b": {"c": "old", "d": "keep"}}},
{"a": {"b": {"c": "new"}}},
),
{"a": {"b": {"c": "new", "d": "keep"}}},
),
# Adding new keys at different levels
(
(
{"x": {"y": "original"}},
{"x": {"z": "new", "y": "updated"}, "new_key": "value"},
),
{"x": {"y": "updated", "z": "new"}, "new_key": "value"},
),
# Empty dict cases
(
(
{},
{"new": "data"},
),
{"new": "data"},
),
(
(
{"existing": "data"},
{},
),
{"existing": "data"},
),
# Lists within dictionaries
(
(
{"items": ["a", "b"], "nested": {"list": ["1", "2"]}},
{"items": ["c"], "nested": {"list": ["3"]}},
),
{"items": ["a", "b", "c"], "nested": {"list": ["1", "2", "3"]}},
),
# Lists of dictionaries
(
(
{
"configs": [
{"name": "config1", "value": "old"},
{"name": "config2", "enabled": True},
],
},
{
"configs": [
{"name": "config3", "value": "new"},
{"name": "config4", "enabled": False},
],
},
),
{
"configs": [
{"name": "config1", "value": "old"},
{"name": "config2", "enabled": True},
{"name": "config3", "value": "new"},
{"name": "config4", "enabled": False},
],
},
),
# Nested lists of dictionaries
(
(
{
"services": {
"web": [
{"port": 80, "protocol": "http"},
{"port": 443, "protocol": "https"},
],
},
},
{"services": {"web": [{"port": 8080, "protocol": "http"}]}},
),
{
"services": {
"web": [
{"port": 80, "protocol": "http"},
{"port": 443, "protocol": "https"},
{"port": 8080, "protocol": "http"},
],
},
},
),
# Mixed types update
(
(
{"mixed": {"num": 42, "list": [1, 2], "str": "old"}},
{"mixed": {"num": 43, "list": [3], "str": "new"}},
),
{"mixed": {"num": 43, "list": [1, 2, 3], "str": "new"}},
),
],
)
def test_recursive_update(
test_input: tuple[dict[str, Any], dict[str, Any]],
expected: dict[str, Any],
) -> None:
TestCase().assertDictEqual(common.recursive_update(*test_input), expected)