Skip to content

Commit

Permalink
change command invocation in integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Swen committed Sep 16, 2021
1 parent afbecbf commit 3c7822c
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 130 deletions.
2 changes: 2 additions & 0 deletions esque/cli/commands/__init__.py
Expand Up @@ -9,6 +9,7 @@
from esque.cli.commands.ctx import ctx
from esque.cli.commands.delete import delete
from esque.cli.commands.describe import describe
from esque.cli.commands.edit import edit
from esque.cli.commands.get import get
from esque.cli.commands.io import io
from esque.cli.commands.ping import ping
Expand Down Expand Up @@ -47,6 +48,7 @@ def stop_profiling():
esque.add_command(ctx)
esque.add_command(delete)
esque.add_command(describe)
esque.add_command(edit)
esque.add_command(get)
esque.add_command(set_)
esque.add_command(apply)
Expand Down
22 changes: 11 additions & 11 deletions tests/integration/commands/test_apply.py
Expand Up @@ -4,7 +4,7 @@
import yaml
from click.testing import CliRunner

from esque.cli.commands.apply import apply
from esque.cli.commands import esque
from esque.controller.topic_controller import TopicController
from esque.errors import InvalidReplicationFactorException, ValidationException
from esque.resources.topic import Topic
Expand All @@ -29,7 +29,7 @@ def test_apply(interactive_cli_runner: CliRunner, topic_controller: TopicControl

# 1: topic creation
path = save_yaml(topic_id, apply_conf)
result = interactive_cli_runner.invoke(apply, ["-f", path], input="Y\n", catch_exceptions=False)
result = interactive_cli_runner.invoke(esque, args=["apply", "-f", path], input="Y\n", catch_exceptions=False)
assert (
result.exit_code == 0 and "Successfully applied changes" in result.output
), f"Calling apply failed, error: {result.output}"
Expand All @@ -38,7 +38,7 @@ def test_apply(interactive_cli_runner: CliRunner, topic_controller: TopicControl
topic_1["config"]["cleanup.policy"] = "delete"
path = save_yaml(topic_id, apply_conf)

result = interactive_cli_runner.invoke(apply, ["-f", path], input="Y\n", catch_exceptions=False)
result = interactive_cli_runner.invoke(esque, args=["apply", "-f", path], input="Y\n", catch_exceptions=False)
assert (
result.exit_code == 0 and "Successfully applied changes" in result.output
), f"Calling apply failed, error: {result.output}"
Expand All @@ -47,13 +47,13 @@ def test_apply(interactive_cli_runner: CliRunner, topic_controller: TopicControl
apply_conf["topics"].append(topic_2)
topic_1["config"]["cleanup.policy"] = "compact"
path = save_yaml(topic_id, apply_conf)
result = interactive_cli_runner.invoke(apply, ["-f", path], input="Y\n", catch_exceptions=False)
result = interactive_cli_runner.invoke(esque, args=["apply", "-f", path], input="Y\n", catch_exceptions=False)
assert (
result.exit_code == 0 and "Successfully applied changes" in result.output
), f"Calling apply failed, error: {result.output}"

# 4: no changes
result = interactive_cli_runner.invoke(apply, ["-f", path], catch_exceptions=False)
result = interactive_cli_runner.invoke(esque, args=["apply", "-f", path], catch_exceptions=False)
assert (
result.exit_code == 0 and "No changes detected, aborting" in result.output
), f"Calling apply failed, error: {result.output}"
Expand All @@ -62,7 +62,7 @@ def test_apply(interactive_cli_runner: CliRunner, topic_controller: TopicControl
topic_1["num_partitions"] = 3
topic_1["config"]["cleanup.policy"] = "delete"
path = save_yaml(topic_id, apply_conf)
result = interactive_cli_runner.invoke(apply, ["-f", path], input="Y\n", catch_exceptions=False)
result = interactive_cli_runner.invoke(esque, args=["apply", "-f", path], input="Y\n", catch_exceptions=False)
assert (
result.exit_code == 1 and "to `replication_factor` and `num_partitions`" in result.output
), f"Calling apply failed, error: {result.output}"
Expand Down Expand Up @@ -91,11 +91,11 @@ def test_apply_duplicate_names(interactive_cli_runner: CliRunner, topic_id: str)

# having the same topic name twice in apply should raise an exception
path = save_yaml(topic_id, apply_conf)
result = interactive_cli_runner.invoke(apply, ["-f", path], input="Y\n")
result = interactive_cli_runner.invoke(esque, args=["apply", "-f", path], input="Y\n")
assert result.exit_code != 0
assert isinstance(result.exception, ValidationException), (
"Calling apply should have failed with " "ValidationException"
)
assert isinstance(
result.exception, ValidationException
), "Calling apply should have failed with ValidationException"


@pytest.mark.integration
Expand All @@ -111,7 +111,7 @@ def test_apply_invalid_replicas(interactive_cli_runner: CliRunner, topic_id: str

# having the same topic name twice in apply should raise an ValueError
path = save_yaml(topic_id, apply_conf)
result = interactive_cli_runner.invoke(apply, ["-f", path], input="Y\n")
result = interactive_cli_runner.invoke(esque, args=["apply", "-f", path], input="Y\n")
assert result.exit_code != 0
assert isinstance(
result.exception, InvalidReplicationFactorException
Expand Down
12 changes: 7 additions & 5 deletions tests/integration/commands/test_consume.py
Expand Up @@ -8,7 +8,7 @@
from confluent_kafka.cimpl import Producer as ConfluentProducer

from esque import config
from esque.cli.commands.consume import consume
from esque.cli.commands import esque
from esque.controller.consumergroup_controller import ConsumerGroupController
from esque.errors import ConsumerGroupDoesNotExistException
from tests.integration.commands.conftest import produce_binary_test_messages
Expand All @@ -23,7 +23,7 @@ def test_avro_consume_to_stdout(
produce_test_messages_with_avro(avro_producer, source_topic)

message_text = non_interactive_cli_runner.invoke(
consume, args=["--stdout", "--number", "10", "--avro", source_topic_id], catch_exceptions=False
esque, args=["consume", "--stdout", "--number", "10", "--avro", source_topic_id], catch_exceptions=False
)
# Check assertions:
separate_messages = message_text.output.split("\n")
Expand All @@ -43,7 +43,7 @@ def test_offset_not_committed(
produce_test_messages_with_avro(avro_producer, source_topic)

non_interactive_cli_runner.invoke(
consume, args=["--stdout", "--numbers", "10", "--avro", source_topic_id], catch_exceptions=False
esque, args=["consume", "--stdout", "--numbers", "10", "--avro", source_topic_id], catch_exceptions=False
)

# cannot use pytest.raises(ConsumerGroupDoesNotExistException) because other tests may have committed offsets
Expand All @@ -63,7 +63,7 @@ def test_binary_consume_to_stdout(
expected_messages = produce_binary_test_messages(producer, source_topic)

message_text = non_interactive_cli_runner.invoke(
consume, args=["--stdout", "--number", "10", "--binary", source_topic_id], catch_exceptions=False
esque, args=["consume", "--stdout", "--number", "10", "--binary", source_topic_id], catch_exceptions=False
)
# Check assertions:
actual_messages = {
Expand All @@ -77,4 +77,6 @@ def test_binary_consume_to_stdout(
@pytest.mark.integration
def test_binary_and_avro_fails(non_interactive_cli_runner: CliRunner):
with pytest.raises(ValueError):
non_interactive_cli_runner.invoke(consume, args=["--binary", "--avro", "thetopic"], catch_exceptions=False)
non_interactive_cli_runner.invoke(
esque, args=["consume", "--binary", "--avro", "thetopic"], catch_exceptions=False
)
27 changes: 14 additions & 13 deletions tests/integration/commands/test_creation.py
Expand Up @@ -2,8 +2,7 @@
import pytest
from click.testing import CliRunner

from esque.cli.commands.create.consumergroup import create_consumergroup
from esque.cli.commands.create.topic import create_topic
from esque.cli.commands import esque
from esque.cli.options import State
from esque.errors import NoConfirmationPossibleException
from esque.resources.topic import Topic
Expand All @@ -13,7 +12,7 @@
def test_create_without_confirmation_does_not_create_topic(
interactive_cli_runner: CliRunner, confluent_admin_client: confluent_kafka.admin.AdminClient, topic_id: str
):
result = interactive_cli_runner.invoke(create_topic, [topic_id], catch_exceptions=False)
result = interactive_cli_runner.invoke(esque, args=["create", "topic", topic_id], catch_exceptions=False)
assert result.exit_code == 0

topics = confluent_admin_client.list_topics(timeout=5).topics.keys()
Expand All @@ -25,7 +24,7 @@ def test_create_topic_without_topic_name_fails(
non_interactive_cli_runner: CliRunner, confluent_admin_client: confluent_kafka.admin.AdminClient
):
n_topics_before = len(confluent_admin_client.list_topics(timeout=5).topics)
result = non_interactive_cli_runner.invoke(create_topic)
result = non_interactive_cli_runner.invoke(esque, args=["create", "topic"])
n_topics_after = len(confluent_admin_client.list_topics(timeout=5).topics)
assert result.exit_code != 0
assert n_topics_before == n_topics_after
Expand All @@ -39,7 +38,9 @@ def test_create_topic_as_argument_with_verification_works(
topics = confluent_admin_client.list_topics(timeout=5).topics.keys()
assert topic_id not in topics

result = interactive_cli_runner.invoke(create_topic, args=topic_id, input="Y\n", catch_exceptions=False)
result = interactive_cli_runner.invoke(
esque, args=["create", "topic", topic_id], input="Y\n", catch_exceptions=False
)
assert result.exit_code == 0
topics = confluent_admin_client.list_topics(timeout=5).topics.keys()
assert topic_id in topics
Expand All @@ -54,7 +55,7 @@ def test_create_topic_with_stdin_works(
assert topic_id not in topics

result = non_interactive_cli_runner.invoke(
create_topic, args="--no-verify", input=topic_id, catch_exceptions=False
esque, args=["create", "topic", "--no-verify"], input=topic_id, catch_exceptions=False
)
assert result.exit_code == 0
topics = confluent_admin_client.list_topics(timeout=5).topics.keys()
Expand All @@ -68,7 +69,7 @@ def test_topic_creation_stops_in_non_interactive_mode_without_no_verify(
topics = confluent_admin_client.list_topics(timeout=5).topics.keys()
assert topic_id not in topics

result = non_interactive_cli_runner.invoke(create_topic, input=topic_id)
result = non_interactive_cli_runner.invoke(esque, args=["create", "topic"], input=topic_id)
assert result.exit_code != 0
assert isinstance(result.exception, NoConfirmationPossibleException)

Expand Down Expand Up @@ -100,7 +101,7 @@ def test_topic_creation_with_template_works(
[Topic(topic_1, replication_factor=replication_factor, num_partitions=num_partitions, config=config)]
)
result = non_interactive_cli_runner.invoke(
create_topic, ["--no-verify", "-l", topic_1, topic_2], catch_exceptions=False
esque, args=["create", "topic", "--no-verify", "-l", topic_1, topic_2], catch_exceptions=False
)
assert result.exit_code == 0
config_from_template = state.cluster.topic_controller.get_cluster_topic(topic_2)
Expand All @@ -119,35 +120,35 @@ def test_consumer_group_correct_creation(
first_topic = f"{topic}"
first_cg = consumer_group + "1"
result1 = interactive_cli_runner.invoke(
create_consumergroup, args=[first_cg, first_topic], input="Y\n", catch_exceptions=False
esque, args=["create", "consumergroup", first_cg, first_topic], input="Y\n", catch_exceptions=False
)
assert result1.exit_code == 0

second_topic = f"{topic}[0]"
second_cg = consumer_group + "2"
result2 = interactive_cli_runner.invoke(
create_consumergroup, args=[second_cg, second_topic], input="Y\n", catch_exceptions=False
esque, args=["create", "consumergroup", second_cg, second_topic], input="Y\n", catch_exceptions=False
)
assert result2.exit_code == 0

third_topic = f"{topic}[0]=3"
third_cg = consumer_group + "3"
result3 = interactive_cli_runner.invoke(
create_consumergroup, args=[third_cg, third_topic], input="Y\n", catch_exceptions=False
esque, args=["create", "consumergroup", third_cg, third_topic], input="Y\n", catch_exceptions=False
)
assert result3.exit_code == 0

fourth_topic = f"{topic}[]"
fourth_cg = consumer_group + "4"
result4 = interactive_cli_runner.invoke(
create_consumergroup, args=[fourth_cg, fourth_topic], input="Y\n", catch_exceptions=False
esque, args=["create", "consumergroup", fourth_cg, fourth_topic], input="Y\n", catch_exceptions=False
)
assert result4.exit_code == 0

fifth_topic = f"{topic}[]="
fifth_cg = consumer_group + "5"
result5 = interactive_cli_runner.invoke(
create_consumergroup, args=[fifth_cg, fifth_topic], input="Y\n", catch_exceptions=False
esque, args=["create", "consumergroup", fifth_cg, fifth_topic], input="Y\n", catch_exceptions=False
)
assert result5.exit_code == 0

Expand Down
27 changes: 16 additions & 11 deletions tests/integration/commands/test_deletion.py
Expand Up @@ -2,8 +2,7 @@
import pytest
from click.testing import CliRunner

from esque.cli.commands.delete.topic import delete_topic
from esque.cli.commands.delete.topics import delete_topics
from esque.cli.commands import esque
from esque.errors import NoConfirmationPossibleException


Expand All @@ -14,7 +13,7 @@ def test_topic_deletion_singular_without_verification_does_not_work(
topics = confluent_admin_client.list_topics(timeout=5).topics.keys()
assert topic in topics

result = interactive_cli_runner.invoke(delete_topic, topic, catch_exceptions=False)
result = interactive_cli_runner.invoke(esque, args=["delete", "topic", topic], catch_exceptions=False)
assert result.exit_code == 0

topics = confluent_admin_client.list_topics(timeout=5).topics.keys()
Expand All @@ -28,7 +27,7 @@ def test_topic_deletion_plural_without_verification_does_not_work(
topics = confluent_admin_client.list_topics(timeout=5).topics.keys()
assert topic in topics

result = interactive_cli_runner.invoke(delete_topics, [topic], catch_exceptions=False)
result = interactive_cli_runner.invoke(esque, ["delete", "topics", topic], catch_exceptions=False)
assert result.exit_code == 0

topics = confluent_admin_client.list_topics(timeout=5).topics.keys()
Expand All @@ -40,7 +39,7 @@ def test_delete_topic_singular_without_topic_name_is_handled(
interactive_cli_runner: CliRunner, confluent_admin_client: confluent_kafka.admin.AdminClient
):
n_topics_before = len(confluent_admin_client.list_topics(timeout=5).topics)
result = interactive_cli_runner.invoke(delete_topic)
result = interactive_cli_runner.invoke(esque, args=["delete", "topic"])
n_topics_after = len(confluent_admin_client.list_topics(timeout=5).topics)
assert result.exit_code == 0
assert n_topics_before == n_topics_after
Expand All @@ -52,7 +51,7 @@ def test_delete_topic_plural_without_topic_name_is_handled(
interactive_cli_runner: CliRunner, confluent_admin_client: confluent_kafka.admin.AdminClient
):
n_topics_before = len(confluent_admin_client.list_topics(timeout=5).topics)
result = interactive_cli_runner.invoke(delete_topics)
result = interactive_cli_runner.invoke(esque, args=["delete", "topics"])
n_topics_after = len(confluent_admin_client.list_topics(timeout=5).topics)
assert result.exit_code == 0
assert n_topics_before == n_topics_after
Expand All @@ -66,7 +65,7 @@ def test_topic_deletion_as_argument_singular_works(
topics = confluent_admin_client.list_topics(timeout=5).topics.keys()
assert topic in topics

result = interactive_cli_runner.invoke(delete_topic, topic, input="y\n", catch_exceptions=False)
result = interactive_cli_runner.invoke(esque, args=["delete", "topic", topic], input="y\n", catch_exceptions=False)
assert result.exit_code == 0

topics = confluent_admin_client.list_topics(timeout=5).topics.keys()
Expand All @@ -80,7 +79,9 @@ def test_topic_deletion_as_argument_plural_works(
topics = confluent_admin_client.list_topics(timeout=5).topics.keys()
assert topic in topics

result = interactive_cli_runner.invoke(delete_topics, topic, input="y\n", catch_exceptions=False)
result = interactive_cli_runner.invoke(
esque, args=["delete", "topics", topic], input="y\n", catch_exceptions=False
)
assert result.exit_code == 0

topics = confluent_admin_client.list_topics(timeout=5).topics.keys()
Expand All @@ -94,7 +95,9 @@ def test_topic_deletion_as_stdin_works(
topics = confluent_admin_client.list_topics(timeout=5).topics.keys()
assert topic in topics

result = non_interactive_cli_runner.invoke(delete_topics, "--no-verify", input=topic, catch_exceptions=False)
result = non_interactive_cli_runner.invoke(
esque, args=["delete", "topics", "--no-verify"], input=topic, catch_exceptions=False
)
assert result.exit_code == 0

topics = confluent_admin_client.list_topics(timeout=5).topics.keys()
Expand All @@ -108,7 +111,7 @@ def test_topic_deletion_stops_in_non_interactive_mode_without_no_verify(
topics = confluent_admin_client.list_topics(timeout=5).topics.keys()
assert topic in topics

result = non_interactive_cli_runner.invoke(delete_topics, input=topic)
result = non_interactive_cli_runner.invoke(esque, args=["delete", "topics"], input=topic)
assert result.exit_code != 0
assert isinstance(result.exception, NoConfirmationPossibleException)

Expand All @@ -126,7 +129,9 @@ def test_keep_dash_delete_dot(
assert basic_topic in topics
assert duplicate_topic in topics

result = interactive_cli_runner.invoke(delete_topics, [duplicate_topic], input="y\n", catch_exceptions=False)
result = interactive_cli_runner.invoke(
esque, args=["delete", "topics", duplicate_topic], input="y\n", catch_exceptions=False
)
assert result.exit_code == 0

topics = confluent_admin_client.list_topics(timeout=5).topics.keys()
Expand Down

0 comments on commit 3c7822c

Please sign in to comment.