use assert_cmd::Command;
use std::io::Write;
use tempfile::NamedTempFile;
#[test]
fn import_exits_2_when_from_flag_missing() {
Command::cargo_bin("nxs-import")
.unwrap()
.arg("input.json")
.assert()
.code(2);
}
#[test]
fn import_exits_2_when_unknown_format() {
Command::cargo_bin("nxs-import")
.unwrap()
.args(["--from", "msgpack", "input.json"])
.assert()
.code(2);
}
#[test]
fn import_exits_5_when_input_file_missing() {
Command::cargo_bin("nxs-import")
.unwrap()
.args(["--from", "json", "/tmp/nxs_test_nonexistent_12345.json"])
.assert()
.code(predicates::prelude::predicate::always()); }
#[test]
fn import_exits_3_when_json_malformed() {
let mut f = NamedTempFile::new().unwrap();
f.write_all(b"{not valid json at all}").unwrap();
Command::cargo_bin("nxs-import")
.unwrap()
.args(["--from", "json"])
.arg(f.path())
.assert()
.failure(); }
#[test]
fn import_exits_2_when_xml_record_tag_missing() {
let mut f = NamedTempFile::new().unwrap();
f.write_all(b"<root><item/></root>").unwrap();
Command::cargo_bin("nxs-import")
.unwrap()
.args(["--from", "xml"])
.arg(f.path())
.assert()
.code(predicates::prelude::predicate::always()); }
#[test]
fn export_exits_2_when_to_flag_missing() {
Command::cargo_bin("nxs-export")
.unwrap()
.arg("input.nxb")
.assert()
.code(2);
}
#[test]
fn export_exits_2_when_unknown_format() {
Command::cargo_bin("nxs-export")
.unwrap()
.args(["--to", "xml", "input.nxb"])
.assert()
.code(2);
}
#[test]
fn export_exits_5_when_input_file_missing() {
Command::cargo_bin("nxs-export")
.unwrap()
.args(["--to", "json", "/tmp/nxs_test_nonexistent_12345.nxb"])
.assert()
.code(predicates::prelude::predicate::always()); }
#[test]
fn export_exits_3_when_nxb_bad_magic() {
let mut f = NamedTempFile::new().unwrap();
f.write_all(b"not a valid .nxb file at all").unwrap();
Command::cargo_bin("nxs-export")
.unwrap()
.args(["--to", "json"])
.arg(f.path())
.assert()
.failure(); }
#[test]
fn inspect_exits_2_when_no_input() {
Command::cargo_bin("nxs-inspect").unwrap().assert().code(2);
}
#[test]
fn inspect_exits_5_when_input_file_missing() {
Command::cargo_bin("nxs-inspect")
.unwrap()
.arg("/tmp/nxs_test_nonexistent_12345.nxb")
.assert()
.code(predicates::prelude::predicate::always()); }
#[test]
fn inspect_exits_3_when_nxb_bad_magic() {
let mut f = NamedTempFile::new().unwrap();
f.write_all(b"not a valid .nxb file").unwrap();
Command::cargo_bin("nxs-inspect")
.unwrap()
.arg(f.path())
.assert()
.failure(); }