From 86c91276de5f44ff185ae65306b57c19f9e2a5b7 Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Mon, 15 Jan 2024 10:06:30 +0100 Subject: [PATCH] Add behave test for the 'token' command --- behave/features/steps/common.py | 22 +++++++++++++++++++ behave/features/token.feature | 38 +++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 behave/features/token.feature diff --git a/behave/features/steps/common.py b/behave/features/steps/common.py index 03b42dd0..74777bbb 100644 --- a/behave/features/steps/common.py +++ b/behave/features/steps/common.py @@ -124,6 +124,28 @@ def step_impl(context): raise AssertionError(f"Stdout is not:\n{expected_str}\n\nActual stdout:\n{found_str}") +@behave.step("stdout matches") +def step_impl(context): + expected = context.text.format(context=context).rstrip() + found = context.cmd_stdout.rstrip() + + if re.match(expected, found, re.MULTILINE): + return + + raise AssertionError(f"Stdout doesn't match:\n{expected}\n\nActual stdout:\n{found}") + + +@behave.step("I search '{pattern}' in stdout and store named groups in '{context_attribute}'") +def step_impl(context, pattern, context_attribute): + pattern = r"{}".format(pattern) + + result = [] + for match in re.finditer(pattern, context.cmd_stdout): + result.append(match.groupdict()) + + setattr(context, context_attribute, result) + + @behave.step("stderr is") def step_impl(context): expected = context.text.format(context=context).rstrip().split("\n") diff --git a/behave/features/token.feature b/behave/features/token.feature new file mode 100644 index 00000000..72fefd6a --- /dev/null +++ b/behave/features/token.feature @@ -0,0 +1,38 @@ +Feature: `osc token` command + + +Scenario: Run `osc token` with no arguments + When I execute osc with args "token" + Then stdout is + """ + + """ + + +Scenario: Run `osc token --operation rebuild` + When I execute osc with args "token --create --operation rebuild test:factory test-pkgA" + Then stdout matches + """ + Create a new token + + Ok + .* + 1 + + """ + Given I execute osc with args "token" + And stdout matches + """ + + + + """ + And I search 'string="(?P[^"]+)' in stdout and store named groups in 'tokens' + When I execute osc with args "token --trigger {context.tokens[0][token]}" + Then stdout is + """ + Trigger token + + Ok + + """