diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-29 22:58:18 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-29 22:58:34 +0300 |
| commit | 6703413fc7ef864f102aa2de5840bf874b589101 (patch) | |
| tree | dc4314024f4627e41fd009efb22fb013e0836de6 /tests | |
| parent | 09bac7f274a2944ca5a5ed83d11845ca6b0ce960 (diff) | |
feat: expose api schema from cli
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/cli_wrapper.rs | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/tests/cli_wrapper.rs b/tests/cli_wrapper.rs index 542d9768..ea402515 100644 --- a/tests/cli_wrapper.rs +++ b/tests/cli_wrapper.rs @@ -1029,6 +1029,8 @@ fn help_commands_exit_successfully() { let help_cases: &[&[&str]] = &[ &["-h"], &["--help"], + &["api", "-h"], + &["api", "schema", "-h"], &["status", "-h"], &["server", "-h"], &["workspace", "-h"], @@ -1073,6 +1075,91 @@ fn root_help_hides_explicit_client_command() { } #[test] +fn root_help_advertises_api_schema_command_group() { + let output = Command::new(env!("CARGO_BIN_EXE_herdr")) + .arg("--help") + .output() + .unwrap(); + + assert!(output.status.success()); + let stdout = String::from_utf8_lossy(&output.stdout); + assert!( + stdout.contains("herdr api <subcommand>"), + "root help should advertise the api command group: {stdout}" + ); +} + +#[test] +fn api_schema_default_output_is_a_short_summary() { + let output = Command::new(env!("CARGO_BIN_EXE_herdr")) + .args(["api", "schema"]) + .output() + .unwrap(); + + assert!(output.status.success()); + let stdout = String::from_utf8_lossy(&output.stdout); + assert!(stdout.contains("Herdr API schema"), "stdout: {stdout}"); + assert!( + stdout.contains("Use `herdr api schema --json`"), + "stdout: {stdout}" + ); + assert!( + stdout.len() < 400, + "summary should stay small enough for terminal output: {stdout}" + ); +} + +#[test] +fn api_schema_json_prints_bundled_schema() { + let output = Command::new(env!("CARGO_BIN_EXE_herdr")) + .args(["api", "schema", "--json"]) + .output() + .unwrap(); + + assert!(output.status.success()); + let schema: serde_json::Value = serde_json::from_slice(&output.stdout).unwrap(); + assert!(schema + .get("protocol") + .and_then(serde_json::Value::as_u64) + .is_some_and(|protocol| protocol > 0)); + assert_eq!( + schema + .get("schemas") + .and_then(serde_json::Value::as_object) + .map(serde_json::Map::len), + Some(5) + ); +} + +#[test] +fn api_schema_output_writes_bundled_schema_to_file() { + let base = unique_test_dir(); + fs::create_dir_all(&base).unwrap(); + let schema_path = base.join("herdr-api.schema.json"); + + let output = Command::new(env!("CARGO_BIN_EXE_herdr")) + .args(["api", "schema", "--output"]) + .arg(&schema_path) + .output() + .unwrap(); + + assert!(output.status.success()); + assert!( + String::from_utf8_lossy(&output.stdout).contains("wrote API schema"), + "stdout: {}", + String::from_utf8_lossy(&output.stdout) + ); + let schema: serde_json::Value = + serde_json::from_slice(&fs::read(&schema_path).unwrap()).unwrap(); + assert!(schema + .get("protocol") + .and_then(serde_json::Value::as_u64) + .is_some_and(|protocol| protocol > 0)); + + cleanup_test_base(&base); +} + +#[test] fn explicit_client_command_respects_nested_guard() { let base = unique_test_dir(); fs::create_dir_all(&base).unwrap(); |
