Skip to content

Commit

Permalink
move the tests one folder up
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorentClarret committed Mar 13, 2023
1 parent 7041e94 commit df1c637
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
3 changes: 0 additions & 3 deletions kafka_consumer/tests/python_client/__init__.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
import pytest

from ..common import assert_check_kafka
from tests.common import assert_check_kafka

pytestmark = [pytest.mark.e2e]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
import logging
from contextlib import nullcontext as does_not_raise

import pytest
from contextlib import nullcontext as does_not_raise
from tests.common import KAFKA_CONNECT_STR, assert_check_kafka, metrics

from datadog_checks.dev.utils import get_metadata_metrics

from ..common import KAFKA_CONNECT_STR, assert_check_kafka, metrics

pytestmark = [pytest.mark.integration, pytest.mark.usefixtures('dd_environment')]


Expand Down Expand Up @@ -68,7 +67,9 @@ def test_no_partitions(aggregator, check, kafka_instance, dd_run_check):
pytest.param(False, 2, ['topic:marvel'], id="Disabled"),
],
)
def test_monitor_broker_highwatermarks(dd_run_check, check, aggregator, kafka_instance, is_enabled, metric_count, topic_tags):
def test_monitor_broker_highwatermarks(
dd_run_check, check, aggregator, kafka_instance, is_enabled, metric_count, topic_tags
):
kafka_instance['consumer_groups'] = {'my_consumer': {'marvel': None}}
kafka_instance['monitor_all_broker_highwatermarks'] = is_enabled
dd_run_check(check(kafka_instance))
Expand Down Expand Up @@ -96,7 +97,7 @@ def test_monitor_broker_highwatermarks(dd_run_check, check, aggregator, kafka_in
id="Invalid Non-string kafka_connect_str",
),
pytest.param(
{'kafka_connect_str': KAFKA_CONNECT_STR, 'consumer_groups': {}},
{'consumer_groups': {}},
does_not_raise(),
'ConfigurationError: Cannot fetch consumer offsets because no consumer_groups are specified and '
'monitor_unlisted_consumer_groups is False',
Expand All @@ -111,50 +112,52 @@ def test_monitor_broker_highwatermarks(dd_run_check, check, aggregator, kafka_in
id="Invalid Nonetype kafka_connect_str",
),
pytest.param(
{'kafka_connect_str': [KAFKA_CONNECT_STR, '127.0.0.1:9093'], 'monitor_unlisted_consumer_groups': True},
{'kafka_connect_str': ['localhost:9092', 'localhost:9093'], 'monitor_unlisted_consumer_groups': True},
does_not_raise(),
'',
4,
id="Valid list kafka_connect_str",
),
pytest.param(
{'kafka_connect_str': KAFKA_CONNECT_STR, 'monitor_unlisted_consumer_groups': True},
{'monitor_unlisted_consumer_groups': True},
does_not_raise(),
'',
4,
id="Valid str kafka_connect_str",
),
pytest.param(
{'kafka_connect_str': KAFKA_CONNECT_STR, 'consumer_groups': {}, 'monitor_unlisted_consumer_groups': True},
{'consumer_groups': {}, 'monitor_unlisted_consumer_groups': True},
does_not_raise(),
'',
4,
id="Empty consumer_groups and monitor_unlisted_consumer_groups true",
),
pytest.param(
{'kafka_connect_str': KAFKA_CONNECT_STR, 'consumer_groups': {'my_consumer': None}},
{'consumer_groups': {'my_consumer': None}},
does_not_raise(),
'',
4,
id="One consumer group, all topics and partitions",
),
pytest.param(
{'kafka_connect_str': KAFKA_CONNECT_STR, 'consumer_groups': {'my_consumer': {'marvel': None}}},
{'consumer_groups': {'my_consumer': {'marvel': None}}},
does_not_raise(),
'',
2,
id="One consumer group, one topic, all partitions",
),
pytest.param(
{'kafka_connect_str': KAFKA_CONNECT_STR, 'consumer_groups': {'my_consumer': {'marvel': [1]}}},
{'consumer_groups': {'my_consumer': {'marvel': [1]}}},
does_not_raise(),
'',
1,
id="One consumer group, one topic, one partition",
),
],
)
def test_config(dd_run_check, check, kafka_instance, override, aggregator, expected_exception, exception_msg, metric_count, caplog):
def test_config(
dd_run_check, check, kafka_instance, override, aggregator, expected_exception, exception_msg, metric_count, caplog
):
caplog.set_level(logging.DEBUG)
kafka_instance.update(override)
with expected_exception:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
# (C) Datadog, Inc. 2023-present
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
import copy
import logging

import mock
import pytest
from tests.common import KAFKA_CONNECT_STR, LEGACY_CLIENT, metrics

from datadog_checks.base import ConfigurationError
from datadog_checks.dev.utils import get_metadata_metrics
from datadog_checks.kafka_consumer import KafkaCheck
from datadog_checks.kafka_consumer.client.kafka_python_client import OAuthTokenProvider

from ..common import KAFKA_CONNECT_STR, LEGACY_CLIENT, metrics

pytestmark = [pytest.mark.unit]


Expand Down Expand Up @@ -73,13 +71,15 @@ def test_tls_config_ok(check, kafka_instance_tls):
)
@pytest.mark.skipif(not LEGACY_CLIENT, reason='not implemented yet with confluent-kafka')
def test_oauth_config(sasl_oauth_token_provider, check, expected_exception, kafka_instance):
kafka_instance.update({
'kafka_connect_str': KAFKA_CONNECT_STR,
'monitor_unlisted_consumer_groups': True,
'security_protocol': 'SASL_PLAINTEXT',
'sasl_mechanism': 'OAUTHBEARER',
'use_legacy_client': LEGACY_CLIENT,
})
kafka_instance.update(
{
'kafka_connect_str': KAFKA_CONNECT_STR,
'monitor_unlisted_consumer_groups': True,
'security_protocol': 'SASL_PLAINTEXT',
'sasl_mechanism': 'OAUTHBEARER',
'use_legacy_client': LEGACY_CLIENT,
}
)
kafka_instance.update(sasl_oauth_token_provider)

with expected_exception:
Expand Down

0 comments on commit df1c637

Please sign in to comment.