Exemplo n.º 1
0
def test_create_snmp_parse_function():
    compliant_parse_function = section_plugins_legacy._create_snmp_parse_function(
        original_parse_function=old_school_parse_function,
        recover_layout_function=lambda x: x,
        handle_empty_info=False,
    )

    with pytest.raises(ValueError):
        # raises b/c of wrong signature!
        section_plugins._validate_parse_function(
            old_school_parse_function,
            expected_annotation=(str, "str"),  # irrelevant in test
        )

    section_plugins._validate_parse_function(
        compliant_parse_function,
        expected_annotation=(
            str,
            "str"),  # irrel. in test, SNMP parse function is not annotated
    )

    arbitrary_non_empty_input = [[['moo']]]
    assert compliant_parse_function([[]]) is None
    assert compliant_parse_function(
        arbitrary_non_empty_input  # type: ignore[arg-type]
    ) == old_school_parse_function(arbitrary_non_empty_input)
Exemplo n.º 2
0
def test_create_snmp_parse_function_handle_empty():
    compliant_parse_function = section_plugins_legacy._create_snmp_parse_function(
        original_parse_function=old_school_parse_function,
        recover_layout_function=lambda x: x,
        handle_empty_info=True,
    )

    assert compliant_parse_function([[]]) == old_school_parse_function([[]])
def test_create_snmp_parse_function():
    compliant_parse_function = section_plugins_legacy._create_snmp_parse_function(
        old_school_parse_function, lambda x: x)

    with pytest.raises(ValueError):
        # raises b/c of wrong signature!
        section_plugins._validate_parse_function(
            old_school_parse_function,
            expected_annotation=(str, "str"),  # irrelevant in test
        )

    section_plugins._validate_parse_function(
        compliant_parse_function,
        expected_annotation=(str, "str"),  # irrel. in test, SNMP parse function is not annotated
    )

    assert old_school_parse_function([]) == compliant_parse_function([])
        host_labels=DiscoveredHostLabels(*HOST_LABELS[1:]),
    )
    yield "item3", "{'how_bad_is_this': 100}"


@pytest.mark.parametrize("name_in, name_out", [
    ("foo.bar", "foo"),
    ("foobar", "foobar"),
])
def test_get_section_name(name_in, name_out):
    assert name_out == section_plugins_legacy.get_section_name(name_in)


@pytest.mark.parametrize("creator_func", [
    section_plugins_legacy._create_agent_parse_function,
    lambda x: section_plugins_legacy._create_snmp_parse_function(
        x, lambda x: x),
])
def test_create_parse_function(creator_func):
    compliant_parse_function = creator_func(old_school_parse_function)

    with pytest.raises(ValueError):
        # raises b/c of wrong signature!
        section_plugins._validate_parse_function(old_school_parse_function)

    section_plugins._validate_parse_function(compliant_parse_function)

    assert old_school_parse_function([]) == compliant_parse_function([])


@pytest.mark.parametrize("disco_func, labels_expected", [
    (old_school_discover_function, HOST_LABELS),