2025-02-09 18:53:36 +01:00
|
|
|
"""Steps for behavioral style tests are defined in this module.
|
|
|
|
|
|
|
|
Each step is defined by the string decorating it. This string is used
|
|
|
|
to call the step in "*.feature" file.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2025-02-09 19:16:42 +01:00
|
|
|
from behave import when, then
|
2025-02-09 18:53:36 +01:00
|
|
|
from textwrap import dedent
|
|
|
|
import tempfile
|
|
|
|
import wrappers
|
|
|
|
|
|
|
|
|
2025-02-09 19:16:42 +01:00
|
|
|
@when("we run dbcli")
|
2025-02-09 18:53:36 +01:00
|
|
|
def step_run_cli(context):
|
|
|
|
wrappers.run_cli(context)
|
|
|
|
|
|
|
|
|
2025-02-09 19:16:42 +01:00
|
|
|
@when("we wait for prompt")
|
2025-02-09 18:53:36 +01:00
|
|
|
def step_wait_prompt(context):
|
|
|
|
wrappers.wait_prompt(context)
|
|
|
|
|
|
|
|
|
|
|
|
@when('we send "ctrl + d"')
|
|
|
|
def step_ctrl_d(context):
|
|
|
|
"""Send Ctrl + D to hopefully exit."""
|
2025-02-09 19:16:42 +01:00
|
|
|
context.cli.sendcontrol("d")
|
2025-02-09 18:53:36 +01:00
|
|
|
context.exit_sent = True
|
|
|
|
|
|
|
|
|
2025-02-09 19:16:42 +01:00
|
|
|
@when(r'we send "\?" command')
|
2025-02-09 18:53:36 +01:00
|
|
|
def step_send_help(context):
|
2025-02-09 19:16:42 +01:00
|
|
|
r"""Send \?
|
2025-02-09 18:53:36 +01:00
|
|
|
|
|
|
|
to see help.
|
|
|
|
|
|
|
|
"""
|
2025-02-09 19:16:42 +01:00
|
|
|
context.cli.sendline("\\?")
|
|
|
|
wrappers.expect_exact(context, context.conf["pager_boundary"] + "\r\n", timeout=5)
|
2025-02-09 18:53:36 +01:00
|
|
|
|
|
|
|
|
2025-02-09 19:16:42 +01:00
|
|
|
@when("we send source command")
|
2025-02-09 18:53:36 +01:00
|
|
|
def step_send_source_command(context):
|
|
|
|
with tempfile.NamedTemporaryFile() as f:
|
2025-02-09 19:16:42 +01:00
|
|
|
f.write(b"\\?")
|
2025-02-09 18:53:36 +01:00
|
|
|
f.flush()
|
2025-02-09 19:16:42 +01:00
|
|
|
context.cli.sendline("\\. {0}".format(f.name))
|
|
|
|
wrappers.expect_exact(context, context.conf["pager_boundary"] + "\r\n", timeout=5)
|
2025-02-09 18:53:36 +01:00
|
|
|
|
|
|
|
|
2025-02-09 19:16:42 +01:00
|
|
|
@when("we run query to check application_name")
|
2025-02-09 18:53:36 +01:00
|
|
|
def step_check_application_name(context):
|
|
|
|
context.cli.sendline(
|
|
|
|
"SELECT 'found' FROM performance_schema.session_connect_attrs WHERE attr_name = 'program_name' AND attr_value = 'mycli'"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2025-02-09 19:16:42 +01:00
|
|
|
@then("we see found")
|
2025-02-09 18:53:36 +01:00
|
|
|
def step_see_found(context):
|
|
|
|
wrappers.expect_exact(
|
|
|
|
context,
|
2025-02-09 19:16:42 +01:00
|
|
|
context.conf["pager_boundary"]
|
|
|
|
+ "\r"
|
|
|
|
+ dedent("""
|
2025-02-09 18:53:36 +01:00
|
|
|
+-------+\r
|
|
|
|
| found |\r
|
|
|
|
+-------+\r
|
|
|
|
| found |\r
|
|
|
|
+-------+\r
|
|
|
|
\r
|
2025-02-09 19:16:42 +01:00
|
|
|
""")
|
|
|
|
+ context.conf["pager_boundary"],
|
|
|
|
timeout=5,
|
2025-02-09 18:53:36 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2025-02-09 19:16:42 +01:00
|
|
|
@then("we confirm the destructive warning")
|
|
|
|
def step_confirm_destructive_command(context): # noqa
|
2025-02-09 18:53:36 +01:00
|
|
|
"""Confirm destructive command."""
|
2025-02-09 19:16:42 +01:00
|
|
|
wrappers.expect_exact(context, "You're about to run a destructive command.\r\nDo you want to proceed? (y/n):", timeout=2)
|
|
|
|
context.cli.sendline("y")
|
2025-02-09 18:53:36 +01:00
|
|
|
|
|
|
|
|
2025-02-09 19:16:42 +01:00
|
|
|
@when('we answer the destructive warning with "{confirmation}"')
|
|
|
|
def step_confirm_destructive_command(context, confirmation): # noqa
|
2025-02-09 18:53:36 +01:00
|
|
|
"""Confirm destructive command."""
|
2025-02-09 19:16:42 +01:00
|
|
|
wrappers.expect_exact(context, "You're about to run a destructive command.\r\nDo you want to proceed? (y/n):", timeout=2)
|
2025-02-09 18:53:36 +01:00
|
|
|
context.cli.sendline(confirmation)
|
|
|
|
|
|
|
|
|
2025-02-09 19:16:42 +01:00
|
|
|
@then('we answer the destructive warning with invalid "{confirmation}" and see text "{text}"')
|
|
|
|
def step_confirm_destructive_command(context, confirmation, text): # noqa
|
2025-02-09 18:53:36 +01:00
|
|
|
"""Confirm destructive command."""
|
2025-02-09 19:16:42 +01:00
|
|
|
wrappers.expect_exact(context, "You're about to run a destructive command.\r\nDo you want to proceed? (y/n):", timeout=2)
|
2025-02-09 18:53:36 +01:00
|
|
|
context.cli.sendline(confirmation)
|
|
|
|
wrappers.expect_exact(context, text, timeout=2)
|
|
|
|
# we must exit the Click loop, or the feature will hang
|
2025-02-09 19:16:42 +01:00
|
|
|
context.cli.sendline("n")
|