Example #1
0
def test_get_enricher_missing_config_raises(mocker, caplog, enricher_config,
                                            auth_client, config_key, exc_msg,
                                            metrics):
    """Raise when configuration key is missing."""
    mocker.patch('gordon_gcp.plugins.service.enricher.http.AIOConnection')
    enricher_config.pop(config_key)

    with pytest.raises(exceptions.GCPConfigError) as e:
        service.get_enricher(enricher_config, metrics)

    e.match('Invalid configuration:\n' + exc_msg)
    assert 1 == len(caplog.records)
Example #2
0
def test_get_enricher_config_bad_dns_zone(mocker, caplog, enricher_config,
                                          auth_client, metrics):
    """Raise when 'dns_zone' config value doesn't end with root zone."""
    mocker.patch('gordon_gcp.plugins.service.enricher.http.AIOConnection')
    enricher_config['dns_zone'] = 'example.com'

    with pytest.raises(exceptions.GCPConfigError) as e:
        service.get_enricher(enricher_config, metrics)

    exc_msg = 'A dns zone must be an FQDN and end with the root zone \("."\).'
    e.match('Invalid configuration:\n' + exc_msg)
    assert 1 == len(caplog.records)
Example #3
0
def test_get_enricher(mocker, enricher_config, auth_client, conf_retries,
                      retries, metrics):
    """Happy path to initialize an Enricher client."""
    mocker.patch('gordon_gcp.plugins.service.enricher.http.AIOConnection')
    enricher_config['retries'] = conf_retries

    client = service.get_enricher(enricher_config, metrics)

    assert isinstance(client, service.enricher.GCEEnricher)
    assert client.config
    assert retries == client.config['retries']
    assert client._http_client