Ejemplo n.º 1
0
def test_matching_returns_things_once_if_multimatch(node_scenario):
    a, b = dummy_object(), dummy_object()
    a.attr = "a - this should match"
    b.attr = "b - this won't"
    node_scenario.schema = {
        "match": [
            {
                "property": {
                    "name": "attr",
                    "value": "a.*"
                }
            },
            {
                "property": {
                    "name": "attr",
                    "value": ".*"
                }
            },
        ]
    }
    node_scenario.inventory.find_nodes = MagicMock(return_value=[a, b])
    matched = node_scenario.match()
    assert len(matched) == 2
    assert a in matched
    assert b in matched
Ejemplo n.º 2
0
def test_add_matched_to_empty_set_metric(node_scenario, pod_scenario):
    node_scenario.schema = {"match": [{"namespace": {"name": "non-existent"}}]}

    with mock.patch('powerfulseal.metriccollectors.StdoutCollector.add_matched_to_empty_set_metric') \
            as metric_function:
        metric_function.assert_not_called()
        node_scenario.match()
        metric_function.assert_called_once_with(NODE_SOURCE)

    pod_scenario.schema = {"match": [{"namespace": {"name": "non-existent"}}]}

    with mock.patch('powerfulseal.metriccollectors.StdoutCollector.add_matched_to_empty_set_metric') \
            as metric_function:
        metric_function.assert_not_called()
        pod_scenario.match()
        metric_function.assert_called_once_with(POD_SOURCE)
Ejemplo n.º 3
0
def test_matching_matches(node_scenario):
    a, b = dummy_object(), dummy_object()
    a.attr = "a - this should match"
    b.attr = "b - this won't"
    node_scenario.schema = {
        "match": [
            {
                "property": {
                    "name": "attr",
                    "value": "a.*"
                }
            },
        ]
    }
    node_scenario.inventory.find_nodes = MagicMock(return_value=[a, b])
    matched = node_scenario.match()
    assert matched == [a]