Skip to content

Commit

Permalink
Create explicit topics to test kafka fixture reset
Browse files Browse the repository at this point in the history
  • Loading branch information
TheByronHimes committed Sep 29, 2023
1 parent 8a4c959 commit 69e73fc
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions tests/integration/test_akafka_testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import pytest
from kafka import KafkaAdminClient
from kafka.admin.new_topic import NewTopic

from hexkit.providers.akafka import KafkaConfig, KafkaEventPublisher
from hexkit.providers.akafka.testutils import (
Expand All @@ -35,18 +36,23 @@ def test_delete_topics_specific(kafka_fixture: KafkaFixture): # noqa: F811
admin_client = KafkaAdminClient(
bootstrap_servers=kafka_fixture.config.kafka_servers
)
new_topics = [
NewTopic(name="test", num_partitions=1, replication_factor=1),
NewTopic(name="test2", num_partitions=1, replication_factor=1),
]
admin_client.create_topics(new_topics)

# get the topics created by default (confluent.support.metrics)
initial_topics = admin_client.list_topics()
initial_length = len(initial_topics)

assert initial_length > 0
assert "test" in initial_topics

# delete that topic
kafka_fixture.delete_topics(initial_topics)
kafka_fixture.delete_topics("test")

# make sure it got deleted
assert len(admin_client.list_topics()) + 1 == initial_length
final_topics = admin_client.list_topics()
assert "test" not in final_topics
assert "test2" in final_topics


def test_delete_topics_all(kafka_fixture: KafkaFixture): # noqa: F811
Expand All @@ -55,12 +61,21 @@ def test_delete_topics_all(kafka_fixture: KafkaFixture): # noqa: F811
bootstrap_servers=kafka_fixture.config.kafka_servers
)

assert len(admin_client.list_topics()) > 0
new_topics = [
NewTopic(name="test", num_partitions=1, replication_factor=1),
NewTopic(name="test2", num_partitions=1, replication_factor=1),
]
admin_client.create_topics(new_topics)
initial_topics = admin_client.list_topics()
assert "test" in initial_topics
assert "test2" in initial_topics

# delete all topics by not specifying any
kafka_fixture.delete_topics()

assert len(admin_client.list_topics()) == 0
final_topics = admin_client.list_topics()
assert "test" not in final_topics
assert "test2" not in final_topics


@pytest.mark.asyncio
Expand Down

0 comments on commit 69e73fc

Please sign in to comment.