Skip to content

Commit 309ffc2

Browse files
committed
adding support for multiples -c / --command parameter to pgcli w/tests
1 parent d607e17 commit 309ffc2

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ Contributors:
144144
* Jay Knight (jay-knight)
145145
* fbdb
146146
* Charbel Jacquin (charbeljc)
147+
* Diego
147148

148149
Creator:
149150
--------

tests/features/command_option.feature

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,13 @@ Feature: run the cli with -c/--command option,
2626
When we run pgcli with -c "SELECT 1; SELECT 2"
2727
then we see both query results
2828
and pgcli exits successfully
29+
30+
Scenario: run pgcli with multiple -c options
31+
When we run pgcli with multiple -c options
32+
then we see all command outputs
33+
and pgcli exits successfully
34+
35+
Scenario: run pgcli with mixed -c and --command options
36+
When we run pgcli with mixed -c and --command
37+
then we see all command outputs
38+
and pgcli exits successfully

tests/features/steps/command_option.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,72 @@ def step_pgcli_exits_with_error(context):
121121
# Clean up
122122
context.cmd_output = None
123123
context.exit_code = None
124+
125+
126+
@when("we run pgcli with multiple -c options")
127+
def step_run_pgcli_with_multiple_c(context):
128+
"""Run pgcli with multiple -c flags."""
129+
cmd = [
130+
"pgcli",
131+
"-h", context.conf["host"],
132+
"-p", str(context.conf["port"]),
133+
"-U", context.conf["user"],
134+
"-d", context.conf["dbname"],
135+
"-c", "SELECT 'first' as result",
136+
"-c", "SELECT 'second' as result",
137+
"-c", "SELECT 'third' as result"
138+
]
139+
try:
140+
context.cmd_output = subprocess.check_output(
141+
cmd,
142+
cwd=context.package_root,
143+
stderr=subprocess.STDOUT,
144+
timeout=10
145+
)
146+
context.exit_code = 0
147+
except subprocess.CalledProcessError as e:
148+
context.cmd_output = e.output
149+
context.exit_code = e.returncode
150+
except subprocess.TimeoutExpired as e:
151+
context.cmd_output = b"Command timed out"
152+
context.exit_code = -1
153+
154+
155+
@when("we run pgcli with mixed -c and --command")
156+
def step_run_pgcli_with_mixed_options(context):
157+
"""Run pgcli with mixed -c and --command flags."""
158+
cmd = [
159+
"pgcli",
160+
"-h", context.conf["host"],
161+
"-p", str(context.conf["port"]),
162+
"-U", context.conf["user"],
163+
"-d", context.conf["dbname"],
164+
"-c", "SELECT 'from_c' as source",
165+
"--command", "SELECT 'from_command' as source"
166+
]
167+
try:
168+
context.cmd_output = subprocess.check_output(
169+
cmd,
170+
cwd=context.package_root,
171+
stderr=subprocess.STDOUT,
172+
timeout=10
173+
)
174+
context.exit_code = 0
175+
except subprocess.CalledProcessError as e:
176+
context.cmd_output = e.output
177+
context.exit_code = e.returncode
178+
except subprocess.TimeoutExpired as e:
179+
context.cmd_output = b"Command timed out"
180+
context.exit_code = -1
181+
182+
183+
@then("we see all command outputs")
184+
def step_see_all_command_outputs(context):
185+
"""Verify that all command outputs are present."""
186+
output = context.cmd_output.decode('utf-8')
187+
# Should contain output from all commands
188+
assert "first" in output or "from_c" in output, f"Expected 'first' or 'from_c' in output, but got: {output}"
189+
assert "second" in output or "from_command" in output, f"Expected 'second' or 'from_command' in output, but got: {output}"
190+
# For the 3-command test, also check for third
191+
if "third" in output or "result" in output:
192+
assert "third" in output, f"Expected 'third' in output for 3-command test, but got: {output}"

0 commit comments

Comments
 (0)