How to use the kopf.structs.diffs.diff function in kopf

To help you get started, we’ve selected a few kopf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zalando-incubator / kopf / tests / diffs-n-dicts / test_diff.py View on Github external
def test_strings_unequal():
    a = 'hello'
    b = 'world'
    d = diff(a, b)
    assert d == (('change', (), 'hello', 'world'),)
github zalando-incubator / kopf / tests / diffs-n-dicts / test_diff.py View on Github external
def test_dicts_with_keys_removed():
    a = {'hello': 'world', 'key': 'val'}
    b = {'hello': 'world'}
    d = diff(a, b)
    assert d == (('remove', ('key',), 'val', None),)
github zalando-incubator / kopf / tests / diffs-n-dicts / test_diff.py View on Github external
def test_lists_equal():
    a = [100, 200, 300]
    b = [100, 200, 300]
    d = diff(a, b)
    assert d == ()
github zalando-incubator / kopf / tests / diffs-n-dicts / test_diff.py View on Github external
def test_strings_equal():
    a = 'hello'
    b = 'hello'
    d = diff(a, b)
    assert d == ()
github zalando-incubator / kopf / tests / diffs-n-dicts / test_diff.py View on Github external
def test_dicts_adding_label():
    body_before_labelling = {'metadata': {}}
    body_after_labelling  = {'metadata': {'labels': 'LABEL'}}

    d = diff(body_before_labelling, body_after_labelling)
    assert d == (('add', ('metadata', 'labels'), None, 'LABEL'),)
github zalando-incubator / kopf / tests / diffs-n-dicts / test_diff.py View on Github external
def test_dicts_with_keys_changed():
    a = {'hello': 'world', 'key': 'old'}
    b = {'hello': 'world', 'key': 'new'}
    d = diff(a, b)
    assert d == (('change', ('key',), 'old', 'new'),)
github zalando-incubator / kopf / tests / diffs-n-dicts / test_diff.py View on Github external
def test_dicts_updating_storage_size():
    body_before_storage_size_update = {'spec': {'size': '42G'}}
    body_after_storage_size_update  = {'spec': {'size': '76G'}}

    d = diff(body_before_storage_size_update, body_after_storage_size_update)
    assert d == (('change', ('spec', 'size'), '42G', '76G'),)
github zalando-incubator / kopf / tests / diffs-n-dicts / test_diff.py View on Github external
def test_dicts_equal():
    a = {'hello': 'world', 'key': 'val'}
    b = {'key': 'val', 'hello': 'world'}
    d = diff(a, b)
    assert d == ()
github zalando-incubator / kopf / tests / diffs-n-dicts / test_diff.py View on Github external
def test_dicts_different_items_handled():
    body_before_storage_size_update = {'spec': {'items': ['task1', 'task2']}}
    body_after_storage_size_update  = {'spec': {'items': ['task3', 'task4']}}

    d = diff(body_before_storage_size_update, body_after_storage_size_update)
    assert d == (('change', ('spec', 'items'), ['task1', 'task2'], ['task3', 'task4']),)
github zalando-incubator / kopf / kopf / structs / lastseen.py View on Github external
def get_essential_diffs(
        body: bodies.Body,
        extra_fields: Optional[Iterable[dicts.FieldSpec]] = None,
) -> Tuple[Optional[bodies.BodyEssence], Optional[bodies.BodyEssence], diffs.Diff]:
    old: Optional[bodies.BodyEssence] = retrieve_essence(body)
    new: Optional[bodies.BodyEssence] = get_essence(body, extra_fields=extra_fields)
    return old, new, diffs.diff(old, new)