def test_check_ok(aggregator, spin_up_squid, instance): squid_check = SquidCheck(common.CHECK_NAME, {}, {}) squid_check.check(instance) expected_tags = ["name:ok_instance", "custom_tag"] aggregator.assert_service_check(common.SERVICE_CHECK, tags=expected_tags, status=squid_check.OK) for metric in common.EXPECTED_METRICS: aggregator.assert_metric("squid.cachemgr." + metric, tags=expected_tags)
def test_parse_counter(aggregator): squid_check = SquidCheck(common.CHECK_NAME, {}, {}) # Good format line = "counter = 0\n" counter, value = squid_check.parse_counter(line) assert counter == "counter" assert value == "0" # Bad format line = "counter: value\n" counter, value = squid_check.parse_counter(line) assert counter is None assert value is None
def test_legacy_username_password(instance, auth_config): instance = deepcopy(instance) instance.update(auth_config) check = SquidCheck(common.CHECK_NAME, {}, {}, [instance]) with mock.patch('datadog_checks.base.utils.http.requests.get') as g: check.get_counters('host', 'port', []) g.assert_called_with( 'http://host:port/squid-internal-mgr/counters', auth=('datadog_user', 'datadog_pass'), cert=mock.ANY, headers=mock.ANY, proxies=mock.ANY, timeout=mock.ANY, verify=mock.ANY, )
def test_parse_instance(aggregator): squid_check = SquidCheck(common.CHECK_NAME, {}, {}) # instance with defaults instance = {"name": "ok_instance"} name, host, port, cachemgr_user, \ cachemgr_passwd, custom_tags = squid_check.parse_instance(instance) assert name == "ok_instance" assert host == "localhost" assert port == 3128 assert cachemgr_user == "" assert cachemgr_passwd == "" assert custom_tags == [] # instance with no defaults instance = { "name": "ok_instance", "host": "host", "port": 1234, "cachemgr_username": "******", "cachemgr_password": "******", "tags": ["foo:bar"], } name, host, port, cachemgr_user,\ cachemgr_passwd, custom_tags = squid_check.parse_instance(instance) assert name == "ok_instance" assert host == "host" assert port == 1234 assert cachemgr_user == "datadog" assert cachemgr_passwd == "pass" assert custom_tags == ["foo:bar"] # instance with no name instance = {"host": "host"} with pytest.raises(Exception): squid_check.parse_instance(instance)
def test_check_fail(aggregator, spin_up_squid, instance): squid_check = SquidCheck(common.CHECK_NAME, {}, {}) instance["host"] = "bad_host" with pytest.raises(Exception): squid_check.check(instance)
def check(): return SquidCheck(common.CHECK_NAME, {}, {})