Exemplo n.º 1
0
def test_swapusage_nomatch(stub_swap_usage):
    with patch("psutil.swap_memory", MagicMock(return_value=stub_swap_usage)):

        config = [{"percent": "10%"}]

        ret = swapusage.validate(config)
        assert ret == (True, "Valid beacon configuration")

        ret = swapusage.beacon(config)
        assert ret != [{"swapusage": 9.7}]
Exemplo n.º 2
0
def test_swapusage_match(stub_swap_usage):
    with patch("psutil.swap_memory", MagicMock(return_value=stub_swap_usage)):

        config = [{"percent": "9%"}, {"interval": 30}]

        ret = swapusage.validate(config)
        assert ret == (True, "Valid beacon configuration")

        ret = swapusage.beacon(config)
        assert ret == [{"swapusage": 9.7}]

        # Test without the percent
        config = [{"percent": 9}, {"interval": 30}]

        ret = swapusage.validate(config)
        assert ret == (True, "Valid beacon configuration")

        ret = swapusage.beacon(config)
        assert ret == [{"swapusage": 9.7}]
Exemplo n.º 3
0
def test_empty_config():
    config = [{}]

    ret = swapusage.validate(config)
    assert ret == (False,
                   "Configuration for swapusage beacon requires percent.")
Exemplo n.º 4
0
def test_non_list_config():
    config = {}

    ret = swapusage.validate(config)
    assert ret == (False, "Configuration for swapusage beacon must be a list.")