Lines
100 %
Functions
Branches
//! Integration tests for the `nomisync` automation CLI. These exercise
//! the clap parser and help/error pathways without needing a running
//! database. Actual command dispatch against the server is covered by
//! `cli-core`'s tests and the per-command tests inside the server crate.
use assert_cmd::Command;
use predicates::prelude::*;
fn cli() -> Command {
Command::cargo_bin("cli").expect("cli binary should build")
}
#[test]
fn top_level_help_mentions_every_subcommand() {
cli()
.arg("--help")
.assert()
.success()
.stdout(predicate::str::contains("version"))
.stdout(predicate::str::contains("account"))
.stdout(predicate::str::contains("transaction"))
.stdout(predicate::str::contains("commodity"))
.stdout(predicate::str::contains("config"))
.stdout(predicate::str::contains("sql"))
.stdout(predicate::str::contains("reports"))
.stdout(predicate::str::contains("ssh-key"));
fn ssh_key_help_lists_subcommands() {
.args(["ssh-key", "--help"])
.stdout(predicate::str::contains("add"))
.stdout(predicate::str::contains("list"))
.stdout(predicate::str::contains("remove"));
fn ssh_key_add_requires_key_source() {
let uuid = uuid::Uuid::new_v4();
.args(["--userid", &uuid.to_string(), "ssh-key", "add"])
.failure()
.stderr(predicate::str::contains("required"));
fn ssh_key_add_rejects_both_key_sources() {
.args([
"--userid",
&uuid.to_string(),
"ssh-key",
"add",
"--key-file",
"/tmp/foo",
"--public-key",
"ssh-ed25519 AAAA",
])
.failure();
fn ssh_key_remove_requires_fingerprint() {
.args(["--userid", &uuid.to_string(), "ssh-key", "remove"])
.stderr(predicate::str::contains("fingerprint"));
fn reports_help_lists_subcommands() {
.args(["reports", "--help"])
.stdout(predicate::str::contains("balance"))
.stdout(predicate::str::contains("activity"))
.stdout(predicate::str::contains("breakdown"));
fn account_help_lists_subcommands() {
.args(["account", "--help"])
.stdout(predicate::str::contains("create"));
fn missing_userid_exits_non_zero() {
.arg("version")
.stderr(predicate::str::contains("userid"));
fn unknown_subcommand_exits_non_zero() {
.args(["--userid", &uuid.to_string(), "bogus"])
fn reports_balance_help_documents_the_descriptor_flags() {
.args(["reports", "balance", "--help"])
.stdout(predicate::str::contains("--chart"))
.stdout(predicate::str::contains("--as-of"))
.stdout(predicate::str::contains("--to").not());
fn transaction_create_rejects_malformed_row() {
"transaction",
"create",
"--row",
"from=Cash,colour=red",
.stderr(predicate::str::contains("row 'from=Cash,colour=red'"));
fn transaction_help_lists_subcommands() {
.args(["transaction", "--help"])
.stdout(predicate::str::contains("create"))
.stdout(predicate::str::contains("delete"));
fn transaction_create_help_documents_rows_and_escaping() {
.args(["transaction", "create", "--help"])
.stdout(predicate::str::contains("--row"))
.stdout(predicate::str::contains("--date"))
.stdout(predicate::str::contains("--note"))
.stdout(predicate::str::contains("\\,"));
fn check_forms_refuses_without_disposable() {
"--database",
"postgres://localhost/nomisync_preflight_1",
"admin",
"check-forms",
.stderr(predicate::str::contains("writes"));
fn check_references_help_documents_the_sources_directory() {
.args(["admin", "check-references", "--help"])
.stdout(predicate::str::contains("--sources"));