Skip to content

Commit

Permalink
Add ui tests for CLI (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rustin170506 authored May 15, 2023
1 parent f4a5403 commit 669304a
Show file tree
Hide file tree
Showing 10 changed files with 480 additions and 21 deletions.
242 changes: 221 additions & 21 deletions pyroscope_cli/Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyroscope_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ features = ["cargo", "derive"]
[dev-dependencies]
assert_cmd = "2.0.4"
predicates = "2.1.1"
trycmd = "0.14"

[features]
default = ["pyroscope/default", "pyroscope_pprofrs/default", "pyroscope_rbspy/default", "pyroscope_pyspy/default"]
Expand Down
6 changes: 6 additions & 0 deletions pyroscope_cli/src/cli/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,9 @@ pub fn cli_match() -> Result<()> {

Ok(())
}

#[test]
fn verify_cli() {
use clap::CommandFactory;
Cli::command().debug_assert()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
bin.name = "pyroscope-cli"
args = ["completion", "bash", "--help"]
status.code = 0
stdout = """
pyroscope-cli-completion-bash
generate the autocompletion script for bash
USAGE:
pyroscope-cli completion bash
OPTIONS:
-h, --help Print help information
"""
stderr = ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
bin.name = "pyroscope-cli"
args = ["completion", "--help"]
status.code = 0
stdout = """
pyroscope-cli-completion
Generate the autocompletion script for pyroscope for the specified shell. See each sub-command's
help for details on how to use the generated script.
USAGE:
pyroscope-cli completion <SUBCOMMAND>
OPTIONS:
-h, --help Print help information
SUBCOMMANDS:
bash generate the autocompletion script for bash
fish generate the autocompletion script for fish
powershell generate the autocompletion script for powershell
zsh generate the autocompletion script for zsh
help Print this message or the help of the given subcommand(s)
"""
stderr = ""
69 changes: 69 additions & 0 deletions pyroscope_cli/tests/cli-ui/pyroscope_cli_connect_cmd_stdout.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
bin.name = "pyroscope-cli"
args = ["connect", "--help"]
status.code = 0
stdout = """
pyroscope-cli-connect
Connect to an existing process and profile it
USAGE:
pyroscope-cli connect [OPTIONS] --pid <PID> --spy-name <SPY_NAME>
OPTIONS:
--application-name <APPLICATION_NAME>
application name used when uploading profiling data
--auth-token <AUTH_TOKEN>
Authentication token used when uploading profiling data
--basic-auth-username <BASIC_AUTH_USERNAME>
HTTP Basic Authentication username used when uploading profiling data
--basic-auth-password <BASIC_AUTH_PASSWORD>
HTTP Basic Authentication password used when uploading profiling data
--scope-org-id <SCOPE_ORG_ID>
X-Scope-OrgID header for phlare multi-tenancy
--detect-subprocesses
keep track of and profile subprocesses of the main process
-l, --log-level <LOG_LEVEL>
[default: info] log level for the application [possible values: trace, debug, info,
warn, error, critical]
--pid <PID>
PID of the process you want to profile. Pass -1 to profile the whole system (only
supported by ebpfspy)
--blocking
enable blocking mode. [supported by: rbspy, pyspy]
--oncpu
enable oncpu mode. [supported by: rbspy, pyspy]
--pyspy-gil
enable GIL mode for pyspy
--pyspy-native
enable native extensions profiling for pyspy
--sample-rate <SAMPLE_RATE>
[default: 100] sample rate for the profiler in Hz. 100 means reading 100 times per
second
--server-address <SERVER_ADDRESS>
[default: http://localhost:4040] Pyroscope server address
--spy-name <SPY_NAME>
name of the profiler to use [possible values: rbspy, pyspy]
--tag <TAG>
tag in key=value form. The flag may be specified multiple times
--http_header <HTTP_HEADER>
http header in 'X-Header: HeaderValue' form. The flag may be specified multiple times
-h, --help
Print help information
"""
stderr = ""
74 changes: 74 additions & 0 deletions pyroscope_cli/tests/cli-ui/pyroscope_cli_exec_cmd_stdout.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
bin.name = "pyroscope-cli"
args = ["exec", "--help"]
status.code = 0
stdout = """
pyroscope-cli-exec
Start a new process from arguments and profile it
USAGE:
pyroscope-cli exec [OPTIONS] --spy-name <SPY_NAME> <COMMAND>...
ARGS:
<COMMAND>... command to execute
OPTIONS:
--application-name <APPLICATION_NAME>
application name used when uploading profiling data
--auth-token <AUTH_TOKEN>
Authentication token used when uploading profiling data
--basic-auth-username <BASIC_AUTH_USERNAME>
HTTP Basic Authentication username used when uploading profiling data
--basic-auth-password <BASIC_AUTH_PASSWORD>
HTTP Basic Authentication password used when uploading profiling data
--scope-org-id <SCOPE_ORG_ID>
X-Scope-OrgID header for phlare multi-tenancy
--detect-subprocesses
keep track of and profile subprocesses of the main process
-l, --log-level <LOG_LEVEL>
[default: info] log level for the application [possible values: trace, debug, info,
warn, error, critical]
--blocking
enable blocking mode. [supported by: rbspy, pyspy]
--oncpu
enable oncpu mode. [supported by: rbspy, pyspy]
--pyspy-gil
enable GIL mode for pyspy
--pyspy-native
enable native extensions profiling for pyspy
--sample-rate <SAMPLE_RATE>
[default: 100] sample rate for the profiler in Hz. 100 means reading 100 times per
second
--server-address <SERVER_ADDRESS>
[default: http://localhost:4040] Pyroscope server address
--spy-name <SPY_NAME>
name of the profiler to use [possible values: rbspy, pyspy]
--tag <TAG>
tag in key=value form. The flag may be specified multiple times
--http_header <HTTP_HEADER>
http header in 'X-Header: HeaderValue' form. The flag may be specified multiple times
--user-name <USER_NAME>
start process under specified user name
--group-name <GROUP_NAME>
start process under specified group name
-h, --help
Print help information
"""
stderr = ""
33 changes: 33 additions & 0 deletions pyroscope_cli/tests/cli-ui/pyroscope_cli_help_cmd_stdout.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
bin.name = "pyroscope-cli"
args = ["help"]
status.code = 0
stdout = """
pyroscope-cli 0.2.3
Abid Omar <[email protected]>
Pyroscope CLI
USAGE:
pyroscope-cli [OPTIONS] <SUBCOMMAND>
OPTIONS:
-c, --config <FILE>
Set a custom config file
-h, --help
Print help information
-V, --version
Print version information
SUBCOMMANDS:
completion
Generate the autocompletion script for pyroscope for the specified shell. See each
sub-command's help for details on how to use the generated script.
connect
Connect to an existing process and profile it
exec
Start a new process from arguments and profile it
help
Print this message or the help of the given subcommand(s)
"""
stderr = ""
33 changes: 33 additions & 0 deletions pyroscope_cli/tests/cli-ui/pyroscope_cli_help_flag_stdout.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
bin.name = "pyroscope-cli"
args = ["--help"]
status.code = 0
stdout = """
pyroscope-cli 0.2.3
Abid Omar <[email protected]>
Pyroscope CLI
USAGE:
pyroscope-cli [OPTIONS] <SUBCOMMAND>
OPTIONS:
-c, --config <FILE>
Set a custom config file
-h, --help
Print help information
-V, --version
Print version information
SUBCOMMANDS:
completion
Generate the autocompletion script for pyroscope for the specified shell. See each
sub-command's help for details on how to use the generated script.
connect
Connect to an existing process and profile it
exec
Start a new process from arguments and profile it
help
Print this message or the help of the given subcommand(s)
"""
stderr = ""
7 changes: 7 additions & 0 deletions pyroscope_cli/tests/cli_ui.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#[test]
fn cli_ui_doc_text_tests() {
let t = trycmd::TestCases::new();
let cli = trycmd::cargo::cargo_bin("pyroscope-cli");
t.register_bin("pyroscope-cli", &cli);
t.case("tests/cli-ui/*.toml");
}

0 comments on commit 669304a

Please sign in to comment.