mirror of https://github.com/chipsenkbeil/distant
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.5 KiB
Rust
61 lines
1.5 KiB
Rust
use crate::cli::fixtures::*;
|
|
use assert_fs::prelude::*;
|
|
use rstest::*;
|
|
use serde_json::json;
|
|
|
|
const FILE_CONTENTS: &str = r#"
|
|
some text
|
|
on multiple lines
|
|
that is a file's contents
|
|
"#;
|
|
|
|
#[rstest]
|
|
#[tokio::test]
|
|
async fn should_support_json_output(mut json_repl: CtxCommand<Repl>) {
|
|
let temp = assert_fs::TempDir::new().unwrap();
|
|
let file = temp.child("test-file");
|
|
file.write_str(FILE_CONTENTS).unwrap();
|
|
|
|
let id = rand::random::<u64>().to_string();
|
|
let req = json!({
|
|
"id": id,
|
|
"payload": {
|
|
"type": "file_read",
|
|
"path": file.to_path_buf(),
|
|
},
|
|
});
|
|
|
|
let res = json_repl.write_and_read_json(req).await.unwrap().unwrap();
|
|
|
|
assert_eq!(res["origin_id"], id);
|
|
assert_eq!(
|
|
res["payload"],
|
|
json!({
|
|
"type": "blob",
|
|
"data": FILE_CONTENTS.as_bytes().to_vec()
|
|
})
|
|
);
|
|
}
|
|
|
|
#[rstest]
|
|
#[tokio::test]
|
|
async fn should_support_json_output_for_error(mut json_repl: CtxCommand<Repl>) {
|
|
let temp = assert_fs::TempDir::new().unwrap();
|
|
let file = temp.child("missing-file");
|
|
|
|
let id = rand::random::<u64>().to_string();
|
|
let req = json!({
|
|
"id": id,
|
|
"payload": {
|
|
"type": "file_read",
|
|
"path": file.to_path_buf(),
|
|
},
|
|
});
|
|
|
|
let res = json_repl.write_and_read_json(req).await.unwrap().unwrap();
|
|
|
|
assert_eq!(res["origin_id"], id);
|
|
assert_eq!(res["payload"]["type"], "error");
|
|
assert_eq!(res["payload"]["kind"], "not_found");
|
|
}
|