Lines
100 %
Functions
Branches
use super::*;
use server::command::CmdResult;
use sqlx::types::Uuid;
use std::fmt::Debug;
use std::future::Future;
use std::pin::Pin;
#[derive(Debug, Default)]
struct StubRunnable {
result_lines: Option<Vec<String>>,
}
impl CliRunnable for StubRunnable {
fn run<'a>(
&'a self,
_args: &'a HashMap<&str, &Argument>,
) -> Pin<Box<dyn Future<Output = Result<Option<CmdResult>, CommandError>> + Send + 'a>> {
let out = self.result_lines.clone().map(CmdResult::Lines);
Box::pin(async move { Ok(out) })
#[tokio::test]
async fn run_and_print_accepts_empty_result() -> Result<(), CommandError> {
let stub = StubRunnable { result_lines: None };
run_and_print(&stub, HashMap::new()).await
async fn run_and_print_handles_lines_result() -> Result<(), CommandError> {
let stub = StubRunnable {
result_lines: Some(vec!["a".to_string(), "b".to_string()]),
};
async fn run_and_print_forwards_runnable_error() {
#[derive(Debug)]
struct Failing;
impl CliRunnable for Failing {
) -> Pin<Box<dyn Future<Output = Result<Option<CmdResult>, CommandError>> + Send + 'a>>
{
Box::pin(async move { Err(CommandError::Argument("boom".to_string())) })
let err = run_and_print(&Failing, HashMap::new())
.await
.expect_err("should bubble error");
assert!(matches!(err, CommandError::Argument(_)));
fn finding(kind: &str, detail: &str) -> DataFinding {
DataFinding {
id: Uuid::nil(),
kind: kind.to_string(),
subjects: vec![Uuid::nil(), Uuid::nil()],
detail: detail.to_string(),
created_at: sqlx::types::chrono::DateTime::UNIX_EPOCH,
#[test]
fn finding_lines_say_when_there_are_none() {
assert_eq!(finding_lines(&[]), ["no findings"]);
fn finding_lines_group_rows_under_their_kind() {
let lines = finding_lines(&[
finding("price-link", "one"),
finding("price-link", "two"),
finding("tag-conflict", "three"),
]);
assert_eq!(lines.len(), 5);
assert_eq!(lines[0], "price-link (2)");
assert_eq!(lines[3], "tag-conflict (1)");
assert!(lines[4].contains("three"));
assert!(
lines[1]
.contains("00000000-0000-0000-0000-000000000000,00000000-0000-0000-0000-000000000000")
);
fn a_merge_line_is_the_kept_id_and_the_moved_count() {
let into = Uuid::from_u128(7);
assert_eq!(merged_line(into, 3), format!("{into}\t3"));