Files
telefind-rs/crates/app/tests/cli.rs
T

57 lines
1.8 KiB
Rust

use serde_json::{json, Value};
use std::{
io::Write,
process::{Command, Stdio},
};
#[test]
fn executable_replays_external_changes_and_returns_a_public_link() {
let mut child = Command::new(env!("CARGO_BIN_EXE_telefind"))
.args(["query", "-", "相机"])
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
.unwrap();
{
let mut input = child.stdin.take().unwrap();
for row in [
json!({"op":"upsert","kind":"channel","id":9,"username":"photocn","title":"相机"}),
json!({"op":"upsert","kind":"post","id":9,"message_id":4,"username":"photocn","body":"相机"}),
json!({"op":"delete","kind":"channel","id":9}),
] {
writeln!(input, "{row}").unwrap();
}
}
let response = child.wait_with_output().unwrap();
assert!(response.status.success());
let result: Value = serde_json::from_slice(&response.stdout).unwrap();
assert_eq!(result["text"], "共 1 条结果");
assert_eq!(
result["reply_markup"]["inline_keyboard"][0][0]["url"],
"https://t.me/photocn/4"
);
}
#[test]
fn invalid_record_reports_its_line_and_fails_before_search() {
let mut child = Command::new(env!("CARGO_BIN_EXE_telefind"))
.args(["query", "-", "demo"])
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.unwrap();
child
.stdin
.take()
.unwrap()
.write_all(b"\n{\"op\":\"delete\",\"kind\":\"post\",\"id\":5}\n")
.unwrap();
let output = child.wait_with_output().unwrap();
assert!(!output.status.success());
assert!(output.stdout.is_empty());
assert!(String::from_utf8(output.stderr)
.unwrap()
.contains("input line 2"));
}