def revise_namespaces( *, insights: references.Insights, namespaces: Collection[references.NamespacePattern], raw_events: Collection[bodies.RawEvent] = (), raw_bodies: Collection[bodies.RawBody] = (), ) -> None: all_events = list(raw_events) + [ bodies.RawEvent(type=None, object=obj) for obj in raw_bodies ] for raw_event in all_events: namespace = references.NamespaceName( raw_event['object']['metadata']['name']) matched = any( references.match_namespace(namespace, pattern) for pattern in namespaces) deleted = is_deleted(raw_event) if deleted: insights.namespaces.discard(namespace) elif matched: insights.namespaces.add(namespace)
def test_reinclusion_after_exclusion(name, pattern, expected): result = match_namespace(name=name, pattern=pattern) assert result == expected
def test_initial_exclusion_implies_catchall_inclusion(name, pattern, expected): result = match_namespace(name=name, pattern=pattern) assert result == expected
def test_spaces_are_ignored(name, pattern, expected): result = match_namespace(name=name, pattern=pattern) assert result == expected
def test_multiple_patterns(name, pattern, expected): result = match_namespace(name=name, pattern=pattern) assert result == expected
def test_exact_values(name, pattern, expected): result = match_namespace(name=name, pattern=pattern) assert result == expected
def test_regexps_with_full_matching(name, pattern, expected): result = match_namespace(name=name, pattern=pattern) assert result == expected