def test_collect_metadata(version, metadata, datadog_agent): client = MagicMock() client.get_transport = MagicMock( return_value=namedtuple('Transport', ['remote_version'])(version)) ssh = CheckSSH('ssh_check', {}, {}, list(common.INSTANCES.values())) ssh.check_id = 'test:123' ssh._collect_metadata(client) datadog_agent.assert_metadata('test:123', metadata)
def test_collect_bad_metadata(datadog_agent): client = MagicMock() client.get_transport = MagicMock(return_value=namedtuple( 'Transport', ['remote_version'])('Cannot parse this')) ssh = CheckSSH('ssh_check', {}, {}, list(common.INSTANCES.values())) ssh.check_id = 'test:123' ssh._collect_metadata(client) datadog_agent.assert_metadata_count(1) datadog_agent.assert_metadata('test:123', {'flavor': 'unknown'})
def test_metadata(aggregator, instance, datadog_agent): check = CheckSSH('ssh_check', {}, [instance]) check.check_id = 'test:123' check.check(instance) _, _, flavor, raw_version = re.split(r'[-_]', common.SSH_SERVER_VERSION) major, minor = raw_version.split(".") version_metadata = { 'version.scheme': 'ssh_check', 'version.major': major, 'version.minor': minor, 'version.raw': common.SSH_SERVER_VERSION, 'flavor': flavor, } datadog_agent.assert_metadata('test:123', version_metadata) common.wait_for_threads( ) # needed, otherwise the next won't count correctly threads